-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstrategies.py
55 lines (43 loc) · 1.63 KB
/
strategies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from bw_recipe_2016.strategies import (
fix_unit_string,
split_synonyms,
more_synonyms,
fix_perspective_string,
name_matcher,
)
def test_fix_unit_string():
def wrap(s):
return [{"unit": s}]
assert fix_unit_string(wrap("(kg CO2eq/ kg GHG)")) == wrap("kg CO2eq/kg GHG")
assert fix_unit_string(wrap("kg CO2eq/kg GHG")) == wrap("kg CO2eq/kg GHG")
def test_split_synonyms():
def wrap(s):
return [{"exchanges": [{"synonyms": s}]}]
assert split_synonyms(wrap("dinitrogen oxide (nitrous oxide)")) == wrap(
["dinitrogen oxide", "nitrous oxide"]
)
assert split_synonyms(wrap("dinitrogen oxide nitrous oxide ")) == wrap(
["dinitrogen oxide nitrous oxide"]
)
assert split_synonyms([{"exchanges": [{}]}]) == [{"exchanges": [{"synonyms": []}]}]
def test_more_synoyms():
given = [{"exchanges": [{"synonyms": ["foo bar", "baz_2"]}]}]
expected = [{"exchanges": [{"synonyms": ["foo bar", "foo-bar", "baz_2"]}]}]
assert more_synonyms(given) == expected
def test_fix_perspective_string():
given = {
1: {"perspective": "Hierarchist"},
2: {"perspective": "EGALITARIAN"},
3: {"perspective": "I"},
}
expected = {
1: {"perspective": "Hierarchist"},
2: {"perspective": "Egalitarian"},
3: {"perspective": "Individualist"},
}
assert fix_perspective_string(given) == expected
def test_name_matcher():
given = [{'exchanges': [{"name": "FOO"}, {"name": "Baz"}]}]
expected = [{'exchanges': [{"name": "bar"}, {"name": "Baz"}]}]
mapping = {"foo": "bar"}
assert name_matcher(given, mapping) == expected