-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46662aa
commit 4f8890e
Showing
4 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
policyengine/tests/economic_impact/poverty_impact/deep_poverty/by_age/by_age.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Regular poverty by age | ||
- test_child_poverty: | ||
reform: | ||
gov.hmrc.income_tax.rates.uk[0].rate: | ||
"2024-01-01.2100-12-31": 0.55 | ||
country: uk | ||
expected: | ||
baseline: 2.44 | ||
reform: 2.45 | ||
change: 0.7 | ||
|
||
- test_adult_poverty: | ||
reform: | ||
gov.hmrc.income_tax.rates.uk[0].rate: | ||
"2024-01-01.2100-12-31": 0.55 | ||
country: uk | ||
expected: | ||
baseline: 2.6 | ||
reform: 2.7 | ||
change: 3.9 | ||
|
||
- test_senior_poverty: | ||
reform: | ||
gov.hmrc.income_tax.rates.uk[0].rate: | ||
"2024-01-01.2100-12-31": 0.55 | ||
country: uk | ||
expected: | ||
baseline: 1.76 | ||
reform: 1.76 | ||
change: 0.5 | ||
|
||
- test_all_poverty: | ||
reform: | ||
gov.hmrc.income_tax.rates.uk[0].rate: | ||
"2024-01-01.2100-12-31": 0.55 | ||
country: uk | ||
expected: | ||
baseline: 2.41 | ||
reform: 2.47 | ||
change: 2.7 |
41 changes: 41 additions & 0 deletions
41
policyengine/tests/economic_impact/poverty_impact/deep_poverty/by_age/test_deep_by_age.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
import yaml | ||
import os | ||
from policyengine import EconomicImpact | ||
|
||
def assert_dict_approx_equal(actual, expected, tolerance=1e-4): | ||
for key in expected: | ||
assert abs(actual[key] - expected[key]) < tolerance, f"Key {key}: expected {expected[key]}, got {actual[key]}" | ||
|
||
|
||
yaml_file_path = "policyengine/tests/economic_impact/poverty_impact/deep_poverty/by_age/by_age.yaml" | ||
|
||
# Check if the file exists | ||
if not os.path.exists(yaml_file_path): | ||
raise FileNotFoundError(f"The YAML file does not exist at: {yaml_file_path}") | ||
|
||
with open(yaml_file_path, 'r') as file: | ||
test_cases = yaml.safe_load(file) | ||
|
||
@pytest.mark.parametrize("test_case", test_cases) | ||
def test_economic_impact(test_case): | ||
test_name = list(test_case.keys())[0] | ||
test_data = test_case[test_name] | ||
|
||
economic_impact = EconomicImpact(test_data['reform'], test_data['country']) | ||
|
||
if 'child' in test_name: | ||
result = economic_impact.calculate("poverty/deep/child") | ||
elif 'adult' in test_name: | ||
result = economic_impact.calculate("poverty/deep/adult") | ||
elif 'senior' in test_name: | ||
result = economic_impact.calculate("poverty/deep/senior") | ||
elif 'all' in test_name: | ||
result = economic_impact.calculate("poverty/deep/age/all") | ||
else: | ||
pytest.fail(f"Unknown test case: {test_name}") | ||
|
||
assert_dict_approx_equal(result, test_data['expected']) | ||
|
||
if __name__ == "__main__": | ||
pytest.main([__file__]) |
30 changes: 30 additions & 0 deletions
30
policyengine/tests/economic_impact/poverty_impact/deep_poverty/by_gender/by_gender.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Regular poverty by age | ||
- male_poverty_test: | ||
reform: | ||
gov.hmrc.income_tax.rates.uk[0].rate: | ||
"2024-01-01.2100-12-31": 0.55 | ||
country: uk | ||
expected: | ||
baseline: 2.66 | ||
reform: 2.73 | ||
change: 2.5 | ||
|
||
- female_poverty_test: | ||
reform: | ||
gov.hmrc.income_tax.rates.uk[0].rate: | ||
"2024-01-01.2100-12-31": 0.55 | ||
country: uk | ||
expected: | ||
baseline: 2.16 | ||
reform: 2.23 | ||
change: 2.9 | ||
|
||
- all_poverty_test: | ||
reform: | ||
gov.hmrc.income_tax.rates.uk[0].rate: | ||
"2024-01-01.2100-12-31": 0.55 | ||
country: uk | ||
expected: | ||
baseline: 2.41 | ||
reform: 2.47 | ||
change: 2.7 |
41 changes: 41 additions & 0 deletions
41
...engine/tests/economic_impact/poverty_impact/deep_poverty/by_gender/test_deep_by_gender.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
import yaml | ||
import os | ||
from policyengine import EconomicImpact | ||
|
||
def assert_dict_approx_equal(actual, expected, tolerance=1e-4): | ||
for key in expected: | ||
assert abs(actual[key] - expected[key]) < tolerance, f"Key {key}: expected {expected[key]}, got {actual[key]}" | ||
|
||
|
||
yaml_file_path = "policyengine/tests/economic_impact/poverty_impact/deep_poverty/by_age/by_age.yaml" | ||
|
||
# Check if the file exists | ||
if not os.path.exists(yaml_file_path): | ||
raise FileNotFoundError(f"The YAML file does not exist at: {yaml_file_path}") | ||
|
||
with open(yaml_file_path, 'r') as file: | ||
test_cases = yaml.safe_load(file) | ||
|
||
@pytest.mark.parametrize("test_case", test_cases) | ||
def test_economic_impact(test_case): | ||
test_name = list(test_case.keys())[0] | ||
test_data = test_case[test_name] | ||
|
||
economic_impact = EconomicImpact(test_data['reform'], test_data['country']) | ||
|
||
if 'child' in test_name: | ||
result = economic_impact.calculate("poverty/deep/child") | ||
elif 'adult' in test_name: | ||
result = economic_impact.calculate("poverty/deep/adult") | ||
elif 'senior' in test_name: | ||
result = economic_impact.calculate("poverty/deep/senior") | ||
elif 'all' in test_name: | ||
result = economic_impact.calculate("poverty/deep/age/all") | ||
else: | ||
pytest.fail(f"Unknown test case: {test_name}") | ||
|
||
assert_dict_approx_equal(result, test_data['expected']) | ||
|
||
if __name__ == "__main__": | ||
pytest.main([__file__]) |