hestia-earth-models 0.65.11__py3-none-any.whl → 0.67.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/cache_sites.py +7 -9
- hestia_earth/models/cml2001Baseline/abioticResourceDepletionFossilFuels.py +23 -54
- hestia_earth/models/cml2001Baseline/resourceUseEnergyDepletionDuringCycle.py +152 -0
- hestia_earth/models/cml2001Baseline/resourceUseEnergyDepletionInputsProduction.py +40 -0
- hestia_earth/models/cml2001Baseline/resourceUseMineralsAndMetalsDuringCycle.py +80 -0
- hestia_earth/models/cml2001Baseline/resourceUseMineralsAndMetalsInputsProduction.py +40 -0
- hestia_earth/models/config/Cycle.json +34 -16
- hestia_earth/models/config/ImpactAssessment.json +1867 -1832
- hestia_earth/models/config/Site.json +4 -1
- hestia_earth/models/cycle/completeness/freshForage.py +10 -2
- hestia_earth/models/cycle/cropResidueManagement.py +3 -1
- hestia_earth/models/cycle/input/hestiaAggregatedData.py +13 -10
- hestia_earth/models/ecoinventV3/__init__.py +2 -1
- hestia_earth/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/__init__.py +4 -3
- hestia_earth/models/environmentalFootprintV3_1/environmentalFootprintSingleOverallScore.py +135 -0
- hestia_earth/models/environmentalFootprintV3_1/marineEutrophicationPotential.py +36 -0
- hestia_earth/models/environmentalFootprintV3_1/scarcityWeightedWaterUse.py +40 -0
- hestia_earth/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/soilQualityIndexLandTransformation.py +17 -6
- hestia_earth/models/geospatialDatabase/{aware.py → awareWaterBasinId.py} +1 -1
- hestia_earth/models/hestia/landCover.py +42 -34
- hestia_earth/models/hestia/residueRemoved.py +80 -0
- hestia_earth/models/hestia/resourceUse_utils.py +43 -29
- hestia_earth/models/impact_assessment/product/value.py +1 -1
- hestia_earth/models/ipcc2019/aboveGroundBiomass.py +34 -13
- hestia_earth/models/ipcc2019/belowGroundBiomass.py +33 -12
- hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py +17 -8
- hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +7 -4
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +2 -1
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +29 -18
- hestia_earth/models/ipcc2019/pastureGrass_utils.py +8 -1
- hestia_earth/models/log.py +1 -1
- hestia_earth/models/mocking/search-results.json +872 -872
- hestia_earth/models/site/defaultMethodClassification.py +9 -2
- hestia_earth/models/site/defaultMethodClassificationDescription.py +4 -2
- hestia_earth/models/site/management.py +48 -30
- hestia_earth/models/site/pre_checks/cache_geospatialDatabase.py +19 -14
- hestia_earth/models/utils/__init__.py +6 -0
- hestia_earth/models/utils/aggregated.py +13 -10
- hestia_earth/models/utils/array_builders.py +4 -3
- hestia_earth/models/utils/blank_node.py +23 -13
- hestia_earth/models/utils/lookup.py +4 -2
- hestia_earth/models/utils/property.py +5 -2
- hestia_earth/models/version.py +1 -1
- hestia_earth/orchestrator/log.py +11 -0
- hestia_earth/orchestrator/models/__init__.py +8 -3
- hestia_earth/orchestrator/strategies/merge/merge_list.py +17 -6
- {hestia_earth_models-0.65.11.dist-info → hestia_earth_models-0.67.0.dist-info}/METADATA +1 -1
- {hestia_earth_models-0.65.11.dist-info → hestia_earth_models-0.67.0.dist-info}/RECORD +86 -69
- tests/models/cml2001Baseline/test_abioticResourceDepletionFossilFuels.py +51 -87
- tests/models/cml2001Baseline/test_resourceUseEnergyDepletionDuringCycle.py +103 -0
- tests/models/cml2001Baseline/test_resourceUseEnergyDepletionInputsProduction.py +23 -0
- tests/models/cml2001Baseline/test_resourceUseMineralsAndMetalsDuringCycle.py +58 -0
- tests/models/cml2001Baseline/test_resourceUseMineralsAndMetalsInputsProduction.py +23 -0
- tests/models/environmentalFootprintV3_1/test_environmentalFootprintSingleOverallScore.py +93 -0
- tests/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/test_freshwaterEcotoxicityPotentialCtue.py +6 -5
- tests/models/environmentalFootprintV3_1/test_marineEutrophicationPotential.py +27 -0
- tests/models/environmentalFootprintV3_1/test_scarcityWeightedWaterUse.py +32 -0
- tests/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/test_soilQualityIndexLandOccupation.py +4 -3
- tests/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/test_soilQualityIndexLandTransformation.py +8 -22
- tests/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/test_soilQualityIndexTotalLandUseEffects.py +4 -4
- tests/models/faostat2018/product/test_price.py +1 -1
- tests/models/geospatialDatabase/{test_aware.py → test_awareWaterBasinId.py} +1 -1
- tests/models/hestia/test_landCover.py +2 -1
- tests/models/hestia/test_landTransformation20YearAverageDuringCycle.py +2 -1
- tests/models/hestia/test_residueRemoved.py +20 -0
- tests/models/impact_assessment/test_emissions.py +0 -1
- tests/models/ipcc2019/test_aboveGroundBiomass.py +3 -1
- tests/models/ipcc2019/test_belowGroundBiomass.py +4 -2
- tests/models/ipcc2019/test_organicCarbonPerHa.py +94 -1
- tests/models/site/pre_checks/test_cache_geospatialDatabase.py +22 -0
- tests/models/site/test_defaultMethodClassification.py +6 -0
- tests/models/site/test_defaultMethodClassificationDescription.py +6 -0
- tests/models/site/test_management.py +4 -4
- tests/models/test_cache_sites.py +2 -2
- tests/models/test_config.py +3 -3
- tests/models/test_ecoinventV3.py +0 -1
- tests/models/utils/test_array_builders.py +2 -2
- tests/orchestrator/strategies/merge/test_merge_list.py +11 -1
- /hestia_earth/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/freshwaterEcotoxicityPotentialCtue.py +0 -0
- /hestia_earth/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/soilQualityIndexLandOccupation.py +0 -0
- /hestia_earth/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/soilQualityIndexTotalLandUseEffects.py +0 -0
- /hestia_earth/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/utils.py +0 -0
- {hestia_earth_models-0.65.11.dist-info → hestia_earth_models-0.67.0.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.65.11.dist-info → hestia_earth_models-0.67.0.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.65.11.dist-info → hestia_earth_models-0.67.0.dist-info}/top_level.txt +0 -0
- /tests/models/{environmentalFootprintV3 → environmentalFootprintV3_1}/__init__.py +0 -0
@@ -4,7 +4,7 @@ from unittest.mock import patch
|
|
4
4
|
from pytest import mark
|
5
5
|
|
6
6
|
from hestia_earth.models.cml2001Baseline.abioticResourceDepletionFossilFuels import MODEL, TERM_ID, run, _should_run, \
|
7
|
-
|
7
|
+
get_all_non_renewable_terms
|
8
8
|
from tests.utils import fixtures_path, fake_new_indicator
|
9
9
|
|
10
10
|
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
@@ -17,7 +17,7 @@ def fake_rounded_indicator(value: float):
|
|
17
17
|
return indicator
|
18
18
|
|
19
19
|
|
20
|
-
def fake_download_hestia(filename):
|
20
|
+
def fake_download_hestia(filename, column_name):
|
21
21
|
data = {
|
22
22
|
'fuel.csv': ["lignite", "conventionalCrudeOil", "naturalGas", "coalTar"],
|
23
23
|
'electricity.csv': ['electricityGridMarketMix', 'electricityGridHardCoal', 'electricityProducedOnSiteHardCoal',
|
@@ -27,94 +27,56 @@ def fake_download_hestia(filename):
|
|
27
27
|
|
28
28
|
|
29
29
|
input_lignite_mj = {"@id": "lignite", "name": "lignite (Brown coal)", "termType": "fuel", "units": "MJ"}
|
30
|
-
|
31
|
-
input_crude_oil_kg_property = {
|
32
|
-
"@id": "conventionalCrudeOil", "name": "Conventional Crude Oil", "termType": "fuel", "units": "kg",
|
33
|
-
"properties": [{"@type": "Property", "value": 45.8,
|
34
|
-
"term": {"@type": "Term", "@id": "energyContentHigherHeatingValue", "units": "MJ / kg"}, }]}
|
35
|
-
input_crude_oil_kg_no_property = {
|
36
|
-
"@id": "conventionalCrudeOil", "name": "Conventional Crude Oil", "termType": "fuel", "units": "kg"}
|
37
|
-
input_natural_gas_m3 = {"@id": "naturalGas", "name": "Natural Gas", "termType": "fuel", "units": "m3"}
|
30
|
+
|
38
31
|
input_nuclear_fuel_mj = {"@id": "electricityGridNuclear", "name": "Any depleted nuclear fuel",
|
39
32
|
"termType": "electricity", "units": "MJ"}
|
40
|
-
|
33
|
+
|
41
34
|
input_excessIndustrialHeat_mj = {"@id": "excessIndustrialHeat", "name": "Excess industrial heat", "termType": "fuel",
|
42
35
|
"units": "MJ"}
|
43
36
|
|
44
|
-
wrong_indicator = {"term": {"@id": "BAD_INDICATOR_ID", "termType": "resourceUse"},
|
37
|
+
wrong_indicator = {"term": {"@id": "BAD_INDICATOR_ID", "termType": "resourceUse", "units": "MJ"},
|
45
38
|
"value": 5,
|
46
39
|
"inputs": [input_lignite_mj]}
|
47
40
|
|
48
|
-
indicator_no_inputs = {
|
49
|
-
|
50
|
-
|
41
|
+
indicator_no_inputs = {
|
42
|
+
"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse", "units": "MJ"},
|
43
|
+
"value": 5,
|
44
|
+
"inputs": []}
|
51
45
|
|
52
|
-
indicator_2_inputs = {
|
53
|
-
|
54
|
-
|
46
|
+
indicator_2_inputs = {
|
47
|
+
"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse", "units": "MJ"},
|
48
|
+
"value": 5,
|
49
|
+
"inputs": [input_lignite_mj, input_lignite_mj]}
|
55
50
|
|
56
51
|
indicator_no_unit = {"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse"},
|
57
52
|
"value": 5,
|
58
|
-
"inputs": [
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
"termType": "fuel",
|
63
|
-
}]}
|
64
|
-
|
65
|
-
indicator_wrong_unit = {"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse"},
|
53
|
+
"inputs": [input_lignite_mj]}
|
54
|
+
|
55
|
+
indicator_wrong_unit = {"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse",
|
56
|
+
"units": "ha"},
|
66
57
|
"value": 5,
|
67
|
-
"inputs": [
|
68
|
-
{
|
69
|
-
"@id": "lignite",
|
70
|
-
"@type": "Term",
|
71
|
-
"name": "lignite (Brown coal)",
|
72
|
-
"termType": "fuel",
|
73
|
-
"units": "ha"
|
74
|
-
}
|
75
|
-
]}
|
76
|
-
|
77
|
-
indicator_bad_input_id = {"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse"},
|
78
|
-
"value": 5,
|
79
|
-
"inputs": [input_excessIndustrialHeat_mj]}
|
58
|
+
"inputs": [input_lignite_mj]}
|
80
59
|
|
81
|
-
|
82
|
-
"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse"},
|
60
|
+
indicator_bad_input_id = {
|
61
|
+
"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse", "units": "MJ"},
|
83
62
|
"value": 5,
|
84
|
-
"inputs": [
|
85
|
-
}
|
63
|
+
"inputs": [input_excessIndustrialHeat_mj]}
|
86
64
|
|
87
|
-
|
88
|
-
|
89
|
-
"inputs": [input_lignite_mj]}
|
90
|
-
|
91
|
-
good_indicator_inputs_production_with_property = {
|
92
|
-
"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse"},
|
65
|
+
good_indicator_inputs_production_mj = {
|
66
|
+
"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse", "units": "MJ"},
|
93
67
|
"value": 5,
|
94
|
-
"inputs": [
|
68
|
+
"inputs": [input_lignite_mj]
|
95
69
|
}
|
96
70
|
|
97
|
-
|
98
|
-
"term": {"@id": "
|
71
|
+
good_indicator_during_cycle_mj = {
|
72
|
+
"term": {"@id": "resourceUseEnergyDepletionDuringCycle", "termType": "resourceUse", "units": "MJ"},
|
99
73
|
"value": 5,
|
100
|
-
"inputs": [
|
101
|
-
}
|
102
|
-
|
103
|
-
good_indicator_m3 = {"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse"},
|
104
|
-
"value": 5,
|
105
|
-
"inputs": [input_natural_gas_m3]}
|
106
|
-
|
107
|
-
good_nuclear_indicator_mj = {"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse"},
|
108
|
-
"value": 5,
|
109
|
-
"inputs": [input_nuclear_fuel_mj]}
|
110
|
-
good_nuclear_indicator_kwh = {"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse"},
|
111
|
-
"value": 1.3889,
|
112
|
-
"inputs": [input_nuclear_fuel_kwh]}
|
74
|
+
"inputs": [input_lignite_mj]}
|
113
75
|
|
114
|
-
|
115
|
-
"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse"},
|
76
|
+
good_nuclear_indicator_mj = {
|
77
|
+
"term": {"@id": "resourceUseEnergyDepletionInputsProduction", "termType": "resourceUse", "units": "MJ"},
|
116
78
|
"value": 5,
|
117
|
-
"inputs": [
|
79
|
+
"inputs": [input_nuclear_fuel_mj]}
|
118
80
|
|
119
81
|
|
120
82
|
@mark.parametrize(
|
@@ -124,26 +86,27 @@ bad_fuel_indicator_no_property_lookup = {
|
|
124
86
|
([wrong_indicator], False, 0),
|
125
87
|
([indicator_no_inputs], False, 0),
|
126
88
|
([indicator_2_inputs], False, 2),
|
127
|
-
([indicator_no_unit], False,
|
128
|
-
([indicator_wrong_unit], False,
|
89
|
+
([indicator_no_unit], False, 1),
|
90
|
+
([indicator_wrong_unit], False, 1),
|
129
91
|
([indicator_bad_input_id], False, 0),
|
130
92
|
([good_indicator_inputs_production_mj], True, 1),
|
131
93
|
([good_indicator_during_cycle_mj], True, 1),
|
132
|
-
([good_indicator_inputs_production_with_property], True, 1),
|
133
|
-
([good_indicator_inputs_production_with_no_property], True, 1),
|
134
|
-
([good_indicator_m3], True, 1),
|
135
94
|
([good_nuclear_indicator_mj], True, 1),
|
136
|
-
([good_nuclear_indicator_kwh], True, 1),
|
137
|
-
([bad_fuel_indicator_no_property_lookup], False, 0),
|
138
95
|
],
|
139
|
-
ids=["No indicators",
|
140
|
-
"
|
141
|
-
"
|
142
|
-
"
|
143
|
-
"
|
96
|
+
ids=["No indicators",
|
97
|
+
"wrong indicator",
|
98
|
+
"indicator no inputs",
|
99
|
+
"indicator 2 inputs",
|
100
|
+
"missing unit",
|
101
|
+
"wrong unit",
|
102
|
+
"input id not in requirements",
|
103
|
+
"good input production mj",
|
104
|
+
"good during cycle mj",
|
105
|
+
"good nuclear fuel use indicator in mj",
|
106
|
+
]
|
144
107
|
)
|
145
|
-
@patch(f"{class_path}.
|
146
|
-
def test_should_run(
|
108
|
+
@patch(f"{class_path}.get_all_non_renewable_terms", side_effect=fake_download_hestia)
|
109
|
+
def test_should_run(mock_get_all_non_renewable_terms, resources, expected, num_inputs):
|
147
110
|
with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
|
148
111
|
impactassessment = json.load(f)
|
149
112
|
|
@@ -154,7 +117,7 @@ def test_should_run(mock_download_all_non_renewable_terms, resources, expected,
|
|
154
117
|
assert len(resources) == num_inputs
|
155
118
|
|
156
119
|
|
157
|
-
@patch(f"{class_path}.
|
120
|
+
@patch(f"{class_path}.get_all_non_renewable_terms", side_effect=fake_download_hestia)
|
158
121
|
@patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
|
159
122
|
def test_run(*args):
|
160
123
|
with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
|
@@ -167,16 +130,17 @@ def test_run(*args):
|
|
167
130
|
assert value == expected
|
168
131
|
|
169
132
|
|
170
|
-
def
|
133
|
+
def test_get_all_non_renewable_terms(*args):
|
171
134
|
"""
|
172
|
-
make sure
|
135
|
+
make sure get_all_non_renewable_terms() only returns terms we want
|
173
136
|
"""
|
174
|
-
electricity_terms =
|
137
|
+
electricity_terms = get_all_non_renewable_terms("electricity.csv", "consideredFossilFuelUnderCml2001Baseline")
|
175
138
|
|
176
139
|
assert "electricityGridHardCoal" in electricity_terms
|
177
140
|
assert "electricityGridWind" not in electricity_terms
|
178
141
|
|
179
|
-
fuel_terms =
|
142
|
+
fuel_terms = get_all_non_renewable_terms("fuel.csv", "consideredFossilFuelUnderCml2001Baseline")
|
180
143
|
|
181
144
|
assert "coalTar" in fuel_terms
|
182
145
|
assert "sodPeat" in fuel_terms
|
146
|
+
assert "bioJetKerosene" not in fuel_terms
|
@@ -0,0 +1,103 @@
|
|
1
|
+
import json
|
2
|
+
from unittest.mock import patch
|
3
|
+
|
4
|
+
import pytest
|
5
|
+
|
6
|
+
from hestia_earth.models.cml2001Baseline.resourceUseEnergyDepletionDuringCycle import MODEL, TERM_ID, run, _should_run
|
7
|
+
from tests.utils import fixtures_path, fake_new_indicator
|
8
|
+
|
9
|
+
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
10
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
11
|
+
|
12
|
+
diesel_input = {"term": {"termType": "fuel", "units": "kg", "@id": "diesel"}, "value": 2}
|
13
|
+
diesel_input_in_mj = {"term": {"termType": "fuel", "units": "MJ", "@id": "diesel"}, "value": 111}
|
14
|
+
diesel_input_wrong_unit = {"term": {"termType": "fuel", "units": "foobedoos", "@id": "diesel"}, "value": 2}
|
15
|
+
diesel_input_no_unit = {"term": {"termType": "fuel", "@id": "diesel"}, "value": 2}
|
16
|
+
diesel_input_with_properties = {"term": {"termType": "fuel", "units": "kg", "@id": "diesel"},
|
17
|
+
"value": 2,
|
18
|
+
"properties": [{"term": {"@id": "energyContentHigherHeatingValue", }, "value": 70}]
|
19
|
+
}
|
20
|
+
diesel_input_with_properties2 = {"term": {"termType": "fuel", "units": "kg", "@id": "diesel"},
|
21
|
+
"value": 2,
|
22
|
+
"properties": [{"term": {"@id": "energyContentHigherHeatingValue", }, "value": 4}]
|
23
|
+
}
|
24
|
+
|
25
|
+
electricity_input = {"term": {"termType": "electricity", "units": "kWh", "@id": "electricityGridOil"}, "value": 30}
|
26
|
+
|
27
|
+
input_coal_tar_kg = {"term": {"@id": "coalTar", "termType": "fuel", "units": "kg",
|
28
|
+
"name": "Coal tar unknown energy Content"},
|
29
|
+
"value": 5}
|
30
|
+
|
31
|
+
input_crude_oil_kg_property = {"term": {"@id": "conventionalCrudeOil", "termType": "fuel", "units": "kg"},
|
32
|
+
"value": 5,
|
33
|
+
"properties": [{"@type": "Property", "value": 45.8,
|
34
|
+
"term": {"@type": "Term", "@id": "energyContentHigherHeatingValue",
|
35
|
+
"units": "MJ / kg"}, }]}
|
36
|
+
|
37
|
+
input_crude_oil_kg_no_property = {"term": {"@id": "conventionalCrudeOil", "termType": "fuel", "units": "kg"},
|
38
|
+
"value": 5}
|
39
|
+
|
40
|
+
input_natural_gas_m3 = {"term": {"@id": "naturalGas", "termType": "fuel", "units": "m3"}, "value": 5}
|
41
|
+
|
42
|
+
input_nuclear_fuel_kwh = {"term": {"@id": "electricityGridNuclear", "termType": "electricity", "units": "kWh"},
|
43
|
+
"value": 1.3889}
|
44
|
+
|
45
|
+
|
46
|
+
@pytest.mark.parametrize(
|
47
|
+
"inputs, expected, num_inputs",
|
48
|
+
[
|
49
|
+
([], False, 0),
|
50
|
+
([diesel_input_wrong_unit], False, 0),
|
51
|
+
([diesel_input_no_unit], False, 0),
|
52
|
+
([diesel_input], True, 1),
|
53
|
+
([diesel_input, diesel_input, diesel_input_in_mj], True, 1),
|
54
|
+
([diesel_input, diesel_input_with_properties], True, 1),
|
55
|
+
([diesel_input_with_properties, diesel_input_with_properties], True, 1),
|
56
|
+
([diesel_input_with_properties2, diesel_input_with_properties], True, 1),
|
57
|
+
([electricity_input], True, 1),
|
58
|
+
([electricity_input, electricity_input, electricity_input], True, 1),
|
59
|
+
([input_crude_oil_kg_property], True, 1),
|
60
|
+
([input_crude_oil_kg_no_property], True, 1),
|
61
|
+
([input_natural_gas_m3], True, 1),
|
62
|
+
([input_nuclear_fuel_kwh], True, 1),
|
63
|
+
([input_coal_tar_kg], False, 0),
|
64
|
+
],
|
65
|
+
ids=[
|
66
|
+
"No inputs => no run, empty input",
|
67
|
+
"bad input unit => no run, empty input",
|
68
|
+
"bad input no unit => no run, empty input",
|
69
|
+
"good fuel input => run",
|
70
|
+
"multiple good merg-able fuel inputs => run",
|
71
|
+
"multiple good distinct fuel inputs => run",
|
72
|
+
"multiple good fuel inputs with same prop=> run",
|
73
|
+
"multiple good fuel inputs with distinct prop=> run",
|
74
|
+
"good electric input => run",
|
75
|
+
"multiple good merg-able electric inputs => run",
|
76
|
+
"good fuel with input property",
|
77
|
+
"good fuel with no input property",
|
78
|
+
"good fuel in m^3",
|
79
|
+
"good nuclear fuel use indicator in kWh",
|
80
|
+
"bad indicator input in kg no property to convert to mj"
|
81
|
+
]
|
82
|
+
)
|
83
|
+
def test_should_run(inputs, expected, num_inputs):
|
84
|
+
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
85
|
+
cycle = json.load(f)
|
86
|
+
|
87
|
+
cycle['inputs'] = inputs
|
88
|
+
|
89
|
+
should_run, grouped_energy_terms = _should_run(cycle)
|
90
|
+
assert should_run is expected
|
91
|
+
assert len(grouped_energy_terms.keys()) == num_inputs
|
92
|
+
|
93
|
+
|
94
|
+
@patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
|
95
|
+
def test_run(*args):
|
96
|
+
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
97
|
+
cycle = json.load(f)
|
98
|
+
|
99
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
100
|
+
expected = json.load(f)
|
101
|
+
|
102
|
+
value = run(cycle)
|
103
|
+
assert value == expected
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import json
|
2
|
+
from unittest.mock import patch
|
3
|
+
|
4
|
+
from hestia_earth.models.cml2001Baseline import MODEL
|
5
|
+
from hestia_earth.models.cml2001Baseline.resourceUseEnergyDepletionInputsProduction import TERM_ID, run
|
6
|
+
from tests.utils import fixtures_path, fake_new_indicator, fake_load_impacts
|
7
|
+
|
8
|
+
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
9
|
+
utils_class_path = "hestia_earth.models.linkedImpactAssessment.utils"
|
10
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
11
|
+
|
12
|
+
|
13
|
+
@patch(f"{utils_class_path}.load_impacts", side_effect=fake_load_impacts)
|
14
|
+
@patch(f"{utils_class_path}._new_indicator", side_effect=fake_new_indicator)
|
15
|
+
def test_run(*args):
|
16
|
+
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
17
|
+
impact = json.load(f)
|
18
|
+
|
19
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
20
|
+
expected = json.load(f)
|
21
|
+
|
22
|
+
value = run(impact)
|
23
|
+
assert value == expected
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import json
|
2
|
+
from unittest.mock import patch
|
3
|
+
|
4
|
+
import pytest
|
5
|
+
|
6
|
+
from hestia_earth.models.cml2001Baseline.resourceUseMineralsAndMetalsDuringCycle import MODEL, TERM_ID, run, _should_run
|
7
|
+
from tests.utils import fixtures_path, fake_new_indicator
|
8
|
+
|
9
|
+
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
10
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
11
|
+
|
12
|
+
antimony = {"term": {"termType": "material", "@id": "antimony", "units": "kg"}, "value": [3]}
|
13
|
+
antimony_bad_unit = {"term": {"termType": "material", "@id": "antimony", "units": "boogiewoogiw"}, "value": [3]}
|
14
|
+
boron = {"term": {"termType": "soilAmendment", "@id": "boron", "units": "kg"}, "value": [3]}
|
15
|
+
tellurium = {"term": {"termType": "otherInorganicChemical", "@id": "CAS-13494-80-9", "units": "kg"}, "value": [30]}
|
16
|
+
|
17
|
+
|
18
|
+
@pytest.mark.parametrize(
|
19
|
+
"cycle_inputs, expected, num_inputs",
|
20
|
+
[
|
21
|
+
([], False, 0),
|
22
|
+
([antimony_bad_unit], False, 0),
|
23
|
+
([antimony], True, 1),
|
24
|
+
([antimony, antimony, antimony], True, 1),
|
25
|
+
([antimony, boron], True, 2),
|
26
|
+
([antimony, boron, tellurium], True, 3),
|
27
|
+
|
28
|
+
],
|
29
|
+
ids=[
|
30
|
+
"No inputs => no run, empty input",
|
31
|
+
"bad input => no run, empty input",
|
32
|
+
"good fuel input => run",
|
33
|
+
"multiple good merg-able material inputs => run",
|
34
|
+
"multiple good non merg-able material inputs => run",
|
35
|
+
"all termTypes inputs => run",
|
36
|
+
]
|
37
|
+
)
|
38
|
+
def test_should_run(cycle_inputs, expected, num_inputs):
|
39
|
+
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
40
|
+
cycle = json.load(f)
|
41
|
+
|
42
|
+
cycle['inputs'] = cycle_inputs
|
43
|
+
|
44
|
+
should_run, grouped_energy_terms = _should_run(cycle)
|
45
|
+
assert should_run is expected
|
46
|
+
assert len(grouped_energy_terms.keys()) == num_inputs
|
47
|
+
|
48
|
+
|
49
|
+
@patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
|
50
|
+
def test_run(*args):
|
51
|
+
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
52
|
+
cycle = json.load(f)
|
53
|
+
|
54
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
55
|
+
expected = json.load(f)
|
56
|
+
|
57
|
+
value = run(cycle)
|
58
|
+
assert value == expected
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import json
|
2
|
+
from unittest.mock import patch
|
3
|
+
|
4
|
+
from hestia_earth.models.cml2001Baseline import MODEL
|
5
|
+
from hestia_earth.models.cml2001Baseline.resourceUseMineralsAndMetalsInputsProduction import TERM_ID, run
|
6
|
+
from tests.utils import fixtures_path, fake_new_indicator, fake_load_impacts
|
7
|
+
|
8
|
+
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
9
|
+
utils_class_path = "hestia_earth.models.linkedImpactAssessment.utils"
|
10
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
11
|
+
|
12
|
+
|
13
|
+
@patch(f"{utils_class_path}.load_impacts", side_effect=fake_load_impacts)
|
14
|
+
@patch(f"{utils_class_path}._new_indicator", side_effect=fake_new_indicator)
|
15
|
+
def test_run(*args):
|
16
|
+
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
17
|
+
impact = json.load(f)
|
18
|
+
|
19
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
20
|
+
expected = json.load(f)
|
21
|
+
|
22
|
+
value = run(impact)
|
23
|
+
assert value == expected
|
@@ -0,0 +1,93 @@
|
|
1
|
+
import json
|
2
|
+
from unittest.mock import patch, Mock
|
3
|
+
|
4
|
+
from pytest import mark
|
5
|
+
|
6
|
+
from hestia_earth.models.environmentalFootprintV3_1 import MODEL_FOLDER
|
7
|
+
from hestia_earth.models.environmentalFootprintV3_1.environmentalFootprintSingleOverallScore import MODEL, TERM_ID, \
|
8
|
+
run, _should_run
|
9
|
+
from tests.utils import fixtures_path, fake_new_indicator
|
10
|
+
|
11
|
+
class_path = f"hestia_earth.models.{MODEL_FOLDER}.{TERM_ID}"
|
12
|
+
fixtures_folder = f"{fixtures_path}/{MODEL_FOLDER}/{TERM_ID}"
|
13
|
+
|
14
|
+
|
15
|
+
def fake_rounded_indicator(value: float):
|
16
|
+
indicator = fake_new_indicator(TERM_ID, MODEL)
|
17
|
+
indicator['value'] = round(value, 20)
|
18
|
+
return indicator
|
19
|
+
|
20
|
+
|
21
|
+
ozone_indicator = {"@type": "Indicator",
|
22
|
+
"term": {"@id": "ozoneDepletionPotential", "termType": "characterisedIndicator"},
|
23
|
+
"value": 0}
|
24
|
+
|
25
|
+
acid_indicator = {
|
26
|
+
"@type": "Indicator",
|
27
|
+
"term": {"@id": "terrestrialAcidificationPotentialAccumulatedExceedance", "termType": "characterisedIndicator"},
|
28
|
+
"value": 0.000420443840380047}
|
29
|
+
|
30
|
+
bad_indicator_id = {"@type": "Indicator",
|
31
|
+
"term": {"@id": "no_a_real_id", "termType": "characterisedIndicator"},
|
32
|
+
"value": 0.000420443840380047}
|
33
|
+
|
34
|
+
not_pef_indicator = {"@type": "Indicator",
|
35
|
+
"term": {"@id": "gwpStar", "termType": "characterisedIndicator"},
|
36
|
+
"value": 0.000420443840380047}
|
37
|
+
|
38
|
+
bad_indicator_no_val = {"@type": "Indicator",
|
39
|
+
"term": {"@id": "damageToHumanHealthParticulateMatterFormation",
|
40
|
+
"termType": "characterisedIndicator"}}
|
41
|
+
|
42
|
+
bad_indicator_bad_val = {"@type": "Indicator",
|
43
|
+
"term": {"@id": "damageToHumanHealthParticulateMatterFormation",
|
44
|
+
"termType": "characterisedIndicator"},
|
45
|
+
"value": None}
|
46
|
+
|
47
|
+
|
48
|
+
@mark.parametrize(
|
49
|
+
"impacts, expected, num_inputs",
|
50
|
+
[
|
51
|
+
([], False, 0),
|
52
|
+
([bad_indicator_id], False, 0),
|
53
|
+
([not_pef_indicator], False, 0),
|
54
|
+
([bad_indicator_no_val], False, 0),
|
55
|
+
([bad_indicator_bad_val], False, 0),
|
56
|
+
([ozone_indicator], True, 1),
|
57
|
+
([ozone_indicator, ozone_indicator], False, 2),
|
58
|
+
([ozone_indicator, acid_indicator], True, 2),
|
59
|
+
([bad_indicator_no_val, acid_indicator], False, 1)
|
60
|
+
],
|
61
|
+
ids=[
|
62
|
+
"No indicators => no run",
|
63
|
+
"bad_indicator_id => no run",
|
64
|
+
"not_pef_indicator => no run",
|
65
|
+
"bad_indicator_no_val => no run",
|
66
|
+
"bad_indicator_bad_val => no run",
|
67
|
+
"ozone_indicator => run",
|
68
|
+
"2 ozone_indicator => no run",
|
69
|
+
"2 good indicators => run",
|
70
|
+
"one bad one good indicator => no run",
|
71
|
+
]
|
72
|
+
)
|
73
|
+
def test_should_run(impacts, expected, num_inputs):
|
74
|
+
with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
|
75
|
+
impactassessment = json.load(f)
|
76
|
+
|
77
|
+
impactassessment['impacts'] = impacts
|
78
|
+
|
79
|
+
should_run, resources = _should_run(impactassessment)
|
80
|
+
assert should_run is expected
|
81
|
+
assert len(resources) == num_inputs
|
82
|
+
|
83
|
+
|
84
|
+
@patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
|
85
|
+
def test_run(_mocked_indicator: Mock, *args):
|
86
|
+
with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
|
87
|
+
impactassessment = json.load(f)
|
88
|
+
|
89
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
90
|
+
expected = json.load(f)
|
91
|
+
|
92
|
+
value = run(impactassessment)
|
93
|
+
assert value == expected
|
@@ -1,11 +1,12 @@
|
|
1
|
-
from unittest.mock import patch
|
2
1
|
import json
|
3
|
-
from
|
2
|
+
from unittest.mock import patch
|
4
3
|
|
5
|
-
from hestia_earth.models.
|
4
|
+
from hestia_earth.models.environmentalFootprintV3_1 import MODEL_FOLDER
|
5
|
+
from hestia_earth.models.environmentalFootprintV3_1.freshwaterEcotoxicityPotentialCtue import TERM_ID, run
|
6
|
+
from tests.utils import fixtures_path, fake_new_indicator
|
6
7
|
|
7
|
-
class_path = f"hestia_earth.models.{
|
8
|
-
fixtures_folder = f"{fixtures_path}/{
|
8
|
+
class_path = f"hestia_earth.models.{MODEL_FOLDER}.{TERM_ID}"
|
9
|
+
fixtures_folder = f"{fixtures_path}/{MODEL_FOLDER}/{TERM_ID}"
|
9
10
|
|
10
11
|
|
11
12
|
with open(f"{fixtures_path}/impact_assessment/emissions/impact-assessment.jsonld", encoding='utf-8') as f:
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import json
|
2
|
+
from unittest.mock import patch
|
3
|
+
|
4
|
+
from hestia_earth.models.environmentalFootprintV3_1 import MODEL_FOLDER
|
5
|
+
from hestia_earth.models.environmentalFootprintV3_1.marineEutrophicationPotential import MODEL, TERM_ID, run
|
6
|
+
from tests.utils import fixtures_path, fake_new_indicator
|
7
|
+
|
8
|
+
class_path = f"hestia_earth.models.{MODEL_FOLDER}.{TERM_ID}"
|
9
|
+
fixtures_folder = f"{fixtures_path}/{MODEL_FOLDER}/{TERM_ID}"
|
10
|
+
|
11
|
+
|
12
|
+
def fake_rounded_indicator(value: float):
|
13
|
+
indicator = fake_new_indicator(TERM_ID, MODEL)
|
14
|
+
indicator['value'] = round(value, 7)
|
15
|
+
return indicator
|
16
|
+
|
17
|
+
|
18
|
+
@patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
|
19
|
+
def test_run(*args):
|
20
|
+
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
21
|
+
impactassessment = json.load(f)
|
22
|
+
|
23
|
+
with open(f"{fixtures_folder}/region-world/result.jsonld", encoding='utf-8') as f:
|
24
|
+
expected = json.load(f)
|
25
|
+
|
26
|
+
value = run(impactassessment)
|
27
|
+
assert value == expected
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import json
|
2
|
+
import os
|
3
|
+
from unittest.mock import patch
|
4
|
+
|
5
|
+
from pytest import mark
|
6
|
+
|
7
|
+
from hestia_earth.models.environmentalFootprintV3_1 import MODEL_FOLDER
|
8
|
+
from hestia_earth.models.environmentalFootprintV3_1.scarcityWeightedWaterUse import MODEL, TERM_ID, run
|
9
|
+
from tests.utils import fixtures_path, fake_new_indicator
|
10
|
+
|
11
|
+
class_path = f"hestia_earth.models.{MODEL_FOLDER}.{TERM_ID}"
|
12
|
+
fixtures_folder = f"{fixtures_path}/{MODEL_FOLDER}/{TERM_ID}"
|
13
|
+
_folders = [d for d in os.listdir(fixtures_folder) if os.path.isdir(os.path.join(fixtures_folder, d))]
|
14
|
+
|
15
|
+
|
16
|
+
def fake_rounded_indicator(value: float):
|
17
|
+
indicator = fake_new_indicator(TERM_ID, MODEL)
|
18
|
+
indicator['value'] = round(value, 13)
|
19
|
+
return indicator
|
20
|
+
|
21
|
+
|
22
|
+
@mark.parametrize("folder", _folders)
|
23
|
+
@patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
|
24
|
+
def test_run(mock_indicator, folder):
|
25
|
+
with open(f"{fixtures_folder}/{folder}/impactassessment.jsonld", encoding='utf-8') as f:
|
26
|
+
impactassessment = json.load(f)
|
27
|
+
|
28
|
+
with open(f"{fixtures_folder}/{folder}/result.jsonld", encoding='utf-8') as f:
|
29
|
+
expected = json.load(f)
|
30
|
+
|
31
|
+
value = run(impactassessment)
|
32
|
+
assert value == expected, folder
|
@@ -3,12 +3,13 @@ from unittest.mock import patch
|
|
3
3
|
|
4
4
|
import pytest
|
5
5
|
|
6
|
-
from hestia_earth.models.
|
6
|
+
from hestia_earth.models.environmentalFootprintV3_1 import MODEL_FOLDER
|
7
|
+
from hestia_earth.models.environmentalFootprintV3_1.soilQualityIndexLandOccupation import TERM_ID, run, \
|
7
8
|
_should_run
|
8
9
|
from tests.utils import fixtures_path, fake_new_indicator
|
9
10
|
|
10
|
-
class_path = f"hestia_earth.models.{
|
11
|
-
fixtures_folder = f"{fixtures_path}/{
|
11
|
+
class_path = f"hestia_earth.models.{MODEL_FOLDER}.{TERM_ID}"
|
12
|
+
fixtures_folder = f"{fixtures_path}/{MODEL_FOLDER}/{TERM_ID}"
|
12
13
|
|
13
14
|
crop_land = {"@id": "cropland", "termType": "landCover"}
|
14
15
|
sea_land_cover = {"@id": "seaOrOcean", "termType": "landCover"}
|