hestia-earth-models 0.64.8__py3-none-any.whl → 0.64.10__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 (105) hide show
  1. hestia_earth/models/cml2001Baseline/abioticResourceDepletionFossilFuels.py +175 -0
  2. hestia_earth/models/cml2001Baseline/abioticResourceDepletionMineralsAndMetals.py +136 -0
  3. hestia_earth/models/cycle/siteArea.py +2 -1
  4. hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandOccupation.py +73 -82
  5. hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandTransformation.py +102 -116
  6. hestia_earth/models/environmentalFootprintV3/soilQualityIndexTotalLandUseEffects.py +27 -16
  7. hestia_earth/models/faostat2018/landTransformationFromCropland100YearAverage.py +3 -2
  8. hestia_earth/models/faostat2018/landTransformationFromCropland20YearAverage.py +3 -2
  9. hestia_earth/models/frischknechtEtAl2000/ionisingRadiationKbqU235Eq.py +69 -37
  10. hestia_earth/models/ipcc2019/aboveGroundBiomass.py +31 -243
  11. hestia_earth/models/ipcc2019/animal/fatContent.py +38 -0
  12. hestia_earth/models/ipcc2019/animal/liveweightGain.py +3 -54
  13. hestia_earth/models/ipcc2019/animal/liveweightPerHead.py +3 -54
  14. hestia_earth/models/ipcc2019/animal/pregnancyRateTotal.py +38 -0
  15. hestia_earth/models/ipcc2019/animal/trueProteinContent.py +38 -0
  16. hestia_earth/models/ipcc2019/animal/utils.py +87 -3
  17. hestia_earth/models/ipcc2019/animal/weightAtMaturity.py +4 -10
  18. hestia_earth/models/ipcc2019/belowGroundBiomass.py +529 -0
  19. hestia_earth/models/ipcc2019/biomass_utils.py +406 -0
  20. hestia_earth/models/ipcc2019/{co2ToAirAboveGroundBiomassStockChangeLandUseChange.py → co2ToAirAboveGroundBiomassStockChange.py} +19 -7
  21. hestia_earth/models/ipcc2019/{co2ToAirBelowGroundBiomassStockChangeLandUseChange.py → co2ToAirBelowGroundBiomassStockChange.py} +19 -7
  22. hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +402 -73
  23. hestia_earth/models/ipcc2019/{co2ToAirSoilOrganicCarbonStockChangeManagementChange.py → co2ToAirSoilOrganicCarbonStockChange.py} +20 -8
  24. hestia_earth/models/ipcc2019/organicCarbonPerHa.py +3 -1
  25. hestia_earth/models/ipcc2019/pastureGrass_utils.py +6 -7
  26. hestia_earth/models/lcImpactAllEffects100Years/damageToFreshwaterEcosystemsFreshwaterEutrophication.py +2 -2
  27. hestia_earth/models/lcImpactAllEffects100Years/damageToFreshwaterEcosystemsWaterStress.py +2 -2
  28. hestia_earth/models/lcImpactAllEffects100Years/damageToHumanHealthParticulateMatterFormation.py +2 -2
  29. hestia_earth/models/lcImpactAllEffects100Years/damageToHumanHealthPhotochemicalOzoneFormation.py +2 -2
  30. hestia_earth/models/lcImpactAllEffects100Years/damageToHumanHealthWaterStress.py +2 -2
  31. hestia_earth/models/lcImpactAllEffects100Years/damageToMarineEcosystemsMarineEutrophication.py +2 -2
  32. hestia_earth/models/lcImpactAllEffects100Years/damageToTerrestrialEcosystemsPhotochemicalOzoneFormation.py +2 -2
  33. hestia_earth/models/lcImpactAllEffects100Years/damageToTerrestrialEcosystemsTerrestrialAcidification.py +2 -2
  34. hestia_earth/models/lcImpactAllEffectsInfinite/damageToFreshwaterEcosystemsFreshwaterEutrophication.py +2 -2
  35. hestia_earth/models/lcImpactAllEffectsInfinite/damageToFreshwaterEcosystemsWaterStress.py +2 -2
  36. hestia_earth/models/lcImpactAllEffectsInfinite/damageToHumanHealthParticulateMatterFormation.py +2 -2
  37. hestia_earth/models/lcImpactAllEffectsInfinite/damageToHumanHealthPhotochemicalOzoneFormation.py +2 -2
  38. hestia_earth/models/lcImpactAllEffectsInfinite/damageToHumanHealthWaterStress.py +2 -2
  39. hestia_earth/models/lcImpactAllEffectsInfinite/damageToMarineEcosystemsMarineEutrophication.py +2 -2
  40. hestia_earth/models/lcImpactAllEffectsInfinite/damageToTerrestrialEcosystemsPhotochemicalOzoneFormation.py +2 -2
  41. hestia_earth/models/lcImpactAllEffectsInfinite/damageToTerrestrialEcosystemsTerrestrialAcidification.py +2 -2
  42. hestia_earth/models/lcImpactCertainEffects100Years/damageToFreshwaterEcosystemsFreshwaterEutrophication.py +2 -2
  43. hestia_earth/models/lcImpactCertainEffects100Years/damageToFreshwaterEcosystemsWaterStress.py +2 -2
  44. hestia_earth/models/lcImpactCertainEffects100Years/damageToHumanHealthParticulateMatterFormation.py +2 -2
  45. hestia_earth/models/lcImpactCertainEffects100Years/damageToHumanHealthPhotochemicalOzoneFormation.py +2 -2
  46. hestia_earth/models/lcImpactCertainEffects100Years/damageToHumanHealthWaterStress.py +2 -2
  47. hestia_earth/models/lcImpactCertainEffects100Years/damageToMarineEcosystemsMarineEutrophication.py +2 -2
  48. hestia_earth/models/lcImpactCertainEffects100Years/damageToTerrestrialEcosystemsPhotochemicalOzoneFormation.py +2 -2
  49. hestia_earth/models/lcImpactCertainEffects100Years/damageToTerrestrialEcosystemsTerrestrialAcidification.py +2 -2
  50. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToFreshwaterEcosystemsFreshwaterEutrophication.py +2 -2
  51. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToFreshwaterEcosystemsWaterStress.py +2 -2
  52. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToHumanHealthParticulateMatterFormation.py +2 -2
  53. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToHumanHealthPhotochemicalOzoneFormation.py +2 -2
  54. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToHumanHealthWaterStress.py +2 -2
  55. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToMarineEcosystemsMarineEutrophication.py +2 -2
  56. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToTerrestrialEcosystemsPhotochemicalOzoneFormation.py +2 -2
  57. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToTerrestrialEcosystemsTerrestrialAcidification.py +2 -2
  58. hestia_earth/models/mocking/build_mock_search.py +44 -0
  59. hestia_earth/models/mocking/mock_search.py +8 -49
  60. hestia_earth/models/mocking/search-results.json +3078 -575
  61. hestia_earth/models/poschEtAl2008/terrestrialAcidificationPotentialAccumulatedExceedance.py +6 -3
  62. hestia_earth/models/poschEtAl2008/terrestrialEutrophicationPotentialAccumulatedExceedance.py +6 -3
  63. hestia_earth/models/preload_requests.py +1 -1
  64. hestia_earth/models/schmidt2007/utils.py +13 -4
  65. hestia_earth/models/utils/__init__.py +5 -4
  66. hestia_earth/models/utils/blank_node.py +73 -3
  67. hestia_earth/models/utils/constant.py +8 -1
  68. hestia_earth/models/utils/cycle.py +10 -13
  69. hestia_earth/models/utils/fuel.py +1 -1
  70. hestia_earth/models/utils/impact_assessment.py +39 -15
  71. hestia_earth/models/utils/lookup.py +36 -7
  72. hestia_earth/models/utils/pesticideAI.py +1 -1
  73. hestia_earth/models/utils/property.py +11 -4
  74. hestia_earth/models/utils/term.py +15 -8
  75. hestia_earth/models/version.py +1 -1
  76. {hestia_earth_models-0.64.8.dist-info → hestia_earth_models-0.64.10.dist-info}/METADATA +2 -2
  77. {hestia_earth_models-0.64.8.dist-info → hestia_earth_models-0.64.10.dist-info}/RECORD +103 -90
  78. {hestia_earth_models-0.64.8.dist-info → hestia_earth_models-0.64.10.dist-info}/WHEEL +1 -1
  79. tests/models/cml2001Baseline/test_abioticResourceDepletionFossilFuels.py +196 -0
  80. tests/models/cml2001Baseline/test_abioticResourceDepletionMineralsAndMetals.py +124 -0
  81. tests/models/edip2003/test_ozoneDepletionPotential.py +1 -13
  82. tests/models/environmentalFootprintV3/test_soilQualityIndexLandOccupation.py +97 -66
  83. tests/models/environmentalFootprintV3/test_soilQualityIndexLandTransformation.py +136 -74
  84. tests/models/environmentalFootprintV3/test_soilQualityIndexTotalLandUseEffects.py +15 -10
  85. tests/models/frischknechtEtAl2000/test_ionisingRadiationKbqU235Eq.py +67 -44
  86. tests/models/impact_assessment/test_emissions.py +1 -0
  87. tests/models/ipcc2019/animal/test_fatContent.py +22 -0
  88. tests/models/ipcc2019/animal/test_liveweightGain.py +4 -2
  89. tests/models/ipcc2019/animal/test_liveweightPerHead.py +4 -2
  90. tests/models/ipcc2019/animal/test_pregnancyRateTotal.py +22 -0
  91. tests/models/ipcc2019/animal/test_trueProteinContent.py +22 -0
  92. tests/models/ipcc2019/animal/test_weightAtMaturity.py +2 -1
  93. tests/models/ipcc2019/test_aboveGroundBiomass.py +27 -63
  94. tests/models/ipcc2019/test_belowGroundBiomass.py +146 -0
  95. tests/models/ipcc2019/test_biomass_utils.py +115 -0
  96. tests/models/ipcc2019/{test_co2ToAirAboveGroundBiomassStockChangeLandUseChange.py → test_co2ToAirAboveGroundBiomassStockChange.py} +5 -5
  97. tests/models/ipcc2019/{test_co2ToAirBelowGroundBiomassStockChangeLandUseChange.py → test_co2ToAirBelowGroundBiomassStockChange.py} +5 -5
  98. tests/models/ipcc2019/{test_co2ToAirSoilOrganicCarbonStockChangeManagementChange.py → test_co2ToAirSoilOrganicCarbonStockChange.py} +5 -5
  99. tests/models/ipcc2021/test_gwp100.py +2 -2
  100. tests/models/poschEtAl2008/test_terrestrialAcidificationPotentialAccumulatedExceedance.py +30 -17
  101. tests/models/poschEtAl2008/test_terrestrialEutrophicationPotentialAccumulatedExceedance.py +28 -14
  102. hestia_earth/models/ipcc2019/aboveGroundBiomass_utils.py +0 -180
  103. tests/models/ipcc2019/test_aboveGroundBiomass_utils.py +0 -92
  104. {hestia_earth_models-0.64.8.dist-info → hestia_earth_models-0.64.10.dist-info}/LICENSE +0 -0
  105. {hestia_earth_models-0.64.8.dist-info → hestia_earth_models-0.64.10.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,159 @@ 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}.get_land_cover_terms", return_value=['cropland', 'seaOrOcean', 'forest'])
