hestia-earth-models 0.67.1__py3-none-any.whl → 0.68.0__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 (147) hide show
  1. hestia_earth/models/aware/scarcityWeightedWaterUse.py +5 -6
  2. hestia_earth/models/blonkConsultants2016/ch4ToAirNaturalVegetationBurning.py +1 -1
  3. hestia_earth/models/blonkConsultants2016/co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +1 -1
  4. hestia_earth/models/blonkConsultants2016/n2OToAirNaturalVegetationBurningDirect.py +1 -1
  5. hestia_earth/models/blonkConsultants2016/utils.py +9 -9
  6. hestia_earth/models/cache_sites.py +26 -14
  7. hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsLandOccupation.py +2 -2
  8. hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsLandTransformation.py +2 -2
  9. hestia_earth/models/chaudharyBrooks2018/utils.py +13 -8
  10. hestia_earth/models/cml2001Baseline/abioticResourceDepletionFossilFuels.py +2 -3
  11. hestia_earth/models/cml2001Baseline/abioticResourceDepletionMineralsAndMetals.py +1 -1
  12. hestia_earth/models/config/Cycle.json +15 -0
  13. hestia_earth/models/config/ImpactAssessment.json +14 -1
  14. hestia_earth/models/config/Site.json +8 -0
  15. hestia_earth/models/cycle/excretaKgMass.py +2 -2
  16. hestia_earth/models/cycle/materialAndSubstrate.py +3 -2
  17. hestia_earth/models/cycle/pastureGrass.py +3 -3
  18. hestia_earth/models/dammgen2009/noxToAirExcreta.py +1 -1
  19. hestia_earth/models/ecoinventV3AndEmberClimate/__init__.py +1 -1
  20. hestia_earth/models/ecoinventV3AndEmberClimate/utils.py +2 -6
  21. hestia_earth/models/emissionNotRelevant/__init__.py +4 -4
  22. hestia_earth/models/environmentalFootprintV3_1/environmentalFootprintSingleOverallScore.py +30 -21
  23. hestia_earth/models/environmentalFootprintV3_1/photochemicalOzoneCreationPotentialHumanHealthNmvocEq.py +36 -0
  24. hestia_earth/models/environmentalFootprintV3_1/scarcityWeightedWaterUse.py +2 -2
  25. hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandOccupation.py +9 -8
  26. hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandTransformation.py +25 -22
  27. hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexTotalLandUseEffects.py +7 -6
  28. hestia_earth/models/faostat2018/coldCarcassWeightPerHead.py +2 -2
  29. hestia_earth/models/faostat2018/coldDressedCarcassWeightPerHead.py +2 -2
  30. hestia_earth/models/faostat2018/liveweightPerHead.py +7 -8
  31. hestia_earth/models/faostat2018/product/price.py +34 -28
  32. hestia_earth/models/faostat2018/readyToCookWeightPerHead.py +2 -2
  33. hestia_earth/models/faostat2018/utils.py +15 -27
  34. hestia_earth/models/frischknechtEtAl2000/ionisingRadiationKbqU235Eq.py +16 -9
  35. hestia_earth/models/geospatialDatabase/altitude.py +60 -0
  36. hestia_earth/models/geospatialDatabase/croppingIntensity.py +1 -1
  37. hestia_earth/models/geospatialDatabase/ecoClimateZone.py +2 -2
  38. hestia_earth/models/geospatialDatabase/longFallowRatio.py +1 -1
  39. hestia_earth/models/geospatialDatabase/utils.py +4 -1
  40. hestia_earth/models/globalCropWaterModel2008/rootingDepth.py +2 -3
  41. hestia_earth/models/haversineFormula/transport/distance.py +3 -3
  42. hestia_earth/models/hestia/landCover.py +72 -45
  43. hestia_earth/models/hestia/seed_emissions.py +11 -7
  44. hestia_earth/models/impact_assessment/__init__.py +3 -3
  45. hestia_earth/models/ipcc2019/animal/fatContent.py +1 -1
  46. hestia_earth/models/ipcc2019/animal/hoursWorkedPerDay.py +1 -1
  47. hestia_earth/models/ipcc2019/animal/liveweightGain.py +1 -1
  48. hestia_earth/models/ipcc2019/animal/liveweightPerHead.py +1 -1
  49. hestia_earth/models/ipcc2019/animal/milkYieldPerAnimal.py +1 -1
  50. hestia_earth/models/ipcc2019/animal/pastureGrass.py +1 -1
  51. hestia_earth/models/ipcc2019/animal/pregnancyRateTotal.py +1 -1
  52. hestia_earth/models/ipcc2019/animal/trueProteinContent.py +1 -1
  53. hestia_earth/models/ipcc2019/animal/utils.py +5 -7
  54. hestia_earth/models/ipcc2019/animal/weightAtMaturity.py +1 -1
  55. hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py +2 -2
  56. hestia_earth/models/ipcc2019/ch4ToAirExcreta.py +6 -7
  57. hestia_earth/models/ipcc2019/ch4ToAirFloodedRice.py +5 -3
  58. hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +1 -1
  59. hestia_earth/models/ipcc2019/croppingDuration.py +3 -6
  60. hestia_earth/models/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning.py +947 -0
  61. hestia_earth/models/ipcc2019/pastureGrass.py +1 -1
  62. hestia_earth/models/koble2014/residueBurnt.py +5 -7
  63. hestia_earth/models/koble2014/residueRemoved.py +5 -7
  64. hestia_earth/models/lcImpactAllEffects100Years/damageToHumanHealthWaterStress.py +2 -2
  65. hestia_earth/models/lcImpactAllEffectsInfinite/damageToHumanHealthWaterStress.py +2 -2
  66. hestia_earth/models/lcImpactCertainEffects100Years/damageToHumanHealthWaterStress.py +2 -2
  67. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToHumanHealthWaterStress.py +2 -2
  68. hestia_earth/models/log.py +1 -1
  69. hestia_earth/models/mocking/search-results.json +3413 -1113
  70. hestia_earth/models/site/management.py +1 -1
  71. hestia_earth/models/site/post_checks/__init__.py +3 -2
  72. hestia_earth/models/site/post_checks/country.py +9 -0
  73. hestia_earth/models/site/pre_checks/__init__.py +3 -2
  74. hestia_earth/models/site/pre_checks/country.py +9 -0
  75. hestia_earth/models/utils/__init__.py +1 -16
  76. hestia_earth/models/utils/blank_node.py +25 -25
  77. hestia_earth/models/utils/completeness.py +3 -2
  78. hestia_earth/models/utils/cycle.py +5 -4
  79. hestia_earth/models/utils/emission.py +5 -5
  80. hestia_earth/models/utils/feedipedia.py +6 -6
  81. hestia_earth/models/utils/impact_assessment.py +1 -2
  82. hestia_earth/models/utils/indicator.py +9 -7
  83. hestia_earth/models/utils/inorganicFertiliser.py +4 -6
  84. hestia_earth/models/utils/input.py +6 -5
  85. hestia_earth/models/utils/lookup.py +32 -100
  86. hestia_earth/models/utils/management.py +4 -4
  87. hestia_earth/models/utils/measurement.py +6 -7
  88. hestia_earth/models/utils/method.py +20 -0
  89. hestia_earth/models/utils/practice.py +4 -5
  90. hestia_earth/models/utils/product.py +4 -5
  91. hestia_earth/models/utils/property.py +12 -22
  92. hestia_earth/models/utils/site.py +14 -8
  93. hestia_earth/models/utils/term.py +27 -1
  94. hestia_earth/models/version.py +1 -1
  95. hestia_earth/orchestrator/log.py +0 -11
  96. hestia_earth/orchestrator/models/__init__.py +17 -4
  97. hestia_earth/orchestrator/strategies/run/add_blank_node_if_missing.py +2 -20
  98. {hestia_earth_models-0.67.1.dist-info → hestia_earth_models-0.68.0.dist-info}/METADATA +2 -2
  99. {hestia_earth_models-0.67.1.dist-info → hestia_earth_models-0.68.0.dist-info}/RECORD +145 -137
  100. tests/models/cml2001Baseline/test_abioticResourceDepletionFossilFuels.py +3 -3
  101. tests/models/cml2001Baseline/test_resourceUseEnergyDepletionDuringCycle.py +1 -1
  102. tests/models/cycle/test_coldCarcassWeightPerHead.py +1 -1
  103. tests/models/cycle/test_coldDressedCarcassWeightPerHead.py +1 -1
  104. tests/models/cycle/test_concentrateFeed.py +1 -1
  105. tests/models/cycle/test_energyContentLowerHeatingValue.py +1 -1
  106. tests/models/cycle/test_excretaKgMass.py +1 -1
  107. tests/models/cycle/test_feedConversionRatio.py +3 -3
  108. tests/models/cycle/test_pastureGrass.py +1 -1
  109. tests/models/cycle/test_readyToCookWeightPerHead.py +1 -1
  110. tests/models/environmentalFootprintV3_1/test_photochemicalOzoneCreationPotentialHumanHealthNmvocEq.py +30 -0
  111. tests/models/environmentalFootprintV3_1/test_soilQualityIndexTotalLandUseEffects.py +30 -7
  112. tests/models/faostat2018/product/test_price.py +27 -14
  113. tests/models/faostat2018/test_faostat_utils.py +4 -24
  114. tests/models/faostat2018/test_liveweightPerHead.py +9 -9
  115. tests/models/globalCropWaterModel2008/test_rootingDepth.py +7 -3
  116. tests/models/haversineFormula/transport/test_distance.py +1 -1
  117. tests/models/hestia/test_landCover.py +53 -5
  118. tests/models/ipcc2019/animal/test_pastureGrass.py +5 -3
  119. tests/models/ipcc2019/test_aboveGroundCropResidueTotal.py +4 -4
  120. tests/models/ipcc2019/test_belowGroundCropResidue.py +4 -4
  121. tests/models/ipcc2019/test_ch4ToAirEntericFermentation.py +10 -10
  122. tests/models/ipcc2019/test_croppingDuration.py +1 -1
  123. tests/models/ipcc2019/test_nonCo2EmissionsToAirNaturalVegetationBurning.py +83 -0
  124. tests/models/ipcc2019/test_organicCarbonPerHa.py +12 -12
  125. tests/models/ipcc2019/test_pastureGrass.py +5 -3
  126. tests/models/pooreNemecek2018/test_excretaKgN.py +5 -5
  127. tests/models/pooreNemecek2018/test_excretaKgVs.py +2 -2
  128. tests/models/site/post_checks/test_country.py +6 -0
  129. tests/models/site/pre_checks/test_cache_geospatialDatabase.py +1 -1
  130. tests/models/site/pre_checks/test_country.py +12 -0
  131. tests/models/test_ecoinventV3.py +7 -3
  132. tests/models/utils/test_blank_node.py +4 -12
  133. tests/models/utils/test_dataCompleteness.py +5 -5
  134. tests/models/utils/test_emission.py +2 -2
  135. tests/models/utils/test_indicator.py +2 -2
  136. tests/models/utils/test_input.py +2 -2
  137. tests/models/utils/test_measurement.py +2 -4
  138. tests/models/utils/test_practice.py +4 -2
  139. tests/models/utils/test_product.py +2 -2
  140. tests/models/utils/test_property.py +4 -2
  141. tests/models/utils/test_site.py +7 -0
  142. tests/orchestrator/strategies/run/test_add_blank_node_if_missing.py +4 -9
  143. hestia_earth/models/environmentalFootprintV3_1/utils.py +0 -17
  144. tests/models/utils/test_lookup.py +0 -10
  145. {hestia_earth_models-0.67.1.dist-info → hestia_earth_models-0.68.0.dist-info}/LICENSE +0 -0
  146. {hestia_earth_models-0.67.1.dist-info → hestia_earth_models-0.68.0.dist-info}/WHEEL +0 -0
  147. {hestia_earth_models-0.67.1.dist-info → hestia_earth_models-0.68.0.dist-info}/top_level.txt +0 -0
