hestia-earth-models 0.64.8__py3-none-any.whl → 0.64.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of hestia-earth-models might be problematic. Click here for more details.

Files changed (37) hide show
  1. hestia_earth/models/cycle/siteArea.py +2 -1
  2. hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandOccupation.py +73 -82
  3. hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandTransformation.py +102 -116
  4. hestia_earth/models/environmentalFootprintV3/soilQualityIndexTotalLandUseEffects.py +27 -16
  5. hestia_earth/models/faostat2018/landTransformationFromCropland100YearAverage.py +3 -2
  6. hestia_earth/models/faostat2018/landTransformationFromCropland20YearAverage.py +3 -2
  7. hestia_earth/models/frischknechtEtAl2000/ionisingRadiationKbqU235Eq.py +69 -37
  8. hestia_earth/models/ipcc2019/animal/fatContent.py +38 -0
  9. hestia_earth/models/ipcc2019/animal/liveweightGain.py +3 -54
  10. hestia_earth/models/ipcc2019/animal/liveweightPerHead.py +3 -54
  11. hestia_earth/models/ipcc2019/animal/pregnancyRateTotal.py +38 -0
  12. hestia_earth/models/ipcc2019/animal/trueProteinContent.py +38 -0
  13. hestia_earth/models/ipcc2019/animal/utils.py +87 -3
  14. hestia_earth/models/ipcc2019/animal/weightAtMaturity.py +4 -10
  15. hestia_earth/models/mocking/search-results.json +265 -259
  16. hestia_earth/models/poschEtAl2008/terrestrialAcidificationPotentialAccumulatedExceedance.py +4 -1
  17. hestia_earth/models/poschEtAl2008/terrestrialEutrophicationPotentialAccumulatedExceedance.py +4 -1
  18. hestia_earth/models/utils/__init__.py +5 -4
  19. hestia_earth/models/utils/impact_assessment.py +13 -4
  20. hestia_earth/models/version.py +1 -1
  21. {hestia_earth_models-0.64.8.dist-info → hestia_earth_models-0.64.9.dist-info}/METADATA +1 -1
  22. {hestia_earth_models-0.64.8.dist-info → hestia_earth_models-0.64.9.dist-info}/RECORD +37 -31
  23. tests/models/environmentalFootprintV3/test_soilQualityIndexLandOccupation.py +97 -66
  24. tests/models/environmentalFootprintV3/test_soilQualityIndexLandTransformation.py +137 -74
  25. tests/models/environmentalFootprintV3/test_soilQualityIndexTotalLandUseEffects.py +15 -10
  26. tests/models/frischknechtEtAl2000/test_ionisingRadiationKbqU235Eq.py +67 -44
  27. tests/models/ipcc2019/animal/test_fatContent.py +22 -0
  28. tests/models/ipcc2019/animal/test_liveweightGain.py +4 -2
  29. tests/models/ipcc2019/animal/test_liveweightPerHead.py +4 -2
  30. tests/models/ipcc2019/animal/test_pregnancyRateTotal.py +22 -0
  31. tests/models/ipcc2019/animal/test_trueProteinContent.py +22 -0
  32. tests/models/ipcc2019/animal/test_weightAtMaturity.py +2 -1
  33. tests/models/poschEtAl2008/test_terrestrialAcidificationPotentialAccumulatedExceedance.py +30 -17
  34. tests/models/poschEtAl2008/test_terrestrialEutrophicationPotentialAccumulatedExceedance.py +28 -14
  35. {hestia_earth_models-0.64.8.dist-info → hestia_earth_models-0.64.9.dist-info}/LICENSE +0 -0
  36. {hestia_earth_models-0.64.8.dist-info → hestia_earth_models-0.64.9.dist-info}/WHEEL +0 -0
  37. {hestia_earth_models-0.64.8.dist-info → hestia_earth_models-0.64.9.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,8 @@
1
1
  import json
2
2
  from unittest.mock import patch
3
3
 
4
+ from pytest import mark
5
+
4
6
  from hestia_earth.models.environmentalFootprintV3.soilQualityIndexLandTransformation import MODEL, TERM_ID, run, \
5
7
  _should_run
6
8
  from tests.utils import fixtures_path, fake_new_indicator
@@ -15,99 +17,160 @@ def fake_rounded_indicator(value: float):
15
17
  return indicator
16
18
 
17
19
 
18
- def test_should_run_ocean(*args):
19
- """
20
- Should not run if a LandCover has no CF (ocean)
21
- """
22
- with open(f"{fixtures_folder}/bad-sites/site-LandCover-has-no-CF.jsonld", encoding='utf-8') as f:
23
- site = json.load(f)
24
-
25
- should_run, *args = _should_run(site)
26
- assert should_run is False
27
-
28
-
29
- def test_should_run_no_management_entries(*args):
30
- """
31
- no management => no run
32
- """
33
- with open(f"{fixtures_folder}/bad-sites/site-no-management.jsonld", encoding='utf-8') as f:
34
- site = json.load(f)
35
-
36
- should_run, *args = _should_run(site)
37
- assert should_run is False
38
-
39
-
40
- def test_should_run_no_sites(*args):
41
- """
42
- impact assessment with no site => no run
43
- """
44
- with open(f"{fixtures_path}/impact_assessment/emissions/impact-assessment.jsonld", encoding='utf-8') as f:
45
- site = json.load(f)
46
-
47
- should_run, *args = _should_run(site)
48
- assert should_run is False
49
-
50
-
51
- def test_should_run_no_transformation(*args):
52
- """
53
- 1 management with no transformation => no run
54
- """
55
- with open(f"{fixtures_folder}/bad-sites/site-no-transformations.jsonld", encoding='utf-8') as f:
56
- site = json.load(f)
57
-
58
- should_run, *args = _should_run(site)
59
- assert should_run is False
60
-
61
-
62
- @patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
63
- def test_run_in_cycle(*args):
64
- with open(f"{fixtures_folder}/Italy/site-italy-inside-cycle.jsonld", encoding='utf-8') as f:
65
- site = json.load(f)
66
-
67
- with open(f"{fixtures_folder}/Italy/result.jsonld", encoding='utf-8') as f:
20
+ crop_land = {"@id": "cropland", "termType": "landCover"}
21
+ sea_land_cover = {"@id": "seaOrOcean", "termType": "landCover"}
22
+ forest = {"@id": "forest", "termType": "landCover"}
23
+
24
+ wrong_indicator = {"term": {"@id": "NOT_VALID_INDICATOR_ID", "termType": "resourceUse", "units": "m2 / year"},
25
+ "value": 0.5, "landCover": crop_land}
26
+
27
+ indicator_no_land_cover = {
28
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse",
29
+ "units": "m2 / year"},
30
+ "value": 0.5}
31
+
32
+ indicator_no_unit = {
33
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse"},
34
+ "value": 0.5, "landCover": crop_land}
35
+
36
+ indicator_wrong_unit = {
37
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse",
38
+ "units": "ha*day"}, "value": 0.5,
39
+ "landCover": crop_land}
40
+
41
+ indicator_bad_area_value = {
42
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse",
43
+ "units": "m2 / year"}, "value": -10,
44
+ "landCover": crop_land}
45
+
46
+ inputs_production_indicator_from_forest_to_no_cf = {
47
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse",
48
+ "units": "m2 / year"}, "value": 0.5,
49
+ "landCover": sea_land_cover}
50
+
51
+ good_inputs_production_indicator_from_forest_to_cropland = {
52
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse",
53
+ "units": "m2 / year"}, "value": 0.5,
54
+ "landCover": crop_land}
55
+
56
+ good_inputs_production_indicator_from_forest_to_forest = {
57
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse",
58
+ "units": "m2 / year"}, "value": 0.5,
59
+ "landCover": forest}
60
+
61
+ good_during_cycle_indicator_from_forest_to_cropland = {
62
+ "term": {"@id": "landTransformationFromForest20YearAverageDuringCycle", "termType": "resourceUse",
63
+ "units": "m2 / year"}, "value": 0.5,
64
+ "landCover": crop_land}
65
+
66
+ good_during_cycle_indicator_from_forest_to_forest = {
67
+ "term": {"@id": "landTransformationFromForest20YearAverageDuringCycle", "termType": "resourceUse",
68
+ "units": "m2 / year"}, "value": 0.5,
69
+ "landCover": forest}
70
+
71
+
72
+ @mark.parametrize(
73
+ "resources, expected, num_inputs",
74
+ [
75
+ ([], True, 0),
76
+ ([wrong_indicator], True, 0),
77
+ ([indicator_no_land_cover], False, 0),
78
+ ([indicator_no_unit], False, 0),
79
+ ([indicator_wrong_unit], False, 0),
80
+ ([indicator_bad_area_value], False, 0),
81
+ ([good_during_cycle_indicator_from_forest_to_cropland], True, 1),
82
+ ([good_during_cycle_indicator_from_forest_to_forest], True, 1),
83
+ ([good_inputs_production_indicator_from_forest_to_cropland], True, 1),
84
+ ([good_inputs_production_indicator_from_forest_to_forest], True, 1),
85
+ ([inputs_production_indicator_from_forest_to_no_cf], True, 0), # todo check
86
+ ([good_inputs_production_indicator_from_forest_to_cropland,
87
+ good_during_cycle_indicator_from_forest_to_cropland], True, 2)
88
+ ],
89
+ ids=["No emissionsResourceUse => run, 0 dict",
90
+ "Wrong indicator termid => run, 0 dict",
91
+ "Indicator no landcover terms => no run",
92
+ "Missing unit => no run",
93
+ "Wrong unit => no run",
94
+ "Bad m2 / year value => no run",
95
+ "One good during cycle transformation => run, 1 dict",
96
+ "One 0 during cycle transformation => run, 1 dict",
97
+ "One good inputs production transformation => run, 1 dict",
98
+ "One 0 inputs production transformation => run, 1 dict",
99
+ "One good from transformation and One with no CF (ocean) => run, 2 dict", # todo
100
+ "Multiple good indicators => run, 2 dict",
101
+ ]
102
+ )
103
+ @patch(f"{class_path}.download_all_land_cover_terms",
104
+ return_value=[{'@id': 'cropland'}, {'@id': 'seaOrOcean'}, {'@id': 'forest'}])
105
+ def test_should_run(mock_download, resources, expected, num_inputs):
106
+ with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
107
+ impact = json.load(f)
108
+
109
+ impact['emissionsResourceUse'] = resources
110
+
111
+ should_run, resources_with_cf = _should_run(impact)
112
+ assert should_run is expected
113
+ assert len(resources_with_cf) == num_inputs
114
+
115
+
116
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
117
+ def test_run(*args):
118
+ with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
119
+ impact = json.load(f)
120
+
121
+ with open(f"{fixtures_folder}/multipleTransformations/result.jsonld", encoding='utf-8') as f:
68
122
  expected = json.load(f)
