hestia-earth-models 0.67.0__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.
- hestia_earth/models/aware/scarcityWeightedWaterUse.py +5 -6
- hestia_earth/models/blonkConsultants2016/ch4ToAirNaturalVegetationBurning.py +1 -1
- hestia_earth/models/blonkConsultants2016/co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +1 -1
- hestia_earth/models/blonkConsultants2016/n2OToAirNaturalVegetationBurningDirect.py +1 -1
- hestia_earth/models/blonkConsultants2016/utils.py +9 -9
- hestia_earth/models/cache_sites.py +26 -14
- hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsLandOccupation.py +2 -2
- hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsLandTransformation.py +2 -2
- hestia_earth/models/chaudharyBrooks2018/utils.py +13 -8
- hestia_earth/models/cml2001Baseline/abioticResourceDepletionFossilFuels.py +2 -3
- hestia_earth/models/cml2001Baseline/abioticResourceDepletionMineralsAndMetals.py +1 -1
- hestia_earth/models/cml2001Baseline/resourceUseEnergyDepletionDuringCycle.py +5 -10
- hestia_earth/models/config/Cycle.json +15 -0
- hestia_earth/models/config/ImpactAssessment.json +14 -1
- hestia_earth/models/config/Site.json +8 -0
- hestia_earth/models/cycle/completeness/freshForage.py +7 -3
- hestia_earth/models/cycle/excretaKgMass.py +2 -2
- hestia_earth/models/cycle/inorganicFertiliser.py +67 -17
- hestia_earth/models/cycle/materialAndSubstrate.py +3 -2
- hestia_earth/models/cycle/pastureGrass.py +3 -3
- hestia_earth/models/dammgen2009/noxToAirExcreta.py +1 -1
- hestia_earth/models/ecoinventV3AndEmberClimate/__init__.py +1 -1
- hestia_earth/models/ecoinventV3AndEmberClimate/utils.py +2 -6
- hestia_earth/models/emissionNotRelevant/__init__.py +4 -4
- hestia_earth/models/environmentalFootprintV3_1/environmentalFootprintSingleOverallScore.py +60 -46
- hestia_earth/models/environmentalFootprintV3_1/photochemicalOzoneCreationPotentialHumanHealthNmvocEq.py +36 -0
- hestia_earth/models/environmentalFootprintV3_1/scarcityWeightedWaterUse.py +2 -2
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandOccupation.py +9 -8
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandTransformation.py +45 -34
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexTotalLandUseEffects.py +24 -21
- hestia_earth/models/faostat2018/coldCarcassWeightPerHead.py +2 -2
- hestia_earth/models/faostat2018/coldDressedCarcassWeightPerHead.py +2 -2
- hestia_earth/models/faostat2018/liveweightPerHead.py +7 -8
- hestia_earth/models/faostat2018/product/price.py +34 -28
- hestia_earth/models/faostat2018/readyToCookWeightPerHead.py +2 -2
- hestia_earth/models/faostat2018/utils.py +15 -27
- hestia_earth/models/frischknechtEtAl2000/ionisingRadiationKbqU235Eq.py +16 -9
- hestia_earth/models/geospatialDatabase/altitude.py +60 -0
- hestia_earth/models/geospatialDatabase/croppingIntensity.py +1 -1
- hestia_earth/models/geospatialDatabase/ecoClimateZone.py +2 -2
- hestia_earth/models/geospatialDatabase/longFallowRatio.py +1 -1
- hestia_earth/models/geospatialDatabase/utils.py +4 -1
- hestia_earth/models/globalCropWaterModel2008/rootingDepth.py +2 -3
- hestia_earth/models/haversineFormula/transport/distance.py +3 -3
- hestia_earth/models/hestia/landCover.py +72 -45
- hestia_earth/models/hestia/landTransformation100YearAverageDuringCycle.py +1 -1
- hestia_earth/models/hestia/landTransformation20YearAverageDuringCycle.py +1 -1
- hestia_earth/models/hestia/seed_emissions.py +11 -7
- hestia_earth/models/impact_assessment/__init__.py +3 -3
- hestia_earth/models/ipcc2019/aboveGroundBiomass.py +1 -1
- hestia_earth/models/ipcc2019/animal/fatContent.py +1 -1
- hestia_earth/models/ipcc2019/animal/hoursWorkedPerDay.py +1 -1
- hestia_earth/models/ipcc2019/animal/liveweightGain.py +1 -1
- hestia_earth/models/ipcc2019/animal/liveweightPerHead.py +1 -1
- hestia_earth/models/ipcc2019/animal/milkYieldPerAnimal.py +1 -1
- hestia_earth/models/ipcc2019/animal/pastureGrass.py +1 -1
- hestia_earth/models/ipcc2019/animal/pregnancyRateTotal.py +1 -1
- hestia_earth/models/ipcc2019/animal/trueProteinContent.py +1 -1
- hestia_earth/models/ipcc2019/animal/utils.py +5 -7
- hestia_earth/models/ipcc2019/animal/weightAtMaturity.py +1 -1
- hestia_earth/models/ipcc2019/belowGroundBiomass.py +1 -1
- hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py +2 -2
- hestia_earth/models/ipcc2019/ch4ToAirExcreta.py +6 -7
- hestia_earth/models/ipcc2019/ch4ToAirFloodedRice.py +5 -3
- hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +1 -1
- hestia_earth/models/ipcc2019/croppingDuration.py +3 -6
- hestia_earth/models/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning.py +947 -0
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +4 -4
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +1 -1
- hestia_earth/models/ipcc2019/pastureGrass.py +1 -1
- hestia_earth/models/koble2014/residueBurnt.py +5 -7
- hestia_earth/models/koble2014/residueRemoved.py +5 -7
- hestia_earth/models/lcImpactAllEffects100Years/damageToHumanHealthWaterStress.py +2 -2
- hestia_earth/models/lcImpactAllEffectsInfinite/damageToHumanHealthWaterStress.py +2 -2
- hestia_earth/models/lcImpactCertainEffects100Years/damageToHumanHealthWaterStress.py +2 -2
- hestia_earth/models/lcImpactCertainEffectsInfinite/damageToHumanHealthWaterStress.py +2 -2
- hestia_earth/models/log.py +1 -1
- hestia_earth/models/mocking/search-results.json +3477 -1045
- hestia_earth/models/site/management.py +1 -1
- hestia_earth/models/site/post_checks/__init__.py +3 -2
- hestia_earth/models/site/post_checks/country.py +9 -0
- hestia_earth/models/site/pre_checks/__init__.py +3 -2
- hestia_earth/models/site/pre_checks/country.py +9 -0
- hestia_earth/models/utils/__init__.py +1 -16
- hestia_earth/models/utils/blank_node.py +89 -36
- hestia_earth/models/utils/completeness.py +3 -2
- hestia_earth/models/utils/cycle.py +5 -4
- hestia_earth/models/utils/ecoClimateZone.py +2 -2
- hestia_earth/models/utils/emission.py +5 -5
- hestia_earth/models/utils/feedipedia.py +6 -6
- hestia_earth/models/utils/impact_assessment.py +6 -6
- hestia_earth/models/utils/indicator.py +9 -7
- hestia_earth/models/utils/inorganicFertiliser.py +4 -6
- hestia_earth/models/utils/input.py +6 -5
- hestia_earth/models/utils/lookup.py +35 -105
- hestia_earth/models/utils/management.py +4 -4
- hestia_earth/models/utils/measurement.py +6 -7
- hestia_earth/models/utils/method.py +20 -0
- hestia_earth/models/utils/practice.py +4 -5
- hestia_earth/models/utils/product.py +4 -5
- hestia_earth/models/utils/property.py +12 -22
- hestia_earth/models/utils/site.py +14 -8
- hestia_earth/models/utils/term.py +27 -1
- hestia_earth/models/version.py +1 -1
- hestia_earth/orchestrator/log.py +0 -11
- hestia_earth/orchestrator/models/__init__.py +17 -4
- hestia_earth/orchestrator/strategies/run/add_blank_node_if_missing.py +2 -20
- {hestia_earth_models-0.67.0.dist-info → hestia_earth_models-0.68.0.dist-info}/METADATA +2 -2
- {hestia_earth_models-0.67.0.dist-info → hestia_earth_models-0.68.0.dist-info}/RECORD +159 -151
- tests/models/cml2001Baseline/test_abioticResourceDepletionFossilFuels.py +3 -3
- tests/models/cml2001Baseline/test_resourceUseEnergyDepletionDuringCycle.py +68 -35
- tests/models/cycle/test_coldCarcassWeightPerHead.py +1 -1
- tests/models/cycle/test_coldDressedCarcassWeightPerHead.py +1 -1
- tests/models/cycle/test_concentrateFeed.py +1 -1
- tests/models/cycle/test_energyContentLowerHeatingValue.py +1 -1
- tests/models/cycle/test_excretaKgMass.py +1 -1
- tests/models/cycle/test_feedConversionRatio.py +3 -3
- tests/models/cycle/test_pastureGrass.py +1 -1
- tests/models/cycle/test_readyToCookWeightPerHead.py +1 -1
- tests/models/environmentalFootprintV3_1/test_environmentalFootprintSingleOverallScore.py +38 -8
- tests/models/environmentalFootprintV3_1/test_photochemicalOzoneCreationPotentialHumanHealthNmvocEq.py +30 -0
- tests/models/environmentalFootprintV3_1/test_soilQualityIndexLandTransformation.py +65 -36
- tests/models/environmentalFootprintV3_1/test_soilQualityIndexTotalLandUseEffects.py +30 -7
- tests/models/faostat2018/product/test_price.py +27 -14
- tests/models/faostat2018/test_faostat_utils.py +4 -24
- tests/models/faostat2018/test_liveweightPerHead.py +9 -9
- tests/models/globalCropWaterModel2008/test_rootingDepth.py +7 -3
- tests/models/haversineFormula/transport/test_distance.py +1 -1
- tests/models/hestia/test_landCover.py +53 -5
- tests/models/ipcc2019/animal/test_pastureGrass.py +5 -3
- tests/models/ipcc2019/test_aboveGroundCropResidueTotal.py +4 -4
- tests/models/ipcc2019/test_belowGroundCropResidue.py +4 -4
- tests/models/ipcc2019/test_ch4ToAirEntericFermentation.py +10 -10
- tests/models/ipcc2019/test_croppingDuration.py +1 -1
- tests/models/ipcc2019/test_nonCo2EmissionsToAirNaturalVegetationBurning.py +83 -0
- tests/models/ipcc2019/test_organicCarbonPerHa.py +12 -12
- tests/models/ipcc2019/test_pastureGrass.py +5 -3
- tests/models/pooreNemecek2018/test_excretaKgN.py +5 -5
- tests/models/pooreNemecek2018/test_excretaKgVs.py +2 -2
- tests/models/site/post_checks/test_country.py +6 -0
- tests/models/site/pre_checks/test_cache_geospatialDatabase.py +1 -1
- tests/models/site/pre_checks/test_country.py +12 -0
- tests/models/site/test_management.py +1 -4
- tests/models/test_ecoinventV3.py +7 -3
- tests/models/utils/test_blank_node.py +17 -177
- tests/models/utils/test_dataCompleteness.py +5 -5
- tests/models/utils/test_emission.py +2 -2
- tests/models/utils/test_indicator.py +2 -2
- tests/models/utils/test_input.py +2 -2
- tests/models/utils/test_measurement.py +2 -4
- tests/models/utils/test_practice.py +4 -2
- tests/models/utils/test_product.py +2 -2
- tests/models/utils/test_property.py +4 -2
- tests/models/utils/test_site.py +7 -0
- tests/orchestrator/models/test_transformations.py +4 -1
- tests/orchestrator/strategies/run/test_add_blank_node_if_missing.py +4 -9
- hestia_earth/models/environmentalFootprintV3_1/utils.py +0 -17
- tests/models/utils/test_lookup.py +0 -10
- {hestia_earth_models-0.67.0.dist-info → hestia_earth_models-0.68.0.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.67.0.dist-info → hestia_earth_models-0.68.0.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.67.0.dist-info → hestia_earth_models-0.68.0.dist-info}/top_level.txt +0 -0
@@ -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}.
|
234
|
+
@patch(f"{property_path}.download_term")
|
235
235
|
def test_should_run(
|
236
|
-
|
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
|
-
|
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}.
|
272
|
+
@patch(f"{property_path}.download_term")
|
273
273
|
def test_should_run_no_data(
|
274
|
-
|
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
|
-
|
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}.
|
307
|
+
@patch(f"{property_path}.download_term")
|
308
308
|
def test_run(
|
309
|
-
|
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
|
-
|
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}.
|
374
|
+
@patch(f"{property_path}.download_term")
|
375
375
|
def test_run_with_stats(
|
376
|
-
|
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
|
-
|
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(
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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,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')
|
@@ -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]
|
tests/models/test_ecoinventV3.py
CHANGED
@@ -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
|
-
|
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:
|
@@ -30,202 +30,42 @@ from hestia_earth.models.utils.blank_node import (
|
|
30
30
|
|
31
31
|
|
32
32
|
class_path = "hestia_earth.models.utils.blank_node"
|
33
|
-
|
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
|
-
|
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"{
|
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():
|
208
|
-
|
209
|
-
'@id': 'ch4ToAirAquacultureSystems',
|
210
|
-
'termType': 'emission'
|
211
|
-
}
|
212
|
-
assert not _run_required('model', term, {
|
56
|
+
assert not _run_required('model', 'ch4ToAirAquacultureSystems', {
|
213
57
|
'site': {'siteType': SiteSiteType.CROPLAND.value}
|
214
58
|
})
|
215
|
-
assert _run_required('model',
|
59
|
+
assert _run_required('model', 'ch4ToAirAquacultureSystems', {
|
216
60
|
'site': {'siteType': SiteSiteType.POND.value}
|
217
61
|
}) is True
|
218
62
|
|
219
63
|
|
220
64
|
def test_run_model_required():
|
221
|
-
|
222
|
-
'@id': 'netPrimaryProduction',
|
223
|
-
'termType': 'measurement'
|
224
|
-
}
|
225
|
-
assert _run_model_required('pooreNemecek2018', term, {
|
65
|
+
assert _run_model_required('pooreNemecek2018', 'netPrimaryProduction', {
|
226
66
|
'site': {'siteType': SiteSiteType.POND.value}
|
227
67
|
}) is True
|
228
|
-
assert not _run_model_required('pooreNemecek2018',
|
68
|
+
assert not _run_model_required('pooreNemecek2018', 'netPrimaryProduction', {
|
229
69
|
'site': {'siteType': SiteSiteType.CROPLAND.value}
|
230
70
|
})
|
231
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}.
|
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}.
|
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}.
|
13
|
-
@patch(f'{class_path}.
|
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}.
|
10
|
-
@patch(f"{class_path}.
|
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')
|
tests/models/utils/test_input.py
CHANGED
@@ -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}.
|
12
|
-
@patch(f"{class_path}.
|
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}.
|
18
|
-
@patch(f"{class_path}.
|
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
|
-
|
8
|
-
@patch(
|
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}.
|
14
|
-
@patch(f"{class_path}.
|
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
|
-
|
8
|
-
@patch('
|
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')
|
tests/models/utils/test_site.py
CHANGED
@@ -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
|
@@ -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)
|