-
Notifications
You must be signed in to change notification settings - Fork 76
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
Mauko Quiroga
committed
Dec 30, 2019
1 parent
3a06983
commit 6b62771
Showing
9 changed files
with
401 additions
and
261 deletions.
There are no files selected for viewing
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
Empty file.
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,26 @@ | ||
from numpy import array | ||
|
||
from openfisca_core.taxscales import AbstractRateTaxScale | ||
from openfisca_core.tools import assert_near | ||
|
||
|
||
def test_bracket_indices(): | ||
tax_base = array([0, 10, 50, 125, 250]) | ||
tax_scale = AbstractRateTaxScale() | ||
tax_scale.add_bracket(0, 0) | ||
tax_scale.add_bracket(100, 0) | ||
tax_scale.add_bracket(200, 0) | ||
|
||
result = tax_scale.bracket_indices(tax_base) | ||
|
||
assert_near(result, [0, 0, 0, 1, 2]) | ||
|
||
|
||
def test_to_dict(): | ||
tax_scale = AbstractRateTaxScale() | ||
tax_scale.add_bracket(0, 0) | ||
tax_scale.add_bracket(100, 0.1) | ||
|
||
result = tax_scale.to_dict() | ||
|
||
assert result == {"0": 0.0, "100": 0.1} |
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,33 @@ | ||
from pytest import fixture | ||
|
||
from openfisca_core.parameters import ParameterNode | ||
from openfisca_core.taxscales import combine_tax_scales | ||
from openfisca_core.tools import assert_near | ||
|
||
|
||
@fixture | ||
def node(): | ||
return ParameterNode( | ||
"baremes", | ||
data = { | ||
"health": { | ||
"brackets": [ | ||
{"rate": {"2015-01-01": 0.05}, "threshold": {"2015-01-01": 0}}, | ||
{"rate": {"2015-01-01": 0.10}, "threshold": {"2015-01-01": 2000}}, | ||
] | ||
}, | ||
"retirement": { | ||
"brackets": [ | ||
{"rate": {"2015-01-01": 0.02}, "threshold": {"2015-01-01": 0}}, | ||
{"rate": {"2015-01-01": 0.04}, "threshold": {"2015-01-01": 3000}}, | ||
] | ||
}, | ||
}, | ||
)(2015) | ||
|
||
|
||
def test_combine_tax_scales(node): | ||
result = combine_tax_scales(node) | ||
|
||
assert_near(result.thresholds, [0, 2000, 3000]) | ||
assert_near(result.rates, [0.07, 0.12, 0.14], 1e-13) |
18 changes: 18 additions & 0 deletions
18
tests/core/tax_scales/test_linear_average_rate_tax_scale.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,18 @@ | ||
from numpy import array | ||
|
||
from openfisca_core.taxscales import LinearAverageRateTaxScale | ||
from openfisca_core.tools import assert_near | ||
|
||
|
||
def test_to_marginal(): | ||
tax_base = array([1, 1.5, 2, 2.5]) | ||
tax_scale = LinearAverageRateTaxScale() | ||
tax_scale.add_bracket(0, 0) | ||
tax_scale.add_bracket(1, 0.1) | ||
tax_scale.add_bracket(2, 0.2) | ||
|
||
result = tax_scale.to_marginal() | ||
|
||
assert result.thresholds == [0, 1, 2] | ||
assert_near(result.rates, [0.1, 0.3, 0.2], absolute_error_margin = 0) | ||
assert_near(result.calc(tax_base), [0.1, 0.25, 0.4, 0.5], absolute_error_margin = 0) |
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,43 @@ | ||
from pytest import fixture | ||
|
||
from numpy import array | ||
|
||
from openfisca_core.parameters import Scale | ||
from openfisca_core.periods import Instant | ||
from openfisca_core.taxscales import MarginalAmountTaxScale | ||
from openfisca_core.tools import assert_near | ||
|
||
|
||
@fixture | ||
def data(): | ||
return { | ||
"description": "Social security contribution tax scale", | ||
"metadata": {"threshold_unit": "currency-EUR", "rate_unit": "/1"}, | ||
"brackets": [ | ||
{ | ||
"threshold": {"2017-10-01": {"value": 0.23}}, | ||
"amount": {"2017-10-01": {"value": 6}, }, | ||
} | ||
], | ||
} | ||
|
||
|
||
def test_calc(): | ||
tax_base = array([1, 8, 10]) | ||
tax_scale = MarginalAmountTaxScale() | ||
tax_scale.add_bracket(6, 0.23) | ||
tax_scale.add_bracket(9, 0.29) | ||
|
||
result = tax_scale.calc(tax_base) | ||
|
||
assert_near(result, [0, 0.23, 0.52]) | ||
|
||
|
||
# TODO: move, as we're testing Scale, not MarginalAmountTaxScale | ||
def test_dispatch_scale_type_on_creation(data): | ||
scale = Scale("amount_scale", data, "") | ||
first_jan = Instant((2017, 11, 1)) | ||
|
||
result = scale.get_at_instant(first_jan) | ||
|
||
assert isinstance(result, MarginalAmountTaxScale) |
Oops, something went wrong.