69
123
 
70
- value = run(site)
124
+ value = run(impact)
71
125
  assert value == expected
72
126
 
73
127
 
74
- @patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
75
- def test_run_other_sites(*args):
76
- with open(f"{fixtures_folder}/Italy/site-italy-otherSites.jsonld", encoding='utf-8') as f:
77
- site = json.load(f)
128
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
129
+ def test_run_italy(*args):
130
+ with open(f"{fixtures_folder}/Italy/impact-assessment.jsonld", encoding='utf-8') as f:
131
+ impact = json.load(f)
78
132
 
79
- with open(f"{fixtures_folder}/Italy/result-otherSites.jsonld", encoding='utf-8') as f:
133
+ with open(f"{fixtures_folder}/Italy/result.jsonld", encoding='utf-8') as f:
80
134
  expected = json.load(f)
81
135
 
82
- value = run(site)
136
+ value = run(impact)
83
137
  assert value == expected
84
138
 
85
139
 
140
+ @mark.parametrize(
141
+ "added_data",
142
+ [
143
+ {"country": {}},
144
+ {"country": {"@id": "region-europe", "@type": "Term", "name": "Europe"}},
145
+ ],
146
+ ids=["No country/region => default to region world",
147
+ "region-europe not in the lookup file => default to region world"]
148
+ )
86
149
  @patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
