hestia-earth-models 0.66.0__py3-none-any.whl → 0.67.1__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.
Files changed (65) hide show
  1. hestia_earth/models/cml2001Baseline/abioticResourceDepletionFossilFuels.py +23 -54
  2. hestia_earth/models/cml2001Baseline/resourceUseEnergyDepletionDuringCycle.py +147 -0
  3. hestia_earth/models/cml2001Baseline/resourceUseEnergyDepletionInputsProduction.py +40 -0
  4. hestia_earth/models/cml2001Baseline/resourceUseMineralsAndMetalsDuringCycle.py +80 -0
  5. hestia_earth/models/cml2001Baseline/resourceUseMineralsAndMetalsInputsProduction.py +40 -0
  6. hestia_earth/models/config/ImpactAssessment.json +1869 -1846
  7. hestia_earth/models/cycle/completeness/freshForage.py +7 -3
  8. hestia_earth/models/cycle/inorganicFertiliser.py +67 -17
  9. hestia_earth/models/cycle/input/hestiaAggregatedData.py +13 -10
  10. hestia_earth/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/__init__.py +4 -3
  11. hestia_earth/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/environmentalFootprintSingleOverallScore.py +42 -37
  12. hestia_earth/models/environmentalFootprintV3_1/marineEutrophicationPotential.py +36 -0
  13. hestia_earth/models/environmentalFootprintV3_1/scarcityWeightedWaterUse.py +40 -0
  14. hestia_earth/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/soilQualityIndexLandTransformation.py +22 -14
  15. hestia_earth/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/soilQualityIndexTotalLandUseEffects.py +17 -15
  16. hestia_earth/models/hestia/landTransformation100YearAverageDuringCycle.py +1 -1
  17. hestia_earth/models/hestia/landTransformation20YearAverageDuringCycle.py +1 -1
  18. hestia_earth/models/impact_assessment/product/value.py +1 -1
  19. hestia_earth/models/ipcc2019/aboveGroundBiomass.py +2 -2
  20. hestia_earth/models/ipcc2019/belowGroundBiomass.py +2 -2
  21. hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +2 -1
  22. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +6 -5
  23. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +3 -2
  24. hestia_earth/models/mocking/search-results.json +1200 -1068
  25. hestia_earth/models/site/management.py +2 -2
  26. hestia_earth/models/utils/__init__.py +6 -0
  27. hestia_earth/models/utils/aggregated.py +13 -10
  28. hestia_earth/models/utils/array_builders.py +4 -3
  29. hestia_earth/models/utils/blank_node.py +78 -21
  30. hestia_earth/models/utils/ecoClimateZone.py +2 -2
  31. hestia_earth/models/utils/impact_assessment.py +5 -4
  32. hestia_earth/models/utils/lookup.py +5 -5
  33. hestia_earth/models/utils/property.py +5 -2
  34. hestia_earth/models/version.py +1 -1
  35. hestia_earth/orchestrator/log.py +11 -0
  36. hestia_earth/orchestrator/models/__init__.py +8 -3
  37. {hestia_earth_models-0.66.0.dist-info → hestia_earth_models-0.67.1.dist-info}/METADATA +1 -1
  38. {hestia_earth_models-0.66.0.dist-info → hestia_earth_models-0.67.1.dist-info}/RECORD +64 -52
  39. tests/models/cml2001Baseline/test_abioticResourceDepletionFossilFuels.py +51 -87
  40. tests/models/cml2001Baseline/test_resourceUseEnergyDepletionDuringCycle.py +136 -0
  41. tests/models/cml2001Baseline/test_resourceUseEnergyDepletionInputsProduction.py +23 -0
  42. tests/models/cml2001Baseline/test_resourceUseMineralsAndMetalsDuringCycle.py +58 -0
  43. tests/models/cml2001Baseline/test_resourceUseMineralsAndMetalsInputsProduction.py +23 -0
  44. tests/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/test_environmentalFootprintSingleOverallScore.py +43 -12
  45. tests/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/test_freshwaterEcotoxicityPotentialCtue.py +6 -5
  46. tests/models/environmentalFootprintV3_1/test_marineEutrophicationPotential.py +27 -0
  47. tests/models/environmentalFootprintV3_1/test_scarcityWeightedWaterUse.py +32 -0
  48. tests/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/test_soilQualityIndexLandOccupation.py +4 -3
  49. tests/models/environmentalFootprintV3_1/test_soilQualityIndexLandTransformation.py +194 -0
  50. tests/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/test_soilQualityIndexTotalLandUseEffects.py +4 -4
  51. tests/models/impact_assessment/test_emissions.py +0 -1
  52. tests/models/site/test_management.py +1 -4
  53. tests/models/test_config.py +3 -3
  54. tests/models/test_ecoinventV3.py +0 -1
  55. tests/models/utils/test_array_builders.py +2 -2
  56. tests/models/utils/test_blank_node.py +13 -165
  57. tests/orchestrator/models/test_transformations.py +4 -1
  58. tests/models/environmentalFootprintV3/test_soilQualityIndexLandTransformation.py +0 -164
  59. /hestia_earth/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/freshwaterEcotoxicityPotentialCtue.py +0 -0
  60. /hestia_earth/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/soilQualityIndexLandOccupation.py +0 -0
  61. /hestia_earth/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/utils.py +0 -0
  62. {hestia_earth_models-0.66.0.dist-info → hestia_earth_models-0.67.1.dist-info}/LICENSE +0 -0
  63. {hestia_earth_models-0.66.0.dist-info → hestia_earth_models-0.67.1.dist-info}/WHEEL +0 -0
  64. {hestia_earth_models-0.66.0.dist-info → hestia_earth_models-0.67.1.dist-info}/top_level.txt +0 -0
  65. /tests/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/__init__.py +0 -0