@@ -16,7 +16,7 @@ CROP_RESIDUE_TERM = {
16
16
  }
17
17
 
18
18
 
19
- @patch('hestia_earth.models.utils.completeness.download_hestia', return_value=CROP_RESIDUE_TERM)
19
+ @patch('hestia_earth.models.utils.completeness.download_term', return_value=CROP_RESIDUE_TERM)
20
20
  @patch(f"{class_path}._should_run_product", return_value=True)
21
21
  def test_should_run(*args):
22
22
  crop_product = {'term': {'termType': TermTermType.CROP.value}}
@@ -33,7 +33,7 @@ def test_should_run(*args):
33
33
  assert should_run is True
34
34
 
35
35
 
36
- @patch('hestia_earth.models.utils.completeness.download_hestia', return_value=CROP_RESIDUE_TERM)
36
+ @patch('hestia_earth.models.utils.completeness.download_term', return_value=CROP_RESIDUE_TERM)
37
37
  @patch(f"{class_path}.get_yield_dm", return_value=None)
38
38
  def test_should_run_product(mock_get_yield_dm, *args):
39
39
  product = {'term': {'@id': 'maizeGrain'}}
@@ -51,7 +51,7 @@ def test_should_run_product(mock_get_yield_dm, *args):
51
51
  assert _should_run_product(product) is True