87
- def test_run_with_region(*args):
150
+ def test_run_with_country_fallback(mocked_indicator, added_data):
88
151
  """
89
- When given valid sub-region or country not in the lookup file should default to 'region-world'
152
+ When given valid sub-region or country not in the lookup file, default to country 'region-world' with value 574.56
90
153
  """
91
- with open(f"{fixtures_folder}/region-world/region-europe.jsonld", encoding='utf-8') as f:
92
- site = json.load(f)
93
154
 
94
- with open(f"{fixtures_folder}/region-world/result-default-region-world.jsonld", encoding='utf-8') as f:
95
- expected = json.load(f)
155
+ with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
156
+ impact = json.load(f)
96
157
 
97
- value = run(site)
98
- assert value == expected
158
+ impact = impact | added_data
99
159
 
160
+ value = run(impact)
161
+ assert value['value'] == 574.56
100
162
 
101
- @patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
102
- def test_run_with_no_region(*args):
163
+
164
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
165
+ def test_run_no_transformation(*args):
103
166
  """
104
- When no location is specified, defaults to region world.
167
+ Impact assessment with no transformations should return a indicator of 0
105
168
  """
106
- with open(f"{fixtures_folder}/region-world/no-region.jsonld", encoding='utf-8') as f:
107
- site = json.load(f)
169
+ with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
170
+ impact = json.load(f)
108
171
 