@@ -18,10 +18,7 @@ _LAND_COVER_TERM_BY_SITE_TYPE = {
18
18
  _folders = [d for d in os.listdir(fixtures_folder) if os.path.isdir(os.path.join(fixtures_folder, d))]
19
19
 
20
20
 
21
- @pytest.mark.parametrize(
22
- "folder",
23
- _folders
24
- )
21
+ @pytest.mark.parametrize('folder', _folders)
25
22
  @patch(
26
23
  f"{class_path}.get_landCover_term_id_from_site_type",
27
24
  side_effect=lambda site_type: _LAND_COVER_TERM_BY_SITE_TYPE[site_type]
@@ -1,5 +1,6 @@
1
- import pytest
2
1
  import importlib
2
+
3
+ import pytest
3
4
  from hestia_earth.utils.tools import flatten
4
5
 
5
6
  from hestia_earth.models.config import (
@@ -7,7 +8,6 @@ from hestia_earth.models.config import (
7
8
  get_max_stage
8
9
  )
9
10
 
10
-
11
11
  _aggregated_model = {
12
12
  "value": "input.hestiaAggregatedData"
13
13
  }
@@ -89,7 +89,7 @@ _ignore_values = [None, '', 'all']
89
89
 
90
90
 
91
91
  def _model_path(model: dict):
92
- name = model.get('model')
92
+ name = model.get('model').replace('-', '_')
93
93
  value = model.get('value')
94
94
  suffix = f"hestia_earth.models.{name}"
95
95
  return f"{suffix}.{value}" if value not in _ignore_values else suffix
@@ -50,7 +50,6 @@ def test_run(*args):
50
50
  expected = json.load(f)
51
51
 
52
52
  result = run('all', cycle)
53
- # print(json.dumps(result, indent=2))
54
53
  assert result == expected
55
54
 
56
55
 
@@ -242,8 +242,8 @@ def test_avg_run_in_rowwise():
242
242
 
243
243
  def test_gen_seed():
244
244
  NODE = {"@id": "site"}
245
- EXPECTED = 2926675914
246
- result = gen_seed(NODE)
245
+ EXPECTED = 1209943397
246
+ result = gen_seed(NODE, "model", "term")
247
247
  assert result == EXPECTED
248
248
 
249
249
 
@@ -30,178 +30,26 @@ from hestia_earth.models.utils.blank_node import (
30
30
 
31
31
 
32
32
  class_path = "hestia_earth.models.utils.blank_node"
33
- measurement_fixtures_folder = f"{fixtures_path}/utils/measurement"
33
+ fixtures_folder = os.path.join(fixtures_path, 'utils', 'blank_node')
34
+ measurement_fixtures_folder = os.path.join(fixtures_path, 'utils', 'measurement')
35
+
36
+ condense_fixtures_folder = os.path.join(fixtures_folder, 'condense-nodes')
37
+ condense_folders = [
38
+ d for d in os.listdir(condense_fixtures_folder) if os.path.isdir(os.path.join(condense_fixtures_folder, d))
39
+ ]
34
40
 
35
- fixtures_path = os.path.join(fixtures_path, 'utils', 'blank_node')
36
41
 
42
+ @pytest.mark.parametrize('folder', condense_folders)
43
+ def test_condense_nodes(folder: str):
44
+ fixture_path = os.path.join(condense_fixtures_folder, folder)
37
45
 
38
- def test_condense_nodes():
39
- with open(f"{fixtures_path}/condense-nodes/original.jsonld", encoding='utf-8') as f:
46
+ with open(f"{fixture_path}/original.jsonld", encoding='utf-8') as f:
40
47
  original = json.load(f)
41
- with open(f"{fixtures_path}/condense-nodes/result.jsonld", encoding='utf-8') as f:
48
+ with open(f"{fixture_path}/result.jsonld", encoding='utf-8') as f:
42
49
  expected = json.load(f)
43
50
 
44
51
  value = condense_nodes(original)
45
- assert value == expected
46
-
47
-
48
- @pytest.mark.parametrize(
49
- "test_name,input_nodes,expected_output_nodes",
50
- [
51
- (
52
- "No match",
53
- [
54
- {"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
55
- "value": [2]},
56
- {"startDate": "2003", "endDate": "2004", "term": {"@id": "bananaPlant", "units": "% area"},
57
- "value": [2]},
58
- ],
59
- [
60
- {"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
61
- "value": [2]},
62
- {"startDate": "2003", "endDate": "2004", "term": {"@id": "bananaPlant", "units": "% area"},
63
- "value": [2]},
64
- ],
65
- ),
66
- (
67
- "No continuity",
68
- [
69
- {"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
70
- "value": [2]},
71
- {"startDate": "2004", "endDate": "2005", "term": {"@id": "treeNutTree", "units": "% area"},
72
- "value": [2]},
73
- ],
74
- [
75
- {"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
76
- "value": [2]},
77
- {"startDate": "2004", "endDate": "2005", "term": {"@id": "treeNutTree", "units": "% area"},
78
- "value": [2]},
79
- ],
80
- ),
81
- (
82
- "No continuity (multiple values differ)",
83
- [
84
- {"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
85
- "value": [10, 20]},
86
- {"startDate": "2003", "endDate": "2004", "term": {"@id": "treeNutTree", "units": "% area"},
87
- "value": [10, 30]},
88
- ],
89
- [
90
- {"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
91
- "value": [10, 20]},
92
- {"startDate": "2003", "endDate": "2004", "term": {"@id": "treeNutTree", "units": "% area"},
93
- "value": [10, 30]},
94
- ],
95
- ),
96
- (
97
- "2-1 condense (YYYY dates)",
98
- [
99
- {"startDate": "2001", "endDate": "2001", "term": {"@id": "treeNutTree", "units": "% area"},
100
- "value": [10, 20]},
101
- {"startDate": "2002", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
102
- "value": [10, 20]},
103
- ],
104
- [
105
- {"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
106
- "value": [10, 20]}
107
- ],
108
- ),
109
- (
110
- "4-2 condense (YYYY-MM dates)",
111
- [
112
- {"startDate": "2001-01", "endDate": "2002-01", "term": {"@id": "treeNutTree", "units": "% area"},
113
- "value": [2]},
114
- {"startDate": "2002-01", "endDate": "2002-03", "term": {"@id": "treeNutTree", "units": "% area"},
115
- "value": [2]},
116
- ],
117
- [
118
- {"startDate": "2001-01", "endDate": "2002-03", "term": {"@id": "treeNutTree", "units": "% area"},
119
- "value": [2]}
120
- ],
121
- ),
122
- (
123
- "2-1 condense (YYYY-MM-DD dates)",
124
- [
125
- {"startDate": "2001-01-01", "endDate": "2001-12-31", "term": {"@id": "treeNutTree", "units": "% area"},
126
- "value": [2]},
127
- {"startDate": "2002-01-01", "endDate": "2002-05-04", "term": {"@id": "treeNutTree", "units": "% area"},
128
- "value": [2]},
129
- ],
130
- [
131
- {"startDate": "2001-01-01", "endDate": "2002-05-04", "term": {"@id": "treeNutTree", "units": "% area"},
132
- "value": [2]}
133
- ],
134
- ),
135
- (
136
- "3-1-condense",
137
- [
138
- {"startDate": "2001-01-01", "endDate": "2001-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
139
- "value": [9]},
140
- {"startDate": "2002-01-01", "endDate": "2002-10-31", "term": {"@id": "bananaPlant", "units": "% area"},
141
- "value": [9]},
142
- {"startDate": "2002-11-01", "endDate": "2004-04-05", "term": {"@id": "bananaPlant", "units": "% area"},
143
- "value": [9]},
144
- ],
145
- [
146
- {"startDate": "2001-01-01", "endDate": "2004-04-05", "term": {"@id": "bananaPlant", "units": "% area"},
147
- "value": [9]}
148
- ],
149
- ),
150
- (
151
- "3-2-partial-condense",
152
- [
153
- {"startDate": "2001-01-01", "endDate": "2001-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
154
- "value": [9]},
155
- {"startDate": "2012-02-01", "endDate": "2012-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
156
- "value": [9]},
157
- {"startDate": "2002-01-01", "endDate": "2003-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
158
- "value": [9]},
159
- ],
160
- [
161
- {"startDate": "2001-01-01", "endDate": "2003-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
162
- "value": [9]},
163
- {"startDate": "2012-02-01", "endDate": "2012-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
164
- "value": [9]},
165
- ],
166
- ),
167
- (
168
- "7-2-multi-condense",
169
- [
170
- {"startDate": "2001-01-01", "endDate": "2001-11-30", "term": {"@id": "bananaPlant", "units": "% area"},
171
- "value": [7]},
172
- {"startDate": "2012-02-01", "endDate": "2012-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
173
- "value": [7]},
174
- {"startDate": "2001-12-01", "endDate": "2001-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
175
- "value": [7]},
176
- {"startDate": "2002-01-01", "endDate": "2002-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
177
- "value": [7]},
178
- {"startDate": "2013-01-01", "endDate": "2013-05-20", "term": {"@id": "bananaPlant", "units": "% area"},
179
- "value": [7]},
180
- ],
181
- [
182
- {"startDate": "2001-01-01", "endDate": "2002-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
183
- "value": [7]},
184
- {"startDate": "2012-02-01", "endDate": "2013-05-20", "term": {"@id": "bananaPlant", "units": "% area"},
185
- "value": [7]}
186
- ],
187
- ),
188
- (
189
- "same-blank-nodes-sum",
190
- [
191
- {"startDate": "2001-01-01", "endDate": "2001-11-30", "term": {"@id": "bananaPlant", "units": "% area"},
192
- "value": [50]},
193
- {"startDate": "2001-01-01", "endDate": "2001-11-30", "term": {"@id": "bananaPlant", "units": "% area"},
194
- "value": [50]}
195
- ],
196
- [
197
- {"startDate": "2001-01-01", "endDate": "2001-11-30", "term": {"@id": "bananaPlant", "units": "% area"},
198
- "value": [100]}
199
- ]
200
- )
201
- ]
202
- )
203
- def test_condense_nodes_(test_name, input_nodes, expected_output_nodes):
204
- assert condense_nodes(input_nodes) == expected_output_nodes
52
+ assert value == expected, folder
205
53
 
206
54
 
207
55
  def test_run_required():
@@ -2,13 +2,16 @@ from unittest.mock import patch
2
2
  import json
3
3
  import os
4
4
 
5
- from tests.utils import fixtures_path
5
+ from tests.utils import fixtures_path, fake_new_emission, fake_new_product, fake_new_input
6
6
  from hestia_earth.orchestrator.models.transformations import run, _include_practice
7
7
 
8
8
  folder_path = os.path.join(fixtures_path, 'orchestrator', 'transformation')
9
9
 
10
10
 
11
11
  @patch('hestia_earth.orchestrator.strategies.merge._merge_version', return_value='0.0.0')
12
+ @patch('hestia_earth.models.transformation.input.excreta._new_input', side_effect=fake_new_input)
13
+ @patch('hestia_earth.models.transformation.product.excreta._new_product', side_effect=fake_new_product)
14
+ @patch('hestia_earth.models.ipcc2019.n2OToAirExcretaDirect._new_emission', side_effect=fake_new_emission)
12
15
  def test_run(*args):
13
16
  with open(os.path.join(folder_path, 'config.json'), encoding='utf-8') as f:
14
17
  config = json.load(f)
@@ -1,164 +0,0 @@
1
- import json
2
- from unittest.mock import Mock, patch
3
-
4
- from pytest import mark
5
-
6
- from hestia_earth.models.environmentalFootprintV3.soilQualityIndexLandTransformation import (
7
- MODEL, TERM_ID, run, _should_run
8
- )
9
- from tests.utils import fixtures_path, fake_new_indicator
10
-
11
- class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
12
- fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
13
-
14
-
15
- def fake_rounded_indicator(value: float):
16
- indicator = fake_new_indicator(TERM_ID, MODEL)
17
- indicator['value'] = round(value, 7)
18
- return indicator
19
-
20
-
21
- crop_land = {"@id": "cropland", "termType": "landCover"}
22
- sea_land_cover = {"@id": "seaOrOcean", "termType": "landCover"}
23
- forest = {"@id": "forest", "termType": "landCover"}
24
- indicator = {
25
- "@id": "landTransformation20YearAverageInputsProduction",
26
- "termType": "resourceUse",
27
- "units": "m2 / year"
28
- }
29
- wrong_indicator = {"term": {"@id": "NOT_VALID_INDICATOR_ID", "termType": "resourceUse", "units": "m2 / year"},
30
- "value": 0.5, "landCover": crop_land, "previousLandCover": forest}
31
-
32
- indicator_no_land_cover = {
33
- "term": indicator,
34
- "previousLandCover": forest,
35
- "value": 0.5}
36
-
37
- indicator_no_previous_land_cover = {
38
- "term": indicator,
39
- "landCover": crop_land,
40
- "value": 0.5}
41
-
42
- indicator_bad_area_value = {
43
- "term": indicator,
44
- "value": -10,
45
- "previousLandCover": forest,
46
- "landCover": crop_land}
47
-
48
- inputs_production_indicator_from_forest_to_no_cf = {
49
- "term": indicator,
50
- "value": 0.5,
51
- "previousLandCover": forest,
52
- "landCover": sea_land_cover}
53
-
54
- good_inputs_production_indicator_from_forest_to_cropland = {
55
- "term": indicator,
56
- "value": 0.5,
57
- "previousLandCover": forest,
58
- "landCover": crop_land}
59
-
60
- good_inputs_production_indicator_from_forest_to_forest = {
61
- "term": indicator,
62
- "value": 0.5,
63
- "previousLandCover": forest,
64
- "landCover": forest}
65
-
66
- good_during_cycle_indicator_from_forest_to_cropland = {
67
- "term": indicator | {'@id': 'landTransformation20YearAverageDuringCycle'},
68
- "value": 0.5,
69
- "previousLandCover": forest,
70
- "landCover": crop_land}
71
-
72
- good_during_cycle_indicator_from_forest_to_forest = {
73
- "term": indicator | {'@id': 'landTransformation20YearAverageDuringCycle'},
74
- "value": 0.5,
75
- "previousLandCover": forest,
76
- "landCover": forest}
77
-
78
-
79
- @mark.parametrize(
80
- "resources, expected, num_inputs",
81
- [
82
- ([], False, 0),
83
- ([wrong_indicator], False, 0),
84
- ([indicator_no_land_cover], False, 0),
85
- ([indicator_no_previous_land_cover], False, 0),
86
- ([indicator_bad_area_value], False, 0),
87
- ([good_during_cycle_indicator_from_forest_to_cropland], True, 1),
88
- ([good_during_cycle_indicator_from_forest_to_forest], True, 1),
89
- ([good_inputs_production_indicator_from_forest_to_cropland], True, 1),
90
- ([good_inputs_production_indicator_from_forest_to_forest], True, 1),
91
- ([inputs_production_indicator_from_forest_to_no_cf], True, 0), # todo check
92
- ([good_inputs_production_indicator_from_forest_to_cropland,
93
- good_during_cycle_indicator_from_forest_to_cropland], True, 2)
94
- ],
95
- ids=["No emissionsResourceUse => no run, 0 dict",
96
- "Wrong indicator termid => no run, 0 dict",
97
- "Indicator no landcover terms => no run",
98
- "Indicator no previousLandCover terms => no run",
99
- "Bad m2 / year value => no run",
100
- "One good during cycle transformation => run, 1 dict",
101
- "One 0 during cycle transformation => run, 1 dict",
102
- "One good inputs production transformation => run, 1 dict",
103
- "One 0 inputs production transformation => run, 1 dict",
104
- "One good from transformation and One with no CF (ocean) => run, 2 dict", # todo
105
- "Multiple good indicators => run, 2 dict",
106
- ]
107
- )
108
- def test_should_run(resources: list, expected: bool, num_inputs: int):
109
- with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
110
- impact = json.load(f)
111
-
112
- impact['emissionsResourceUse'] = resources
113
-
114
- should_run, resources_with_cf = _should_run(impact)
115
- assert should_run is expected
116
- assert len(resources_with_cf) == num_inputs
117
-
118
-
119
- @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
120
- def test_run(*args):
121
- with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
122
- impact = json.load(f)
123
-
124
- with open(f"{fixtures_folder}/multipleTransformations/result.jsonld", encoding='utf-8') as f:
125
- expected = json.load(f)
126
-
127
- value = run(impact)
128
- assert value == expected
129
-
130
-
131
- @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
132
- def test_run_italy(*args):
133
- with open(f"{fixtures_folder}/Italy/impact-assessment.jsonld", encoding='utf-8') as f:
134
- impact = json.load(f)
135
-
136
- with open(f"{fixtures_folder}/Italy/result.jsonld", encoding='utf-8') as f:
137
- expected = json.load(f)
138
-
139
- value = run(impact)
140
- assert value == expected
141
-
142
-
143
- @mark.parametrize(
144
- "added_data",
145
- [
146
- {"country": {}},
147
- {"country": {"@id": "region-europe", "@type": "Term", "name": "Europe"}},
148
- ],
149
- ids=["No country/region => default to region world",
150
- "region-europe not in the lookup file => default to region world"]
151
- )
152
- @patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
153
- def test_run_with_country_fallback(mocked_indicator: Mock, added_data: dict):
154
- """
155
- When given valid sub-region or country not in the lookup file, default to country 'region-world' with value 574.56
156
- """
157
-
158
- with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
159
- impact = json.load(f)
160
-
161
- impact = impact | added_data
162
-
163
- value = run(impact)
164
- assert value['value'] == 574.56