52
52
 
53
53
 
54
- @patch('hestia_earth.models.utils.completeness.download_hestia', return_value=CROP_RESIDUE_TERM)
54
+ @patch('hestia_earth.models.utils.completeness.download_term', return_value=CROP_RESIDUE_TERM)
55
55
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
56
56
  def test_run_crop(*args):
57
57
  with open(f"{fixtures_folder}/crop/cycle.jsonld", encoding='utf-8') as f:
@@ -64,7 +64,7 @@ def test_run_crop(*args):
64
64
  assert value == expected
65
65
 
66
66
 
67
- @patch('hestia_earth.models.utils.completeness.download_hestia', return_value=CROP_RESIDUE_TERM)
67
+ @patch('hestia_earth.models.utils.completeness.download_term', return_value=CROP_RESIDUE_TERM)
68
68
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
69
69
  def test_run_forage(*args):
70
70
  with open(f"{fixtures_folder}/forage/cycle.jsonld", encoding='utf-8') as f:
@@ -15,7 +15,7 @@ TERMS_BY_ID = {
15
15
  }
16
16
 
17
17
 
18
- def fake_download_hestia(term_id: str, *args): return TERMS_BY_ID[term_id]
18
+ def fake_download_term(term_id: str, *args): return TERMS_BY_ID[term_id]
19
19
 
20
20
 
21
21
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
@@ -53,7 +53,7 @@ def test_should_run(mock_feed, mock_lookup_value, *args):
53
53
 
54
54
 
55
55
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
56
- @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
56
+ @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
57
57
  # patch get_node_property to read value from lookups only
58
58
  @patch('hestia_earth.models.utils.property.get_node_property', return_value=None)
59
59
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
@@ -69,7 +69,7 @@ def test_run(*args):
69
69
 
70
70
 
71
71
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
72
- @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
72
+ @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
73
73
  # patch get_node_property to read value from lookups only
74
74
  @patch('hestia_earth.models.utils.property.get_node_property', return_value=None)
75
75
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
@@ -85,7 +85,7 @@ def test_run_dairy(*args):
85
85
 
86
86
 
87
87
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=['milkYieldPerBuffaloRaw'])
88
- @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
88
+ @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
89
89
  # patch get_node_property to read value from lookups only
90
90
  @patch('hestia_earth.models.utils.property.get_node_property', return_value={})
91
91
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
@@ -101,7 +101,7 @@ def test_run_with_milkYield(*args):
101
101
 
102
102
 
103
103
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
104
- @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
104
+ @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
105
105
  # patch get_node_property to read value from lookups only
106
106
  @patch('hestia_earth.models.utils.property.get_node_property', return_value={})
107
107
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
@@ -117,7 +117,7 @@ def test_run_non_dairy(*args):
117
117
 
118
118
 
119
119
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
120
- @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
120
+ @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
121
121
  # patch get_node_property to read value from lookups only
