From 0b0d195f448041f5287df0088f121b409976031e Mon Sep 17 00:00:00 2001 From: "Benjamin W. Portner" Date: Sun, 18 Feb 2024 19:42:47 +0100 Subject: [PATCH] add test for generic strategy test_assign_default_location --- tests/strategies/generic.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/strategies/generic.py b/tests/strategies/generic.py index 2620e4d..2e8e484 100644 --- a/tests/strategies/generic.py +++ b/tests/strategies/generic.py @@ -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 @@ -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 \ No newline at end of file