Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
abhcs committed Feb 6, 2024
1 parent c5b4a86 commit dc45ff4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
12 changes: 8 additions & 4 deletions policyengine_core/variables/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def __init__(self, baseline_variable=None):
raise ValueError(
'Variable "{name}" has no label'.format(name=self.name)
)

self.end = self.set(attr, "end", allowed_type=str, setter=self.set_end)
self.reference = self.set(attr, "reference", setter=self.set_reference)
self.cerfa_field = self.set(
Expand Down Expand Up @@ -291,10 +291,14 @@ def __init__(self, baseline_variable=None):
self.name, ", ".join(sorted(unexpected_attrs.keys()))
)
)

if len(self.formulas) != 0 and (self.adds is not None or self.subtracts is not None):

if len(self.formulas) != 0 and (
self.adds is not None or self.subtracts is not None
):
raise ValueError(
'Variable "{name}" has a formula and an add or subtract'.format(name=self.name)
'Variable "{name}" has a formula and an add or subtract'.format(
name=self.name
)
)

self.is_neutralized = False
Expand Down
24 changes: 20 additions & 4 deletions tests/core/variables/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ class variable_with_strange_attr(Variable):
with raises(ValueError):
tax_benefit_system.add_variable(variable_with_strange_attr)


class variable__one_formula_one_add(Variable):
value_type = int
entity = Person
Expand All @@ -623,13 +624,17 @@ class variable__one_formula_one_add(Variable):
def formula():
pass


def test_one_formula_one_add():
check_error_at_add_variable(
tax_benefit_system,
variable__one_formula_one_add,
'Variable "{name}" has a formula and an add or subtract'.format(name="variable__one_formula_one_add"),
'Variable "{name}" has a formula and an add or subtract'.format(
name="variable__one_formula_one_add"
),
)


class variable__one_formula_one_subtract(Variable):
value_type = int
entity = Person
Expand All @@ -640,13 +645,17 @@ class variable__one_formula_one_subtract(Variable):
def formula():
pass


def test_one_formula_one_subtract():
check_error_at_add_variable(
tax_benefit_system,
variable__one_formula_one_subtract,
'Variable "{name}" has a formula and an add or subtract'.format(name="variable__one_formula_one_subtract"),
'Variable "{name}" has a formula and an add or subtract'.format(
name="variable__one_formula_one_subtract"
),
)


class variable__one_formula(Variable):
value_type = int
entity = Person
Expand All @@ -656,43 +665,50 @@ class variable__one_formula(Variable):
def formula():
pass


def test_one_formula():
tax_benefit_system.add_variable(variable__one_formula)
variable = tax_benefit_system.variables["variable__one_formula"]
assert len(variable.formulas)


class variable__one_add(Variable):
value_type = int
entity = Person
definition_period = MONTH
label = "Variable with one add."
adds = ["pass"]


def test_one_add():
tax_benefit_system.add_variable(variable__one_add)
variable = tax_benefit_system.variables["variable__one_add"]
assert len(variable.adds)


class variable__one_subtract(Variable):
value_type = int
entity = Person
definition_period = MONTH
label = "Variable with one subtract."
subtracts = ["pass"]


def test_one_subtract():
tax_benefit_system.add_variable(variable__one_subtract)
variable = tax_benefit_system.variables["variable__one_subtract"]
assert len(variable.subtracts)


class variable__no_label(Variable):
value_type = int
entity = Person
definition_period = MONTH


def test_no_label():
check_error_at_add_variable(
tax_benefit_system,
variable__no_label,
'Variable "{name}" has no label'.format(name="variable__no_label")
)
'Variable "{name}" has no label'.format(name="variable__no_label"),
)

0 comments on commit dc45ff4

Please sign in to comment.