122
122
  @patch('hestia_earth.models.utils.property.get_node_property', return_value={})
123
123
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
@@ -133,7 +133,7 @@ def test_run_with_ionophores(*args):
133
133
 
134
134
 
135
135
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
136
- @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
136
+ @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
137
137
  # patch get_node_property to read value from lookups only
138
138
  @patch('hestia_earth.models.utils.property.get_node_property', return_value={})
139
139
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
@@ -149,7 +149,7 @@ def test_run_without_ionophores(*args):
149
149
 
150
150
 
151
151
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
152
- @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
152
+ @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
153
153
  # patch get_node_property to read value from lookups only
154
154
  @patch('hestia_earth.models.utils.property.get_node_property', return_value={})
155
155
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
@@ -162,7 +162,7 @@ def test_run_no_feed(*args):
162
162
 
163
163
 
164
164
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
165
- @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
165
+ @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
166
166
  # patch get_node_property to read value from lookups only
167
167
  @patch('hestia_earth.models.utils.property.get_node_property', return_value={})
168
168
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
@@ -178,7 +178,7 @@ def test_run_with_system(*args):
178
178
 
179
179
 
180
180
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
181
- @patch("hestia_earth.models.utils.property.download_hestia", return_value={})
181
+ @patch("hestia_earth.models.utils.property.download_term", return_value={})
182
182
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
183
183
  def test_run_default(*args):
184
184
  with open(f"{fixtures_folder}/default-value/cycle.jsonld", encoding="utf-8") as f:
@@ -8,7 +8,7 @@ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
9
 
10
10
 
11
- @patch(f"{class_path}.get_table_value", return_value='0')
11
+ @patch(f"{class_path}.get_region_lookup_value", return_value='0')
12
12
  @patch(f"{class_path}.has_flooded_rice", return_value=False)
13
13
  def test_should_run(mock_flooded_rice, *args):
14
14
  # no cycleDuration => no run
@@ -0,0 +1,83 @@
1
+ from functools import reduce
2
+ import json
3
+ from pytest import mark
4
+ from os.path import isfile
5
+ from unittest.mock import MagicMock, patch
6
+
7
+ from tests.utils import fake_new_emission, fixtures_path, order_list
8
+
9
+ from hestia_earth.models.ipcc2019.nonCo2EmissionsToAirNaturalVegetationBurning import run, _should_run
10
+
11
+ class_path = 'hestia_earth.models.ipcc2019.nonCo2EmissionsToAirNaturalVegetationBurning'
12
+ fixtures_folder = f"{fixtures_path}/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning"
13
+
14
+
15
+ def _load_fixture(path: str, default=None):
16
+ if isfile(path):
17
+ with open(path, encoding="utf-8") as f:
18
+ return json.load(f)
19
+ return default
20
+
21
+
22
+ RUN_SCENARIOS = [
23
+ ("forest-to-cropland", 4),
24
+ ("historical-land-cover-mix", 3),
25
+ ("deforestation-reforestation", 1), # gains should not offset losses
26
+ ("no-clearance-via-fire", 1), # LUC in the UK, which has a percentage burned factor of 0
27
+ ("forest-to-cropland-with-ground-cover", 4) # Cover crops/ground covers should be ignored
28
+ ]
29
+
30
+
31
+ RUN_PARAMS = reduce(
32
+ lambda params, scenario: params + [(scenario[0], scenario[1], i) for i in range(scenario[1])],
33
+ RUN_SCENARIOS,
34
+ list()
35
+ )
36
+ """List of (subfolder: str, num_cycles: int, cycle_index: int)."""
37
+
38
+ RUN_IDS = [f"{param[0]}, cycle{param[2]}" for param in RUN_PARAMS]
39
+
40
+
41
+ @mark.parametrize("subfolder, num_cycles, cycle_index", RUN_PARAMS, ids=RUN_IDS)
42
+ @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
43
+ @patch(f"{class_path}.related_cycles")
44
+ @patch(f"{class_path}._get_site")
45
+ def test_run(
46
+ get_site_mock: MagicMock,
47
+ related_cycles_mock: MagicMock,
48
+ _new_emission_mock: MagicMock,
49
+ subfolder: str,
50
+ num_cycles: int,
51
+ cycle_index: int
52
+ ):
53
+ """
54
+ Test `run` function for each cycle in each scenario.
55
+ """
56
+ site = _load_fixture(f"{fixtures_folder}/{subfolder}/site.jsonld")
57
+ cycle = _load_fixture(f"{fixtures_folder}/{subfolder}/cycle{cycle_index}.jsonld")
58
+ expected = _load_fixture(f"{fixtures_folder}/{subfolder}/result{cycle_index}.jsonld", default=[])
59
+
60
+ cycles = [_load_fixture(f"{fixtures_folder}/{subfolder}/cycle{i}.jsonld") for i in range(num_cycles)]
61
+
62
+ get_site_mock.return_value = site
63
+ related_cycles_mock.return_value = cycles
64
+
65
+ result = run(cycle)
66
+ assert order_list(result) == order_list(expected)
67
+
68
+
69
+ def test_should_run_no_data():
70
+ CYCLE = {}
71
+ EXPECTED = False
72
+
73
+ result, *_ = _should_run(CYCLE)
74
+ assert result == EXPECTED
75
+
76
+
77
+ @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
78
+ def test_run_no_data(*_):
79
+ CYCLE = {}
80
+ EXPECTED = []
81
+
82
+ result = run(CYCLE)
83
+ assert result == EXPECTED
@@ -231,9 +231,9 @@ IDS_SHOULD_RUN = [p[0] for p in PARAMS_SHOULD_RUN]
231
231
  @patch(f"{utils_path}.get_cover_crop_property_terms", return_value=COVER_CROP_PROPERTY_TERM_IDS)