104
+ def test_should_run(mock_download, resources, expected, num_inputs):
105
+ with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
106
+ impact = json.load(f)
107
+
108
+ impact['emissionsResourceUse'] = resources
109
+
110
+ should_run, resources_with_cf = _should_run(impact)
111
+ assert should_run is expected
112
+ assert len(resources_with_cf) == num_inputs
113
+
114
+
115
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
116
+ def test_run(*args):
117
+ with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
118
+ impact = json.load(f)
119
+
120
+ with open(f"{fixtures_folder}/multipleTransformations/result.jsonld", encoding='utf-8') as f:
68
121
  expected = json.load(f)
69
122
 
70
- value = run(site)
123
+ value = run(impact)
71
124
  assert value == expected
72
125
 
73
126
 
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)
127
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
128
+ def test_run_italy(*args):
129
+ with open(f"{fixtures_folder}/Italy/impact-assessment.jsonld", encoding='utf-8') as f:
130
+ impact = json.load(f)
78
131
 
79
- with open(f"{fixtures_folder}/Italy/result-otherSites.jsonld", encoding='utf-8') as f:
132
+ with open(f"{fixtures_folder}/Italy/result.jsonld", encoding='utf-8') as f:
80
133
  expected = json.load(f)
81
134
 
82
- value = run(site)
135
+ value = run(impact)
83
136
  assert value == expected