109
- with open(f"{fixtures_folder}/region-world/result-default-region-world.jsonld", encoding='utf-8') as f:
110
- expected = json.load(f)
172
+ impact['emissionsResourceUse'] = []
111
173
 
112
- value = run(site)
113
- assert value == expected
174
+ value = run(impact)
175
+
176
+ assert value['value'] == 0
@@ -17,25 +17,30 @@ bad_value_indicator = {'term': {'@id': 'soilQualityIndexLandOccupation'}, 'value
17
17
 
18
18
 
19
19
  @mark.parametrize(
20
- "emissions_resource_use, expected",
20
+ "emissions_resource_use, expected, num_expected",
21
21
  [
22
- ([], False),
23
- ([transform_indicator], False),
24
- ([transform_indicator, transform_indicator], False),
25
- ([transform_indicator, missing_value_indicator], False),
26
- ([transform_indicator, bad_value_indicator], False),
27
- ([transform_indicator, occupation_indicator], True),
22
+ ([], False, 0),
23
+ ([transform_indicator], False, 1),
24
+ ([transform_indicator, transform_indicator], False, 2),
25
+ ([transform_indicator, missing_value_indicator], False, 2),
26
+ ([transform_indicator, bad_value_indicator], False, 2),
27
+ ([transform_indicator, occupation_indicator], True, 2),
28
+ ([occupation_indicator], False, 1),
29
+ ([occupation_indicator, occupation_indicator, occupation_indicator,
30
+ transform_indicator, transform_indicator], True, 5),
28
31
  ],
29
- ids=["Empty", "missing entry", "duplicate entry", "no value in entry", "bad value in entry", "correct assessment"]
32
+ ids=["Empty", "missing obligatory occupation", "duplicate entry", "no value in entry", "bad value in entry",
33
+ "correct assessment", "just occupation", "multiple occupations and transformations"]
30
34
  )
31
- def test_should_run(emissions_resource_use, expected):
35
+ def test_should_run(emissions_resource_use, expected, num_expected):
32
36
  with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
33
37
  impactassessment = json.load(f)
34
38
 
35
39
  impactassessment['emissionsResourceUse'] = emissions_resource_use
36
40
 
37
- should_run, *args = _should_run(impactassessment)
41
+ should_run, indicators = _should_run(impactassessment)
38
42
  assert should_run is expected
43
+ assert len(indicators) is num_expected
39
44
 
40
45
 
41
46
  @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
@@ -8,54 +8,77 @@ from hestia_earth.models.frischknechtEtAl2000.ionisingRadiationKbqU235Eq import
8
8
  class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
9
9
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
10
 
11
+ hydrogen3_input = {"@id": "hydrogen3", "termType": "waste", "units": "kg"}
12
+ cesium134_input = {"@id": "cesium134", "termType": "waste", "units": "kg"}
13
+ cesium137_input = {"@id": "cesium137", "termType": "waste", "units": "kg"}
14
+ uranium234_input = {"@id": "uranium234", "termType": "waste", "units": "kg"}
15
+ iodine129_input = {"@id": "iodine129", "termType": "waste", "units": "kg"}
16
+ no_cf_input = {"@id": "oilPalmMillEffluentWaste", "termType": "waste", "units": "kg"}
17
+
18
+ wrong_indicator = {"term": {"@id": "co2ToAirSoilOrganicCarbonStockChangeManagementChange", "termType": "emission"},
19
+ "value": 3, "inputs": [hydrogen3_input]}
20
+
21
+ indicator_no_inputs = {"term": {"@id": "ionisingCompoundsToAirInputsProduction", "termType": "emission"},
22
+ "value": 3, "inputs": []}
23
+
24
+ indicator_2_inputs = {"term": {"@id": "ionisingCompoundsToWaterInputsProduction", "termType": "emission"},
25
+ "value": 3, "inputs": [cesium134_input, cesium137_input]}
26
+
27
+ indicator_no_unit = {"term": {"@id": "ionisingCompoundsToAirInputsProduction", "termType": "emission"},
28
+ "value": 3, "inputs": [{"@id": "hydrogen3", "termType": "waste"}]}
29
+
30
+ indicator_wrong_unit = {"term": {"@id": "ionisingCompoundsToAirInputsProduction", "termType": "emission"},
31
+ "value": 3, "inputs": [{"@id": "hydrogen3", "termType": "waste", "units": "not_a_unit"}]}
32
+
33
+ indicator_no_cf_input = {"term": {"@id": "ionisingCompoundsToAirInputsProduction", "termType": "emission"},
34
+ "value": 3, "inputs": [no_cf_input]}
35
+
36
+ indicator_hydrogen3_input = {"term": {"@id": "ionisingCompoundsToAirInputsProduction", "termType": "emission"},
37
+ "value": 3, "inputs": [hydrogen3_input]}
38
+
39
+ indicator_cesium137_input = {"term": {"@id": "ionisingCompoundsToWaterInputsProduction", "termType": "emission"},
40
+ "value": 3, "inputs": [cesium137_input]}
41
+
42
+ indicator_uranium234_input = {"term": {"@id": "ionisingCompoundsToSaltwaterInputsProduction", "termType": "emission"},
43
+ "value": 3, "inputs": [uranium234_input]}
44
+
11
45
 
12
46
  @pytest.mark.parametrize(
13
- 'test_name,impact,expected_should_run',
47
+ "resources, expected, num_inputs",
14
48
  [
15
- (
16
- 'no emissionsResourceUse => no run',
17
- {},
18
- False
19
- ),
20
- (
21
- 'no emissions in the lookups list => no run',
22
- {
23
- 'emissionsResourceUse': [
24
- {
25
- 'term': {'@id': 'co2ToAirInputsProduction'}
26
- }
27
- ]
28
- },
29
- False
30
- ),
31
- (
32
- 'with emissions in the lookup list but no waste inputs => no run',
33
- {
34
- 'emissionsResourceUse': [
35
- {
36
- 'term': {'@id': 'ionisingCompoundsToAirInputsProduction'}
37
- }
38
- ]
39
- },
40
- False
41
- ),
42
- (
43
- 'with emissions in the lookup list and waste inputs => run',
44
- {
45
- 'emissionsResourceUse': [
46
- {
47
- 'term': {'@id': 'ionisingCompoundsToAirInputsProduction'},
48
- 'inputs': [{'termType': 'waste'}]
49
- }
50
- ]
51
- },
52
- True
53
- )
54
- ]
49
+ ([], True, 0),
50
+ ([wrong_indicator], True, 0),
51
+ ([indicator_no_inputs], False, 0),
52
+ ([indicator_2_inputs], False, 0),
53
+ ([indicator_no_unit], False, 0),
54
+ ([indicator_wrong_unit], False, 0),
55
+ ([indicator_no_cf_input], True, 0),
56
+ ([indicator_hydrogen3_input], True, 1),
57
+ ([indicator_cesium137_input], True, 1),
58
+ ([indicator_uranium234_input], True, 1),
59
+ ([indicator_cesium137_input, indicator_no_cf_input], True, 1),
60
+ ],
61
+ ids=["No emissionsResourceUse => run, empty input",
62
+ "Wrong indicator termid => run, empty input",
63
+ "Indicator no inputs => no run",
64
+ "Indicator 2 inputs => no run",
65
+ "Missing unit => no run",
66
+ "Wrong unit => no run",
67
+ "Input with no cf => run, empty input",
68
+ "Good input ionisingCompoundsToAirInputsProduction => run, 1 input",
69
+ "Good input ionisingCompoundsToWaterInputsProduction => run, 1 input",
70
+ "Good input ionisingCompoundsToSaltwaterInputsProduction => run, 1 input",
71
+ "One good input => run, 1 input"]
55
72
  )