232
232
  @patch(f"{term_path}.search")
233
233
  @patch(f"{property_path}.find_term_property", side_effect=fake_find_term_property)
234
- @patch(f"{property_path}.download_hestia")
234
+ @patch(f"{property_path}.download_term")
235
235
  def test_should_run(
236
- download_hestia_mock: MagicMock,
236
+ download_term_mock: MagicMock,
237
237
  _find_term_property_mock: MagicMock,
238
238
  search_mock: MagicMock,
239
239
  _get_cover_crop_property_terms_mock: MagicMock,
@@ -263,15 +263,15 @@ def test_should_run(
263
263
  assert result == should_run
264
264
 
265
265
  # Ensure that the property and term utils are properly mocked.
266
- download_hestia_mock.assert_not_called()
266
+ download_term_mock.assert_not_called()
267
267
  search_mock.assert_not_called()
268
268
 
269
269
 
270
270
  @patch(f"{tier_2_utils_path}.related_cycles", return_value=[])
271
271
  @patch(f"{term_path}.search")
272
- @patch(f"{property_path}.download_hestia")
272
+ @patch(f"{property_path}.download_term")
273
273
  def test_should_run_no_data(
274
- download_hestia_mock: MagicMock,
274
+ download_term_mock: MagicMock,
275
275
  search_mock: MagicMock,
276
276
  _related_cycles_mock: MagicMock
277
277
  ):
@@ -280,7 +280,7 @@ def test_should_run_no_data(
280
280
 
281
281
  result = run(SITE)
282
282
 
283
- download_hestia_mock.assert_not_called()
283
+ download_term_mock.assert_not_called()
284
284
  search_mock.assert_not_called()
285
285
  assert result == EXPECTED
286
286
 
@@ -304,9 +304,9 @@ PARAMS_RUN = [subfolder for subfolder, should_run in PARAMS_SHOULD_RUN if should
304
304
  @patch(f"{utils_path}.get_cover_crop_property_terms", return_value=COVER_CROP_PROPERTY_TERM_IDS)
305
305
  @patch(f"{term_path}.search")
306
306
  @patch(f"{property_path}.find_term_property", side_effect=fake_find_term_property)
307
- @patch(f"{property_path}.download_hestia")
307
+ @patch(f"{property_path}.download_term")
308
308
  def test_run(
309
- download_hestia_mock: MagicMock,
309
+ download_term_mock: MagicMock,
310
310
  _find_term_property_mock: MagicMock,
311
311
  search_mock: MagicMock,
312
312
  _get_cover_crop_property_terms_mock: MagicMock,
@@ -346,7 +346,7 @@ def test_run(
346
346
  assert order_list(result) == order_list(expected)
347
347
 
348
348
  # Ensure that the property and term utils are properly mocked.
349
- download_hestia_mock.assert_not_called()
349
+ download_term_mock.assert_not_called()
350
350
  search_mock.assert_not_called()
351
351
 
352
352
 
@@ -371,9 +371,9 @@ PARAMS_RUN_WITH_STATS = [
371
371
  @patch(f"{utils_path}.get_cover_crop_property_terms", return_value=COVER_CROP_PROPERTY_TERM_IDS)
372
372
  @patch(f"{term_path}.search")
373
373
  @patch(f"{property_path}.find_term_property", side_effect=fake_find_term_property)
374
- @patch(f"{property_path}.download_hestia")
374
+ @patch(f"{property_path}.download_term")
375
375
  def test_run_with_stats(
376
- download_hestia_mock: MagicMock,
376
+ download_term_mock: MagicMock,
377
377
  _find_term_property_mock: MagicMock,
378
378
  search_mock: MagicMock,
379
379
  _get_cover_crop_property_terms_mock: MagicMock,
@@ -409,5 +409,5 @@ def test_run_with_stats(
409
409
  assert order_list(result) == order_list(expected)
410
410
 
411
411
  # Ensure that the property and term utils are properly mocked.
412
- download_hestia_mock.assert_not_called()
412
+ download_term_mock.assert_not_called()
413
413
  search_mock.assert_not_called()
@@ -31,11 +31,13 @@ TERMS_BY_ID = {
31
31
  }
32
32
 
33
33
 
34
- def fake_download_hestia(term_id: str, *args): return TERMS_BY_ID.get(term_id, {})
34
+ def fake_download_hestia(term, *args):
35
+ term_id = term.get('@id') if isinstance(term, dict) else term
36
+ return TERMS_BY_ID.get(term_id, {})
35
37
 
36
38
 
37
39
  @patch(f"{class_path_utils}.download_hestia", side_effect=fake_download_hestia)
38
- @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
40
+ @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_hestia)
39
41
  @patch(f"{class_path}.get_wool_terms", return_value=WOOL_TERMS)
40
42
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=MILK_YIELD_TERMS)
41
43
  @patch(f"{class_path}._new_input", side_effect=fake_new_input)
@@ -51,7 +53,7 @@ def test_run(*args):
51
53
 
52
54
 
53
55
  @patch(f"{class_path_utils}.download_hestia", side_effect=fake_download_hestia)
54
- @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
56
+ @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_hestia)
55
57
  @patch(f"{class_path}.get_wool_terms", return_value=WOOL_TERMS)
56
58
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=MILK_YIELD_TERMS)
57
59
  @patch(f"{class_path}._new_input", side_effect=fake_new_input)
@@ -59,7 +59,7 @@ def test_should_run(mock_animal_produced, mock_get_feed, *args):
59
59
  assert should_run is True
60
60
 
61
61
 
62
- @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
62
+ @patch("hestia_earth.models.utils.property.download_term", return_value={'units': '%'})
63
63
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
64
64
  def test_run(*args):
65
65
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
@@ -72,7 +72,7 @@ def test_run(*args):
72
72
  assert value == expected
73
73
 
74
74
 
75
- @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
75
+ @patch("hestia_earth.models.utils.property.download_term", return_value={'units': '%'})
76
76
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
77
77
  def test_run_with_liveweight(*args):
78
78
  with open(f"{fixtures_folder}/with-liveweight/cycle.jsonld", encoding='utf-8') as f:
@@ -85,7 +85,7 @@ def test_run_with_liveweight(*args):
85
85
  assert value == expected
86
86
 
87
87
 
88
- @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
88
+ @patch("hestia_earth.models.utils.property.download_term", return_value={'units': '%'})
89
89
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
90
90
  def test_run_with_carcass(*args):
91
91
  with open(f"{fixtures_folder}/with-carcass/cycle.jsonld", encoding='utf-8') as f:
@@ -98,7 +98,7 @@ def test_run_with_carcass(*args):
98
98
  assert value == expected
99
99
 
100
100
 
101
- @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
101
+ @patch("hestia_earth.models.utils.property.download_term", return_value={'units': '%'})
102
102
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
103
103
  def test_run_with_head(*args):
104
104
  with open(f"{fixtures_folder}/with-head/cycle.jsonld", encoding='utf-8') as f:
@@ -111,7 +111,7 @@ def test_run_with_head(*args):
111
111
  assert value == expected
112
112
 
113
113
 
114
- @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
114
+ @patch("hestia_earth.models.utils.property.download_term", return_value={'units': '%'})
115
115
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
116
116
  def test_run_with_liveAquaticSpecies(*args):
117
117
  with open(f"{fixtures_folder}/with-liveAquaticSpecies/cycle.jsonld", encoding='utf-8') as f:
@@ -79,7 +79,7 @@ def test_should_run(*args):
79
79
  assert should_run is True
80
80
 
81
81
 
82
- @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
82
+ @patch("hestia_earth.models.utils.property.download_term", return_value={'units': '%'})
83
83
  @patch(f"{class_path}.get_node_property", return_value={'value': 1490.6951744738524})
84
84
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
85
85
  def test_run(*args):
@@ -93,7 +93,7 @@ def test_run(*args):
93
93
  assert value == expected
94
94
 
95
95
 
96
- @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
96
+ @patch("hestia_earth.models.utils.property.download_term", return_value={'units': '%'})
97
97
  @patch(f"{class_path}.get_node_property", return_value={'value': 1490.6951744738524})
98
98
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
99
99
  def test_run_excretaKgN(*args):
@@ -0,0 +1,6 @@
1
+ from hestia_earth.models.site.post_checks.country import run
2
+
3
+
4
+ def test_run():
5
+ site = {'country': {'@type': 'Term', '@id': 'GADM-GBR', 'defaultProperties': []}}
6
+ assert run(site) == {'country': {'@type': 'Term', '@id': 'GADM-GBR'}}
@@ -5,7 +5,7 @@ from hestia_earth.models.site.pre_checks.cache_geospatialDatabase import list_ra
5
5
 
6
6
  def test_list_rasters():
7
7
  rasters = list_rasters(years=[2010])
8
- assert len(rasters) == 72
8
+ assert len(rasters) == 73
9
9
 
10
10
 
11
11
  @pytest.mark.parametrize(
@@ -0,0 +1,12 @@
1
+ from unittest.mock import Mock, patch
2
+
3
+ from hestia_earth.models.site.pre_checks.country import run
4
+
5
+ class_path = 'hestia_earth.models.site.pre_checks.country'
6
+
7
+
8
+ @patch(f"{class_path}.download_hestia")
9
+ def test_run(mock_download_hestia: Mock):
10
+ site = {'country': {'@type': 'Term', '@id': 'GADM-GBR'}}
11
+ run(site)
12
+ mock_download_hestia.assert_called_once_with('GADM-GBR')
@@ -8,8 +8,7 @@ from hestia_earth.models.ecoinventV3 import MODEL, run
8
8
  class_path = f"hestia_earth.models.{MODEL}"
9
9
  fixtures_folder = os.path.join(fixtures_path, MODEL)
10
10
 
11
-
12
- TERM_BY_ID = {
11
+ TERMS_BY_ID = {
13
12
  '24EpibrassinolideTgai': {
14
13
  "defaultProperties": [{
15
14
  "@type": "Property",
@@ -40,7 +39,12 @@ TERM_BY_ID = {
40
39
  }
41
40
 
42
41
 
43
- @patch('hestia_earth.models.utils.blank_node.download_hestia', side_effect=lambda id, *args: TERM_BY_ID[id])
42
+ def fake_download_hestia(term, *args):
43
+ term_id = term.get('@id') if isinstance(term, dict) else term
44
+ return TERMS_BY_ID.get(term_id, {})
45
+
46
+
47
+ @patch('hestia_earth.models.utils.blank_node.download_term', side_effect=fake_download_hestia)
44
48
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
45
49
  def test_run(*args):
46
50
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
@@ -53,27 +53,19 @@ def test_condense_nodes(folder: str):
53
53
 
54
54
 
55
55
  def test_run_required():
56
- term = {
57
- '@id': 'ch4ToAirAquacultureSystems',
58
- 'termType': 'emission'
59
- }
60
- assert not _run_required('model', term, {
56
+ assert not _run_required('model', 'ch4ToAirAquacultureSystems', {
61
57
  'site': {'siteType': SiteSiteType.CROPLAND.value}
62
58
  })
63
- assert _run_required('model', term, {
59
+ assert _run_required('model', 'ch4ToAirAquacultureSystems', {
64
60
  'site': {'siteType': SiteSiteType.POND.value}
65
61
  }) is True
66
62
 
67
63
 
68
64
  def test_run_model_required():
69
- term = {
70
- '@id': 'netPrimaryProduction',
71
- 'termType': 'measurement'
72
- }
73
- assert _run_model_required('pooreNemecek2018', term, {
65
+ assert _run_model_required('pooreNemecek2018', 'netPrimaryProduction', {
74
66
  'site': {'siteType': SiteSiteType.POND.value}
75
67
  }) is True
76
- assert not _run_model_required('pooreNemecek2018', term, {
68
+ assert not _run_model_required('pooreNemecek2018', 'netPrimaryProduction', {
77
69
  'site': {'siteType': SiteSiteType.CROPLAND.value}
78
70
  })
79
71
 
@@ -1,4 +1,4 @@
1
- from unittest.mock import patch
1
+ from unittest.mock import Mock, patch
2
2
  from hestia_earth.schema import TermTermType
3
3
 
4
4
  from hestia_earth.models.utils.completeness import _is_term_type_complete, _is_term_type_incomplete
@@ -6,8 +6,8 @@ from hestia_earth.models.utils.completeness import _is_term_type_complete, _is_t
6
6
  class_path = 'hestia_earth.models.utils.completeness'
7
7
 
8
8
 
9
- @patch(f"{class_path}.download_hestia")
10
- def test_is_term_type_complete(mock_download):
9
+ @patch(f"{class_path}.download_term")
10
+ def test_is_term_type_complete(mock_download: Mock):
11
11
  cycle = {'completeness': {}}
12
12
 
13
13
  cycle['completeness'][TermTermType.CROPRESIDUE.value] = True
@@ -29,8 +29,8 @@ def test_is_term_type_complete(mock_download):
29
29
  assert not _is_term_type_complete(cycle, 'termid')
30
30
 
31
31
 
32
- @patch(f"{class_path}.download_hestia")
33
- def test_is_term_type_incomplete(mock_download):
32
+ @patch(f"{class_path}.download_term")
33
+ def test_is_term_type_incomplete(mock_download: Mock):
34
34
  cycle = {'completeness': {}}
35
35
 
36
36
  cycle['completeness'][TermTermType.CROPRESIDUE.value] = True
@@ -9,8 +9,8 @@ from hestia_earth.models.utils.emission import _new_emission, min_emission_metho
9
9
  class_path = 'hestia_earth.models.utils.emission'
10
10
 
11
11
 
12
- @patch(f'{class_path}._include_methodModel', side_effect=lambda n, x: n)
13
- @patch(f'{class_path}.download_hestia', return_value=TERM)
12
+ @patch(f'{class_path}.include_methodModel', side_effect=lambda n, x: n)
13
+ @patch(f'{class_path}.download_term', return_value=TERM)
14
14
  def test_new_emission(*args):
15
15
  # with a Term as string
16
16
  emission = _new_emission('term')
@@ -6,8 +6,8 @@ from hestia_earth.models.utils.indicator import _new_indicator
6
6
  class_path = 'hestia_earth.models.utils.indicator'
7
7
 
8
8
 
9
- @patch(f"{class_path}._include_methodModel", side_effect=lambda n, x: n)
10
- @patch(f"{class_path}.download_hestia", return_value=TERM)
9
+ @patch(f"{class_path}.include_methodModel", side_effect=lambda n, x: n)
10
+ @patch(f"{class_path}.download_term", return_value=TERM)
11
11
  def test_new_indicator(*args):
12
12
  # with a Term as string
13
13
  indicator = _new_indicator('term')
@@ -8,8 +8,8 @@ from hestia_earth.models.utils.input import _new_input, get_feed_inputs
8
8
  class_path = 'hestia_earth.models.utils.input'
9
9
 
10
10
 
11
- @patch(f"{class_path}._include_model", side_effect=lambda n, x: n)
12
- @patch(f"{class_path}.download_hestia", return_value=TERM)
11
+ @patch(f"{class_path}.include_model", side_effect=lambda n, x: n)
12
+ @patch(f"{class_path}.download_term", return_value=TERM)
13
13
  def test_new_input(*args):
14
14
  # with a Term as string
15
15
  input = _new_input('term')
@@ -1,11 +1,9 @@
1
1
  import json
2
2
  from pytest import mark
3
3
  from unittest.mock import patch
4
-
5
4
  from hestia_earth.schema import MeasurementMethodClassification
6
5
 
7
6
  from tests.utils import fixtures_path, TERM
8
-
9
7
  from hestia_earth.models.utils.measurement import (
10
8
  _new_measurement, most_relevant_measurement_value, min_measurement_method_classification
11
9
  )
@@ -14,8 +12,8 @@ class_path = 'hestia_earth.models.utils.measurement'
14
12
  fixtures_folder = f"{fixtures_path}/utils/measurement"
15
13
 
16
14
 
17
- @patch(f"{class_path}._include_method", side_effect=lambda n, **kwargs: n)
18
- @patch(f"{class_path}.download_hestia", return_value=TERM)
15
+ @patch(f"{class_path}.include_methodModel", side_effect=lambda n, **kwargs: n)
16
+ @patch(f"{class_path}.download_term", return_value=TERM)
19
17
  def test_new_measurement(*args):
20
18
  # with a Term as string
21
19
  measurement = _new_measurement('term')
@@ -3,9 +3,11 @@ from tests.utils import TERM
3
3
 
4
4
  from hestia_earth.models.utils.practice import _new_practice
5
5
 
6
+ class_path = 'hestia_earth.models.utils.practice'
6
7
 
7
- @patch('hestia_earth.models.utils.practice._include_model', side_effect=lambda n, x: n)
8
- @patch('hestia_earth.models.utils.practice.download_hestia', return_value=TERM)
8
+
9
+ @patch(f"{class_path}.include_model", side_effect=lambda n, x: n)
10
+ @patch(f"{class_path}.download_term", return_value=TERM)
9
11
  def test_new_practice(*args):
10
12
  # with a Term as string
11
13
  practice = _new_practice('term')
@@ -10,8 +10,8 @@ class_path = 'hestia_earth.models.utils.product'
10
10
  fixtures_folder = f"{fixtures_path}/utils/product"
11
11
 
12
12
 
13
- @patch(f"{class_path}._include_model", side_effect=lambda n, x: n)
14
- @patch(f"{class_path}.download_hestia", return_value=TERM)
13
+ @patch(f"{class_path}.include_model", side_effect=lambda n, x: n)
14
+ @patch(f"{class_path}.download_term", return_value=TERM)
15
15
  def test_new_product(*args):
16
16
  # with a Term as string
17
17
  product = _new_product('term', 10)
@@ -3,9 +3,11 @@ from tests.utils import TERM
3
3
 
4
4
  from hestia_earth.models.utils.property import _new_property
5
5
 
6
+ class_path = 'hestia_earth.models.utils.property'
6
7
 
7
- @patch('hestia_earth.models.utils.property._include_methodModel', side_effect=lambda n, x: n)
8
- @patch('hestia_earth.models.utils.property.download_hestia', return_value=TERM)
8
+
9
+ @patch(f'{class_path}.include_methodModel', side_effect=lambda n, x: n)
10
+ @patch(f'{class_path}.download_term', return_value=TERM)
9
11
  def test_new_property(*args):
10
12
  # with a Term as string
11
13
  property = _new_property('term')
@@ -25,6 +25,13 @@ def test_related_cycles(*args):
25
25
  assert related_cycles({'@id': 'id'}) == [CYCLE]
26
26
 
27
27
 
28
+ @patch(f"{class_path}.find_related", return_value=[CYCLE])
29
+ @patch(f"{class_path}._load_calculated_node")
30
+ def test_related_cycles_with_mapping(_load_calculated_node_mock, find_related_mock):
31
+ assert related_cycles({'@id': 'id'}, {'id': CYCLE}) == [CYCLE]
32
+ _load_calculated_node_mock.assert_not_called() # Confirm the load function is not used for nodes in mapping
33
+
34
+
28
35
  def test_valid_site_type():
29
36
  site = {'siteType': SiteSiteType.CROPLAND.value}
30
37
  assert valid_site_type(site) is True
@@ -3,7 +3,7 @@ from unittest.mock import patch
3
3
  from hestia_earth.orchestrator.strategies.run.add_blank_node_if_missing import should_run
4
4
 
5
5
  class_path = 'hestia_earth.orchestrator.strategies.run.add_blank_node_if_missing'
6
- FAKE_EMISSION = {'@id': 'n2OToAirExcretaDirect', 'termType': 'emission'}
6
+ FAKE_EMISSION = {'@id': 'n2OToAirCropResidueDecompositionIndirect', 'termType': 'emission'}
7
7
 
8
8
 
9
9
  @patch(f"{class_path}.get_required_model_param", return_value='')
@@ -95,20 +95,15 @@ def test_should_run_runNonMeasured(mock_node_exists, *args):
95
95
  assert should_run(data, model) is True
96
96
 
97
97
 
98
- @patch(f"{class_path}.get_table_value", return_value='Cycle')
99
- @patch(f"{class_path}.download_hestia", return_value=FAKE_EMISSION)
100
- @patch(f"{class_path}.get_required_model_param", return_value='')
98
+ @patch(f"{class_path}.get_required_model_param", return_value=FAKE_EMISSION.get('@id'))
101
99
  @patch(f"{class_path}.find_term_match")
102
100
  def test_should_run_check_typeAllowed(mock_node_exists, *args):
103
- data = {}
104
101
  node = {'term': FAKE_EMISSION}
105
102
  mock_node_exists.return_value = node
106
103
  model = {}
107
104
 
108
105
  # type is not allowed => no run
109
- data['@type'] = 'Transformation'
110
- assert not should_run(data, model)
106
+ assert not should_run({'type': 'Transformation'}, model)
111
107
 
112
108
  # type is allowed => run
113
- data['@type'] = 'Cycle'
114
- assert should_run(data, model) is True
109
+ assert should_run({'type': 'Cycle'}, model) is True