Skip to content

Commit

Permalink
add test for generic strategy test_assign_default_location
Browse files Browse the repository at this point in the history
  • Loading branch information
BenPortner committed Feb 18, 2024
1 parent 493ce83 commit 0b0d195
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tests/strategies/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
tupleize_categories,
split_exchanges,
)
from bw2io.strategies.generic import overwrite_exchange_field_values
from bw2io.strategies.generic import overwrite_exchange_field_values, assign_default_location
from bw2data.tests import bw2test
from bw2data import Database
from copy import deepcopy
Expand Down Expand Up @@ -423,3 +423,29 @@ def test_overwrite_exchange_field_values():
got = overwrite_exchange_field_values(ds.copy(), fields=["categories"])
expected = [{"exchanges": [{"input": ("bio", "2"), "categories": ("water",)}]}]
assert got == expected


def test_assign_default_location():
ds = [
{"name": "foo", "location": "DE"},
{"name": "bar"},
{"name": "con", "location": "CH"},
]

# default should add "GLO" as missing locations
got = assign_default_location(ds)
expected = [
{"name": "foo", "location": "DE"},
{"name": "bar", "location": "GLO"},
{"name": "con", "location": "CH"},
]
assert got == expected

# test overwrite with custom loc
got = assign_default_location(ds, default_loc="ES", overwrite=True)
expected = [
{"name": "foo", "location": "ES"},
{"name": "bar", "location": "ES"},
{"name": "con", "location": "ES"},
]
assert got == expected

0 comments on commit 0b0d195

Please sign in to comment.