56
- def test_should_run(test_name, impact, expected_should_run):
57
- should_run, *args = _should_run(impact)
58
- assert should_run == expected_should_run, test_name
73
+ def test_should_run(resources, expected, num_inputs):
74
+ with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
75
+ impactassessment = json.load(f)
76
+
77
+ impactassessment['emissionsResourceUse'] = resources
78
+
79
+ should_run, resources_with_cf = _should_run(impactassessment)
80
+ assert should_run is expected
81
+ assert len(resources_with_cf) == num_inputs
59
82
 
60
83
 
61
84
  @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
@@ -0,0 +1,22 @@
1
+ from unittest.mock import patch
2
+ import json
3
+ from tests.utils import fixtures_path, fake_new_property
4
+
5
+ from hestia_earth.models.ipcc2019 import MODEL
6
+ from hestia_earth.models.ipcc2019.animal.fatContent import TERM_ID, run
7
+
8
+ utils_path = '.'.join(['hestia_earth', 'models', MODEL, 'animal', 'utils'])
9
+ class_path = f"hestia_earth.models.{MODEL}.animal.{TERM_ID}"
10
+ fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{TERM_ID}"
11
+
12
+
13
+ @patch(f"{utils_path}._new_property", side_effect=fake_new_property)
14
+ def test_run(*args):
15
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
16
+ cycle = json.load(f)
17
+
18
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
19
+ expected = json.load(f)
20
+
21
+ value = run(cycle)
22
+ assert value == expected
@@ -2,13 +2,15 @@ from unittest.mock import patch
2
2
  import json
