Skip to content

Commit

Permalink
Merge 903390b into 36abb2c
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Nov 17, 2016
2 parents 36abb2c + 903390b commit bf28af0
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 14 deletions.
1 change: 1 addition & 0 deletions ocelot/transformations/locations/market_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def unroll(lst, dct):

flat = unroll([], tree)

# Shouldn't exist - means that markets overlap
for loc, children in flat:
if children and not location_lookup[loc]['type'] == 'market group':
raise MarketGroupError
Expand Down
11 changes: 11 additions & 0 deletions tests/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,20 @@ def test_base_directory():
def test_output_directory():
assert get_output_directory()

def test_output_directory_envvar():
os.environ["OCELOT_OUTPUT"] = os.getcwd()
assert get_output_directory() == os.getcwd()

def test_cache_directory():
assert get_cache_directory()

def test_cache_directory_error(monkeypatch):
monkeypatch.setattr(
'ocelot.filesystem.get_cache_filepath_for_data_path',
lambda x: "not a real thing"
)
assert not check_cache_directory(os.getcwd())

def test_directory_structure():
base = get_base_directory()
output = get_output_directory()
Expand Down
49 changes: 49 additions & 0 deletions tests/locations/market_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,55 @@ def group_fixture(monkeypatch):
}]
return data


def test_inconsistent_names():
data = [{
'type': 'market group',
'name': 'market group for bar',
'reference product': 'foo',
}, {
'type': 'market group',
'name': 'market group for foo',
'reference product': 'foo',
}]
with pytest.raises(MarketGroupError):
link_market_group_suppliers(data)

def test_overlapping_markets():
data = [{
'type': 'market activity',
'location': 'FR',
'code': '1',
'name': 'market for foo',
'reference product': 'foo',
'exchanges': [{
'type': 'reference product',
'name': 'foo',
}]
}, {
'type': 'market activity',
'location': 'RER',
'code': '2',
'name': 'market for foo',
'reference product': 'foo',
'exchanges': [{
'type': 'reference product',
'name': 'foo',
}]
}, {
'type': 'market group',
'location': 'GLO',
'code': '3',
'name': 'market group for foo',
'reference product': 'foo',
'exchanges': [{
'type': 'reference product',
'name': 'foo',
}]
}]
with pytest.raises(MarketGroupError):
link_market_group_suppliers(data)

def test_link_market_group_suppliers(group_fixture):
expected = [{
'type': 'market activity',
Expand Down
32 changes: 18 additions & 14 deletions tests/transformations/transformations_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,27 @@ def test_ensure_mandatory_properties():
}]
assert ensure_mandatory_properties(given)

# missing = [{
# 'filepath': '',
# 'exchanges': [{
# 'name': 'something',
# 'type': 'from technosphere',
# 'properties': [
# {'amount': 1, 'name': "dry mass"},
# {'amount': 1, 'name': "water in wet mass"},
# {'amount': 1, 'name': "wet mass"},
# {'amount': 1, 'name': "water content"},
# {'amount': 1, 'name': "carbon content fossil"},
# ]
# }]
# }]
missing = [{
'name': 'foo',
'filepath': '',
'exchanges': [{
'name': 'something',
'type': 'from technosphere',
'properties': [
{'amount': 1, 'name': "dry mass"},
{'amount': 1, 'name': "water in wet mass"},
{'amount': 1, 'name': "wet mass"},
{'amount': 1, 'name': "water content"},
{'amount': 1, 'name': "carbon content fossil"},
]
}]
}]
# with pytest.raises(MissingMandatoryProperty):
# ensure_mandatory_properties(missing)

# Will pass, even though properties are missing; tests logging
assert ensure_mandatory_properties(missing)

missing = [{
'filepath': '',
'exchanges': [{
Expand Down
6 changes: 6 additions & 0 deletions tests/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ def test_correct_unrolling(func):
filter_func = lambda x: x == 2
wrapped = TransformationWrapper(funky, filter_func)
assert wrapped([1, 2, 3]) == [1, 1, 2, 3, 3]

def test_correct_unrolling_no_filter(func):
funky = lambda x: [1,2,3]
wrapped = TransformationWrapper(funky)
assert wrapped([None, None]) == [1, 2, 3, 1, 2, 3]

0 comments on commit bf28af0

Please sign in to comment.