84
137
 
85
138
 
139
+ @mark.parametrize(
140
+ "added_data",
141
+ [
142
+ {"country": {}},
143
+ {"country": {"@id": "region-europe", "@type": "Term", "name": "Europe"}},
144
+ ],
145
+ ids=["No country/region => default to region world",
146
+ "region-europe not in the lookup file => default to region world"]
147
+ )
86
148
  @patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
87
- def test_run_with_region(*args):
149
+ def test_run_with_country_fallback(mocked_indicator, added_data):
88
150
  """
89
- When given valid sub-region or country not in the lookup file should default to 'region-world'
151
+ When given valid sub-region or country not in the lookup file, default to country 'region-world' with value 574.56
90
152
  """
91
- with open(f"{fixtures_folder}/region-world/region-europe.jsonld", encoding='utf-8') as f:
92
- site = json.load(f)
93
153
 
94
- with open(f"{fixtures_folder}/region-world/result-default-region-world.jsonld", encoding='utf-8') as f:
95
- expected = json.load(f)
154
+ with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
155
+ impact = json.load(f)
96
156
 
97
- value = run(site)
98
- assert value == expected
157
+ impact = impact | added_data
99
158
 
159
+ value = run(impact)
160
+ assert value['value'] == 574.56
100
161
 
101
- @patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
102
- def test_run_with_no_region(*args):
162
+
163
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
164
+ def test_run_no_transformation(*args):
103
165
  """
104
- When no location is specified, defaults to region world.
166
+ Impact assessment with no transformations should return a indicator of 0
105
167
  """
106
- with open(f"{fixtures_folder}/region-world/no-region.jsonld", encoding='utf-8') as f:
107
- site = json.load(f)
168
+ with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
169
+ impact = json.load(f)
108
170
 
109
- with open(f"{fixtures_folder}/region-world/result-default-region-world.jsonld", encoding='utf-8') as f:
110
- expected = json.load(f)
171
+ impact['emissionsResourceUse'] = []
111
172
 
112
- value = run(site)
113
- assert value == expected
173
+ value = run(impact)
174
+
175
+ 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)
@@ -28,4 +28,5 @@ def test_run(*args):
28
28
  expected = json.load(f)
29
29
 
30
30
  value = run(impact)
31
+ print(json.dumps(value))
31
32
  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.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}"