Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/4147.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unit tests check that a household calculation without axes returns an enum variable as its member name and a string variable as a plain string.
42 changes: 42 additions & 0 deletions tests/unit/test_country.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,48 @@ def get_population(self, entity_plural):

assert result.household["people"]["you"]["age"]["2025"] == 40

@pytest.mark.parametrize(
("value_type", "calculated", "expected"),
[
(Enum, EnumArray(np.array([1]), ExampleEnum), "SECOND"),
(str, np.array(["second"]), "second"),
],
ids=["enum", "str"],
)
def test__calculate_returns_enum_names_and_plain_strings_without_axes(
self,
monkeypatch,
value_type,
calculated,
expected,
):
variable = SimpleNamespace(value_type=value_type)
simulation = SimpleNamespace(
calculate=lambda _variable_name, _period: calculated,
get_population=lambda _entity_plural: SimpleNamespace(
get_index=lambda _entity_id: 0
),
)
system = SimpleNamespace(
variables={"example_category": variable},
get_variable=lambda _variable_name: variable,
)
country = PolicyEngineCountry.__new__(PolicyEngineCountry)
monkeypatch.setattr(
country,
"_create_simulation",
lambda _household, _reform, **_kwargs: (simulation, system),
)

result = country.calculate(
{"people": {"you": {"example_category": {"2025": None}}}},
None,
)

value = result.household["people"]["you"]["example_category"]["2025"]
assert value == expected
assert type(value) is str


class TestAxisResults:
@pytest.mark.parametrize(
Expand Down
Loading