Skip to content

Commit

Permalink
Merge pull request #18 from statisticsnorway/bugfix
Browse files Browse the repository at this point in the history
Bugfix
  • Loading branch information
MagnusEngh authored May 7, 2024
2 parents 80e9050 + 3b957fc commit 59d5faa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ssb-jordbruk-fagfunksjoner"
version = "0.2.0"
version = "0.2.1"
description = "SSB Jordbruk Fagfunksjoner"
authors = ["Magnus Theodor Engh <dor@ssb.no>"]
license = "MIT"
Expand Down
13 changes: 8 additions & 5 deletions src/ssb_jordbruk_fagfunksjoner/produksjonstilskudd.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ class Produksjonstilskudd:
}

statbank_groups: ClassVar[dict[str, list[str]]] = {
"storfe": ["119", "120", "121"],
"ku": ["120", "121"],
"sau": ["145", "146", "139"],
"avlssvin": ["155", "156", "158", "159"],
"svin": ["154", "155", "156", "157", "158", "159"],
"statbank_storfe": ["119", "120", "121"],
"statbank_ku": ["120", "121"],
"statbank_sau": ["145", "146", "139"],
"statbank_avlssvin": ["155", "156", "158", "159"],
"statbank_svin": ["154", "155", "156", "157", "158", "159"],
}

def __init__(self) -> None:
Expand Down Expand Up @@ -286,6 +286,9 @@ def _setup_dynamic_attributes(self) -> None:
combined_dict.update(getattr(self, group, {}))
setattr(self, combo_name, combined_dict)

for statbank_name, codes in self.statbank_groups.items():
setattr(self, statbank_name, self._extract_from_codelist(codes))

def _extract_from_codelist(self, numbers: list[str]) -> dict[str, str]:
result = {}
for code in numbers:
Expand Down
13 changes: 12 additions & 1 deletion tests/test_produksjonstilskudd.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,16 @@ def test_dynamic_combinations_creation(
), "Instance should have 'frukt' combination attribute"
combination = produksjonstilskudd_instance.frukt
assert (
"001" in combination or "271" in combination
"001" in combination and "271" in combination
), "'frukt' combination should contain codes from its groups"


def test_dynamic_statbank_creation(
produksjonstilskudd_instance: Produksjonstilskudd,
) -> None:
assert hasattr(
produksjonstilskudd_instance, "statbank_storfe"
), "Instance should have 'statbank_storfe' attribute"
assert isinstance(
produksjonstilskudd_instance.statbank_storfe, dict
), "'statbank_storfe' should be a dictionary"

0 comments on commit 59d5faa

Please sign in to comment.