3
3
  from tests.utils import fixtures_path, fake_new_property
4
4
 
5
- from hestia_earth.models.ipcc2019.animal.liveweightGain import MODEL, TERM_ID, run
5
+ from hestia_earth.models.ipcc2019 import MODEL
6
+ from hestia_earth.models.ipcc2019.animal.liveweightGain import TERM_ID, run
6
7
 
8
+ utils_path = '.'.join(['hestia_earth', 'models', MODEL, 'animal', 'utils'])
7
9
  class_path = f"hestia_earth.models.{MODEL}.animal.{TERM_ID}"
8
10
  fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{TERM_ID}"
9
11
 
10
12
 
11
- @patch(f"{class_path}._new_property", side_effect=fake_new_property)
13
+ @patch(f"{utils_path}._new_property", side_effect=fake_new_property)
12
14
  def test_run(*args):
13
15
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
14
16
  cycle = json.load(f)
@@ -2,13 +2,15 @@ from unittest.mock import patch
2
2
  import json
3
3
  from tests.utils import fixtures_path, fake_new_property
4
4
 
5
- from hestia_earth.models.ipcc2019.animal.liveweightPerHead import MODEL, TERM_ID, run
5
+ from hestia_earth.models.ipcc2019 import MODEL
6
+ from hestia_earth.models.ipcc2019.animal.liveweightPerHead import TERM_ID, run
6
7
 
8
+ utils_path = '.'.join(['hestia_earth', 'models', MODEL, 'animal', 'utils'])
7
9
  class_path = f"hestia_earth.models.{MODEL}.animal.{TERM_ID}"
8
10
  fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{TERM_ID}"
9
11
 
10
12
 
11
- @patch(f"{class_path}._new_property", side_effect=fake_new_property)
13
+ @patch(f"{utils_path}._new_property", side_effect=fake_new_property)
12
14
  def test_run(*args):
13
15
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
14
16
  cycle = json.load(f)
@@ -0,0 +1,22 @@
1
+ from unittest.mock import patch
2
+ import json
3
+ from tests.utils import fixtures_path, fake_new_property
4
+
5
+ from hestia_earth.models.ipcc2019 import MODEL
6
+ from hestia_earth.models.ipcc2019.animal.pregnancyRateTotal import TERM_ID, run
7
+
8
+ utils_path = '.'.join(['hestia_earth', 'models', MODEL, 'animal', 'utils'])
9
+ class_path = f"hestia_earth.models.{MODEL}.animal.{TERM_ID}"
10
+ fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{TERM_ID}"
11
+
12
+
13
+ @patch(f"{utils_path}._new_property", side_effect=fake_new_property)
14
+ def test_run(*args):
15
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
16
+ cycle = json.load(f)
17
+
18
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
19
+ expected = json.load(f)
20
+
21
+ value = run(cycle)
22
+ assert value == expected
@@ -0,0 +1,22 @@
1
+ from unittest.mock import patch
2
+ import json
3
+ from tests.utils import fixtures_path, fake_new_property
4
+
5
+ from hestia_earth.models.ipcc2019 import MODEL
6
+ from hestia_earth.models.ipcc2019.animal.trueProteinContent import TERM_ID, run
7
+
8
+ utils_path = '.'.join(['hestia_earth', 'models', MODEL, 'animal', 'utils'])
9
+ class_path = f"hestia_earth.models.{MODEL}.animal.{TERM_ID}"
10
+ fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{TERM_ID}"
11
+
12
+
13
+ @patch(f"{utils_path}._new_property", side_effect=fake_new_property)
14
+ def test_run(*args):
15
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
16
+ cycle = json.load(f)
17
+
18
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
19
+ expected = json.load(f)
20
+
21
+ value = run(cycle)
22
+ assert value == expected
@@ -2,7 +2,8 @@ from unittest.mock import patch
2
2
  import json
3
3
  from tests.utils import fixtures_path, fake_new_property
4
4
 
5
- from hestia_earth.models.ipcc2019.animal.weightAtMaturity import MODEL, TERM_ID, run
5
+ from hestia_earth.models.ipcc2019 import MODEL
6
+ from hestia_earth.models.ipcc2019.animal.weightAtMaturity import TERM_ID, run
6
7
 
7
8
  class_path = f"hestia_earth.models.{MODEL}.animal.{TERM_ID}"
8
9
  fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{TERM_ID}"
@@ -1,45 +1,58 @@
1
1
  import json
2
2
  from unittest.mock import patch
3
3
 
4
- from hestia_earth.models.poschEtAl2008.terrestrialAcidificationPotentialAccumulatedExceedance import MODEL, TERM_ID, run
4
+ from hestia_earth.models.poschEtAl2008.terrestrialAcidificationPotentialAccumulatedExceedance import MODEL, TERM_ID, \
5
+ run
5
6
  from tests.utils import fixtures_path, fake_new_indicator
6
7
 
7
8
  class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
9
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
10
 
10
11
 
12
+ def fake_rounded_indicator(value: float):
13
+ indicator = fake_new_indicator(TERM_ID, MODEL)
14
+ indicator['value'] = round(value, 7)
15
+ return indicator
16
+
17
+
11
18
  @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
12
19
  def test_run(*args):
13
20
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
14
- cycle = json.load(f)
21
+ impactassessment = json.load(f)
15
22
 
16
- with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
23
+ with open(f"{fixtures_folder}/Australia/result.jsonld", encoding='utf-8') as f:
17
24
  expected = json.load(f)
18
25
 
19
- value = run(cycle)
26
+ value = run(impactassessment)
20
27
  assert value == expected
21
28
 
22
29
 
23
- @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
30
+ @patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
24
31
  def test_lookup_to_bad_country(*args):
32
+ """
33
+ Should default to region-world value
34
+ """
25
35
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
26
- cycle = json.load(f)
27
- cycle['country']['@id'] = "example-land-not-real"
36
+ impactassessment = json.load(f)
28
37
 
29
- value = run(cycle)
30
- assert value['value'] is None
38
+ impactassessment['country']['@id'] = "example-land-not-real"
39
+
40
+ with open(f"{fixtures_folder}/region-world/result.jsonld", encoding='utf-8') as f:
41
+ expected = json.load(f)
42
+
43
+ value = run(impactassessment)
44
+ assert value == expected
31
45
 
32
46
 
33
47
  @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
34
- def test_lookup_no_term_type(*args):
48
+ def test_run_no_emissions(*args):
35
49
  """
36
- We currently do not filter out bad termTypes so this is expected behavior.
50
+ Impact assessment with no emissions should return a indicator of 0
37
51
  """
38
52
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
39
- cycle = json.load(f)
40
- del cycle['emissionsResourceUse'][0]['term']['termType']
41
- del cycle['emissionsResourceUse'][1]['term']['termType']
42
- cycle['emissionsResourceUse'][2]['term']['termType'] = "wrong-type"
53
+ impactassessment = json.load(f)
54
+
55
+ del impactassessment['emissionsResourceUse']
43
56
 
44
- value = run(cycle)
45
- assert value['value'] == 0.085
57
+ value = run(impactassessment)
58
+ assert value['value'] == 0