hestia-earth-models 0.64.6__py3-none-any.whl → 0.64.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of hestia-earth-models might be problematic. Click here for more details.

Files changed (37) hide show
  1. hestia_earth/models/cycle/animal/milkYield.py +10 -22
  2. hestia_earth/models/cycle/unknownPreSeasonWaterRegime.py +0 -1
  3. hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandOccupation.py +25 -24
  4. hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandTransformation.py +182 -0
  5. hestia_earth/models/environmentalFootprintV3/soilQualityIndexTotalLandUseEffects.py +66 -0
  6. hestia_earth/models/environmentalFootprintV3/utils.py +1 -1
  7. hestia_earth/models/hyde32/utils.py +4 -0
  8. hestia_earth/models/ipcc2019/animal/pastureGrass.py +3 -1
  9. hestia_earth/models/ipcc2019/co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +191 -0
  10. hestia_earth/models/ipcc2019/co2ToAirBelowGroundBiomassStockChangeLandUseChange.py +204 -0
  11. hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +255 -35
  12. hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +63 -149
  13. hestia_earth/models/ipcc2019/pastureGrass.py +3 -1
  14. hestia_earth/models/mocking/search-results.json +337 -319
  15. hestia_earth/models/pooreNemecek2018/landOccupationDuringCycle.py +12 -8
  16. hestia_earth/models/site/management.py +3 -5
  17. hestia_earth/models/transformation/input/excreta.py +9 -13
  18. hestia_earth/models/utils/input.py +5 -2
  19. hestia_earth/models/utils/site.py +4 -2
  20. hestia_earth/models/version.py +1 -1
  21. {hestia_earth_models-0.64.6.dist-info → hestia_earth_models-0.64.8.dist-info}/METADATA +2 -2
  22. {hestia_earth_models-0.64.6.dist-info → hestia_earth_models-0.64.8.dist-info}/RECORD +37 -29
  23. tests/models/cycle/animal/test_milkYield.py +1 -14
  24. tests/models/environmentalFootprintV3/test_freshwaterEcotoxicityPotentialCtue.py +4 -2
  25. tests/models/environmentalFootprintV3/test_soilQualityIndexLandOccupation.py +16 -24
  26. tests/models/environmentalFootprintV3/test_soilQualityIndexLandTransformation.py +113 -0
  27. tests/models/environmentalFootprintV3/test_soilQualityIndexTotalLandUseEffects.py +50 -0
  28. tests/models/ipcc2019/test_co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +83 -0
  29. tests/models/ipcc2019/test_co2ToAirBelowGroundBiomassStockChangeLandUseChange.py +83 -0
  30. tests/models/ipcc2019/test_co2ToAirCarbonStockChange_utils.py +6 -6
  31. tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +5 -4
  32. tests/models/pooreNemecek2018/test_landOccupationDuringCycle.py +4 -1
  33. tests/models/site/test_management.py +4 -1
  34. tests/models/utils/test_input.py +65 -1
  35. {hestia_earth_models-0.64.6.dist-info → hestia_earth_models-0.64.8.dist-info}/LICENSE +0 -0
  36. {hestia_earth_models-0.64.6.dist-info → hestia_earth_models-0.64.8.dist-info}/WHEEL +0 -0
  37. {hestia_earth_models-0.64.6.dist-info → hestia_earth_models-0.64.8.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,113 @@
1
+ import json
2
+ from unittest.mock import patch
3
+
4
+ from hestia_earth.models.environmentalFootprintV3.soilQualityIndexLandTransformation import MODEL, TERM_ID, run, \
5
+ _should_run
6
+ from tests.utils import fixtures_path, fake_new_indicator
7
+
8
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
9
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{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
+ def test_should_run_ocean(*args):
19
+ """
20
+ Should not run if a LandCover has no CF (ocean)
21
+ """
22
+ with open(f"{fixtures_folder}/bad-sites/site-LandCover-has-no-CF.jsonld", encoding='utf-8') as f:
23
+ site = json.load(f)
24
+
25
+ should_run, *args = _should_run(site)
26
+ assert should_run is False
27
+
28
+
29
+ def test_should_run_no_management_entries(*args):
30
+ """
31
+ no management => no run
32
+ """
33
+ with open(f"{fixtures_folder}/bad-sites/site-no-management.jsonld", encoding='utf-8') as f:
34
+ site = json.load(f)
35
+
36
+ should_run, *args = _should_run(site)
37
+ assert should_run is False
38
+
39
+
40
+ def test_should_run_no_sites(*args):
41
+ """
42
+ impact assessment with no site => no run
43
+ """
44
+ with open(f"{fixtures_path}/impact_assessment/emissions/impact-assessment.jsonld", encoding='utf-8') as f:
45
+ site = json.load(f)
46
+
47
+ should_run, *args = _should_run(site)
48
+ assert should_run is False
49
+
50
+
51
+ def test_should_run_no_transformation(*args):
52
+ """
53
+ 1 management with no transformation => no run
54
+ """
55
+ with open(f"{fixtures_folder}/bad-sites/site-no-transformations.jsonld", encoding='utf-8') as f:
56
+ site = json.load(f)
57
+
58
+ should_run, *args = _should_run(site)
59
+ assert should_run is False
60
+
61
+
62
+ @patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
63
+ def test_run_in_cycle(*args):
64
+ with open(f"{fixtures_folder}/Italy/site-italy-inside-cycle.jsonld", encoding='utf-8') as f:
65
+ site = json.load(f)
66
+
67
+ with open(f"{fixtures_folder}/Italy/result.jsonld", encoding='utf-8') as f:
68
+ expected = json.load(f)
69
+
70
+ value = run(site)
71
+ assert value == expected
72
+
73
+
74
+ @patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
75
+ def test_run_other_sites(*args):
76
+ with open(f"{fixtures_folder}/Italy/site-italy-otherSites.jsonld", encoding='utf-8') as f:
77
+ site = json.load(f)
78
+
79
+ with open(f"{fixtures_folder}/Italy/result-otherSites.jsonld", encoding='utf-8') as f:
80
+ expected = json.load(f)
81
+
82
+ value = run(site)
83
+ assert value == expected
84
+
85
+
86
+ @patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
87
+ def test_run_with_region(*args):
88
+ """
89
+ When given valid sub-region or country not in the lookup file should default to 'region-world'
90
+ """
91
+ with open(f"{fixtures_folder}/region-world/region-europe.jsonld", encoding='utf-8') as f:
92
+ site = json.load(f)
93
+
94
+ with open(f"{fixtures_folder}/region-world/result-default-region-world.jsonld", encoding='utf-8') as f:
95
+ expected = json.load(f)
96
+
97
+ value = run(site)
98
+ assert value == expected
99
+
100
+
101
+ @patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
102
+ def test_run_with_no_region(*args):
103
+ """
104
+ When no location is specified, defaults to region world.
105
+ """
106
+ with open(f"{fixtures_folder}/region-world/no-region.jsonld", encoding='utf-8') as f:
107
+ site = json.load(f)
108
+
109
+ with open(f"{fixtures_folder}/region-world/result-default-region-world.jsonld", encoding='utf-8') as f:
110
+ expected = json.load(f)
111
+
112
+ value = run(site)
113
+ assert value == expected
@@ -0,0 +1,50 @@
1
+ import json
2
+ from unittest.mock import patch
3
+
4
+ from pytest import mark
5
+
6
+ from hestia_earth.models.environmentalFootprintV3.soilQualityIndexTotalLandUseEffects import MODEL, TERM_ID, run, \
7
+ _should_run
8
+ from tests.utils import fixtures_path, fake_new_indicator
9
+
10
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
11
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
12
+
13
+ transform_indicator = {'term': {'@id': 'soilQualityIndexLandTransformation'}, 'value': 10}
14
+ occupation_indicator = {'term': {'@id': 'soilQualityIndexLandOccupation'}, 'value': 10}
15
+ missing_value_indicator = {'term': {'@id': 'soilQualityIndexLandOccupation'}}
16
+ bad_value_indicator = {'term': {'@id': 'soilQualityIndexLandOccupation'}, 'value': "42"}
17
+
18
+
19
+ @mark.parametrize(
20
+ "emissions_resource_use, expected",
21
+ [
22
+ ([], False),
23
+ ([transform_indicator], False),
24
+ ([transform_indicator, transform_indicator], False),
25
+ ([transform_indicator, missing_value_indicator], False),
26
+ ([transform_indicator, bad_value_indicator], False),
27
+ ([transform_indicator, occupation_indicator], True),
28
+ ],
29
+ ids=["Empty", "missing entry", "duplicate entry", "no value in entry", "bad value in entry", "correct assessment"]
30
+ )
31
+ def test_should_run(emissions_resource_use, expected):
32
+ with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
33
+ impactassessment = json.load(f)
34
+
35
+ impactassessment['emissionsResourceUse'] = emissions_resource_use
36
+
37
+ should_run, *args = _should_run(impactassessment)
38
+ assert should_run is expected
39
+
40
+
41
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
42
+ def test_run(*args):
43
+ with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
44
+ impactassessment = json.load(f)
45
+
46
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
47
+ expected = json.load(f)
48
+
49
+ value = run(impactassessment)
50
+ assert value == expected
@@ -0,0 +1,83 @@
1
+ from functools import reduce
2
+ import json
3
+ from os.path import isfile
4
+ from pytest import mark
5
+ from unittest.mock import patch
6
+
7
+ from hestia_earth.models.ipcc2019.co2ToAirAboveGroundBiomassStockChangeLandUseChange import MODEL, run, TERM_ID
8
+
9
+ from tests.utils import fake_new_emission, fixtures_path
10
+
11
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
12
+ utils_path = f"hestia_earth.models.{MODEL}.co2ToAirCarbonStockChange_utils"
13
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
14
+
15
+ RUN_SCENARIOS = [
16
+ ("no-overlapping-cycles", 3),
17
+ ("overlapping-cycles", 4),
18
+ ("complex-overlapping-cycles", 5),
19
+ ("missing-measurement-dates", 3),
20
+ ("no-biomass-measurements", 1), # Closes issue #700
21
+ ("non-consecutive-biomass-measurements", 1), # Closes issue #827
22
+ ("multiple-method-classifications", 5), # Closes issue #764
23
+ ("non-soil-based-gohac-system", 3), # Closes issue #848
24
+ ("soil-based-gohac-system", 3) # Closes issue #848
25
+ ]
26
+ """List of (subfolder: str, num_cycles: int)."""
27
+
28
+
29
+ def _load_fixture(path: str, default=None):
30
+ if isfile(path):
31
+ with open(path, encoding="utf-8") as f:
32
+ return json.load(f)
33
+ return default
34
+
35
+
36
+ RUN_PARAMS = reduce(
37
+ lambda params, scenario: params + [(scenario[0], scenario[1], i) for i in range(scenario[1])],
38
+ RUN_SCENARIOS,
39
+ list()
40
+ )
41
+ """List of (subfolder: str, num_cycles: int, cycle_index: int)."""
42
+
43
+ RUN_IDS = [f"{param[0]}, cycle{param[2]}" for param in RUN_PARAMS]
44
+
45
+
46
+ @mark.parametrize("subfolder, num_cycles, cycle_index", RUN_PARAMS, ids=RUN_IDS)
47
+ @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
48
+ @patch(f"{utils_path}.related_cycles")
49
+ @patch(f"{utils_path}._get_site") # TODO: rationalise order of patches
50
+ def test_run(_get_site_mock, related_cycles_mock, _new_emission_mock, subfolder, num_cycles, cycle_index):
51
+ """
52
+ Test `run` function for each cycle in each scenario.
53
+ """
54
+ site = _load_fixture(f"{fixtures_folder}/{subfolder}/site.jsonld")
55
+ cycle = _load_fixture(f"{fixtures_folder}/{subfolder}/cycle{cycle_index}.jsonld")
56
+ expected = _load_fixture(f"{fixtures_folder}/{subfolder}/result{cycle_index}.jsonld", default=[])
57
+
58
+ cycles = [
59
+ _load_fixture(f"{fixtures_folder}/{subfolder}/cycle{i}.jsonld") for i in range(num_cycles)
60
+ ]
61
+
62
+ _get_site_mock.return_value = site
63
+ related_cycles_mock.return_value = cycles
64
+
65
+ result = run(cycle)
66
+ assert result == expected
67
+
68
+
69
+ @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
70
+ @patch(f"{utils_path}.related_cycles")
71
+ @patch(f"{utils_path}._get_site") # TODO: rationalise order of patches
72
+ def test_run_empty(_get_site_mock, related_cycles_mock, _new_emission_mock):
73
+ """
74
+ Test `run` function for each cycle in each scenario.
75
+ """
76
+ CYCLE = {}
77
+ EXPECTED = []
78
+
79
+ _get_site_mock.return_value = {}
80
+ related_cycles_mock.return_value = [CYCLE]
81
+
82
+ result = run(CYCLE)
83
+ assert result == EXPECTED
@@ -0,0 +1,83 @@
1
+ from functools import reduce
2
+ import json
3
+ from os.path import isfile
4
+ from pytest import mark
5
+ from unittest.mock import patch
6
+
7
+ from hestia_earth.models.ipcc2019.co2ToAirBelowGroundBiomassStockChangeLandUseChange import MODEL, run, TERM_ID
8
+
9
+ from tests.utils import fake_new_emission, fixtures_path
10
+
11
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
12
+ utils_path = f"hestia_earth.models.{MODEL}.co2ToAirCarbonStockChange_utils"
13
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
14
+
15
+ RUN_SCENARIOS = [
16
+ ("no-overlapping-cycles", 3),
17
+ ("overlapping-cycles", 4),
18
+ ("complex-overlapping-cycles", 5),
19
+ ("missing-measurement-dates", 3),
20
+ ("no-biomass-measurements", 1), # Closes issue #700
21
+ ("non-consecutive-biomass-measurements", 1), # Closes issue #827
22
+ ("multiple-method-classifications", 5), # Closes issue #764
23
+ ("non-soil-based-gohac-system", 3), # Closes issue #848
24
+ ("soil-based-gohac-system", 3) # Closes issue #848
25
+ ]
26
+ """List of (subfolder: str, num_cycles: int)."""
27
+
28
+
29
+ def _load_fixture(path: str, default=None):
30
+ if isfile(path):
31
+ with open(path, encoding="utf-8") as f:
32
+ return json.load(f)
33
+ return default
34
+
35
+
36
+ RUN_PARAMS = reduce(
37
+ lambda params, scenario: params + [(scenario[0], scenario[1], i) for i in range(scenario[1])],
38
+ RUN_SCENARIOS,
39
+ list()
40
+ )
41
+ """List of (subfolder: str, num_cycles: int, cycle_index: int)."""
42
+
43
+ RUN_IDS = [f"{param[0]}, cycle{param[2]}" for param in RUN_PARAMS]
44
+
45
+
46
+ @mark.parametrize("subfolder, num_cycles, cycle_index", RUN_PARAMS, ids=RUN_IDS)
47
+ @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
48
+ @patch(f"{utils_path}.related_cycles")
49
+ @patch(f"{utils_path}._get_site")
50
+ def test_run(_get_site_mock, related_cycles_mock, _new_emission_mock, subfolder, num_cycles, cycle_index):
51
+ """
52
+ Test `run` function for each cycle in each scenario.
53
+ """
54
+ site = _load_fixture(f"{fixtures_folder}/{subfolder}/site.jsonld")
55
+ cycle = _load_fixture(f"{fixtures_folder}/{subfolder}/cycle{cycle_index}.jsonld")
56
+ expected = _load_fixture(f"{fixtures_folder}/{subfolder}/result{cycle_index}.jsonld", default=[])
57
+
58
+ cycles = [
59
+ _load_fixture(f"{fixtures_folder}/{subfolder}/cycle{i}.jsonld") for i in range(num_cycles)
60
+ ]
61
+
62
+ _get_site_mock.return_value = site
63
+ related_cycles_mock.return_value = cycles
64
+
65
+ result = run(cycle)
66
+ assert result == expected
67
+
68
+
69
+ @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
70
+ @patch(f"{utils_path}.related_cycles")
71
+ @patch(f"{utils_path}._get_site")
72
+ def test_run_empty(_get_site_mock, related_cycles_mock, _new_emission_mock):
73
+ """
74
+ Test `run` function for each cycle in each scenario.
75
+ """
76
+ CYCLE = {}
77
+ EXPECTED = []
78
+
79
+ _get_site_mock.return_value = {}
80
+ related_cycles_mock.return_value = [CYCLE]
81
+
82
+ result = run(CYCLE)
83
+ assert result == EXPECTED
@@ -1,8 +1,8 @@
1
1
  from hestia_earth.schema import EmissionMethodTier, MeasurementMethodClassification
2
2
 
3
3
  from hestia_earth.models.ipcc2019.co2ToAirCarbonStockChange_utils import (
4
- add_carbon_stock_change_emissions, calc_carbon_stock_change, calc_carbon_stock_change_emission, _convert_c_to_co2,
5
- lerp_carbon_stocks, CarbonStock, CarbonStockChange, CarbonStockChangeEmission
4
+ _add_carbon_stock_change_emissions, _calc_carbon_stock_change, _calc_carbon_stock_change_emission,
5
+ _convert_c_to_co2, _lerp_carbon_stocks, CarbonStock, CarbonStockChange, CarbonStockChangeEmission
6
6
  )
7
7
 
8
8
 
@@ -20,7 +20,7 @@ def test_lerp_carbon_stocks():
20
20
  21000, "2001-12-31", MeasurementMethodClassification.ON_SITE_PHYSICAL_MEASUREMENT
21
21
  )
22
22
 
23
- result = lerp_carbon_stocks(START, END, TARGET_DATE)
23
+ result = _lerp_carbon_stocks(START, END, TARGET_DATE)
24
24
  assert result == EXPECTED
25
25
 
26
26
 
@@ -29,7 +29,7 @@ def test_calc_carbon_stock_change():
29
29
  END = CarbonStock(21000, "2001", MeasurementMethodClassification.TIER_1_MODEL)
30
30
  EXPECTED = CarbonStockChange(1000, "2000", "2001", MeasurementMethodClassification.TIER_1_MODEL)
31
31
 
32
- result = calc_carbon_stock_change(START, END)
32
+ result = _calc_carbon_stock_change(START, END)
33
33
  assert result == EXPECTED
34
34
 
35
35
 
@@ -37,7 +37,7 @@ def test_calc_carbon_stock_change_emission():
37
37
  SOC_STOCK_CHANGE = CarbonStockChange(-1000, "2000", "2001", MeasurementMethodClassification.TIER_1_MODEL)
38
38
  EXPECTED = CarbonStockChangeEmission(3663.836163836164, "2000", "2001", EmissionMethodTier.TIER_1)
39
39
 
40
- result = calc_carbon_stock_change_emission(SOC_STOCK_CHANGE)
40
+ result = _calc_carbon_stock_change_emission(SOC_STOCK_CHANGE)
41
41
  assert result == EXPECTED
42
42
 
43
43
 
@@ -46,5 +46,5 @@ def test_add_carbon_stock_change_emissions():
46
46
  EMISSION_2 = CarbonStockChangeEmission(2000, "2001", "2002", EmissionMethodTier.TIER_1)
47
47
  EXPECTED = CarbonStockChangeEmission(5000, "2000", "2002", EmissionMethodTier.TIER_1)
48
48
 
49
- result = add_carbon_stock_change_emissions(EMISSION_1, EMISSION_2)
49
+ result = _add_carbon_stock_change_emissions(EMISSION_1, EMISSION_2)
50
50
  assert result == EXPECTED
@@ -9,6 +9,7 @@ from hestia_earth.models.ipcc2019.co2ToAirSoilOrganicCarbonStockChangeManagement
9
9
  from tests.utils import fake_new_emission, fixtures_path
10
10
 
11
11
  class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
12
+ utils_path = f"hestia_earth.models.{MODEL}.co2ToAirCarbonStockChange_utils"
12
13
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
13
14
 
14
15
  RUN_SCENARIOS = [
@@ -44,8 +45,8 @@ RUN_IDS = [f"{param[0]}, cycle{param[2]}" for param in RUN_PARAMS]
44
45
 
45
46
  @mark.parametrize("subfolder, num_cycles, cycle_index", RUN_PARAMS, ids=RUN_IDS)
46
47
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
47
- @patch(f"{class_path}.related_cycles")
48
- @patch(f"{class_path}._get_site")
48
+ @patch(f"{utils_path}.related_cycles")
49
+ @patch(f"{utils_path}._get_site")
49
50
  def test_run(_get_site_mock, related_cycles_mock, _new_emission_mock, subfolder, num_cycles, cycle_index):
50
51
  """
51
52
  Test `run` function for each cycle in each scenario.
@@ -66,8 +67,8 @@ def test_run(_get_site_mock, related_cycles_mock, _new_emission_mock, subfolder,
66
67
 
67
68
 
68
69
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
69
- @patch(f"{class_path}.related_cycles")
70
- @patch(f"{class_path}._get_site")
70
+ @patch(f"{utils_path}.related_cycles")
71
+ @patch(f"{utils_path}._get_site")
71
72
  def test_run_empty(_get_site_mock, related_cycles_mock, _new_emission_mock):
72
73
  """
73
74
  Test `run` function for each cycle in each scenario.
@@ -9,8 +9,9 @@ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
9
9
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
10
 
11
11
 
12
+ @patch(f"{class_path}.get_land_cover_term_id", return_value='cropland')
12
13
  @patch(f"{class_path}.land_occupation_per_kg", return_value=None)
13
- def test_should_run(mock_land_occupation):
14
+ def test_should_run(mock_land_occupation, *args):
14
15
  # with a cycle and functionalUnit = 1 ha => no run
15
16
  impact = {'cycle': {'functionalUnit': CycleFunctionalUnit._1_HA.value}}
16
17
  should_run, *args = _should_run(impact)
@@ -22,6 +23,7 @@ def test_should_run(mock_land_occupation):
22
23
  assert should_run is True
23
24
 
24
25
 
26
+ @patch(f"{class_path}.get_land_cover_term_id", return_value='cropland')
25
27
  @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
26
28
  def test_run(*args):
27
29
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -34,6 +36,7 @@ def test_run(*args):
34
36
  assert value == expected
35
37
 
36
38
 
39
+ @patch(f"{class_path}.get_land_cover_term_id", return_value='cropland')
37
40
  @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
38
41
  def test_run_with_plantation(*args):
39
42
  with open(f"{fixtures_folder}/with-orchard-crop/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -25,7 +25,10 @@ TERM_BY_ID = {
25
25
  }
26
26
  }
27
27
 
28
- LAND_COVER_TERM_BY_SITE_TYPE = {SiteSiteType.ANIMAL_HOUSING.value: "animalHousing"}
28
+ LAND_COVER_TERM_BY_SITE_TYPE = {
29
+ SiteSiteType.ANIMAL_HOUSING.value: "animalHousing",
30
+ SiteSiteType.CROPLAND.value: "cropland"
31
+ }
29
32
 
30
33
 
31
34
  def lookup_side_effect(*args, **kwargs):
@@ -1,7 +1,9 @@
1
+ import pytest
1
2
  from unittest.mock import patch
3
+ from hestia_earth.schema import TermTermType
2
4
  from tests.utils import TERM
3
5
 
4
- from hestia_earth.models.utils.input import _new_input
6
+ from hestia_earth.models.utils.input import _new_input, get_feed_inputs
5
7
 
6
8
  class_path = 'hestia_earth.models.utils.input'
7
9
 
@@ -22,3 +24,65 @@ def test_new_input(*args):
22
24
  '@type': 'Input',
23
25
  'term': TERM
24
26
  }
27
+
28
+
29
+ @pytest.mark.parametrize(
30
+ 'test_name,cycle,expected_input_length',
31
+ [
32
+ (
33
+ 'no inputs',
34
+ {},
35
+ 0
36
+ ),
37
+ (
38
+ 'with crop feed',
39
+ {
40
+ 'inputs': [{
41
+ 'term': {'units': 'kg', 'termType': TermTermType.CROP.value, '@id': 'wheatGrain'},
42
+ 'isAnimalFeed': True,
43
+ 'value': [10]
44
+ }]
45
+ },
46
+ 1
47
+ ),
48
+ (
49
+ 'with crop no feed',
50
+ {
51
+ 'inputs': [{
52
+ 'term': {'units': 'kg', 'termType': TermTermType.CROP.value, '@id': 'wheatGrain'},
53
+ 'isAnimalFeed': False,
54
+ 'value': [10]
55
+ }]
56
+ },
57
+ 0
58
+ ),
59
+ (
60
+ 'with feed food additive and energy content',
61
+ {
62
+ 'inputs': [{
63
+ 'term': {
64
+ 'units': 'kg', 'termType': TermTermType.FEEDFOODADDITIVE.value, '@id': 'aminoAcidsUnspecified'
65
+ },
66
+ 'isAnimalFeed': True,
67
+ 'value': [10]
68
+ }]
69
+ },
70
+ 1
71
+ ),
72
+ (
73
+ 'with feed food additive not energy content',
74
+ {
75
+ 'inputs': [{
76
+ 'term': {
77
+ 'units': 'kg', 'termType': TermTermType.FEEDFOODADDITIVE.value, '@id': 'premixUnspecified'
78
+ },
79
+ 'isAnimalFeed': True,
80
+ 'value': [10]
81
+ }]
82
+ },
83
+ 0
84
+ ),
85
+ ]
86
+ )
87
+ def test_get_feed_inputs(test_name, cycle, expected_input_length):
88
+ assert len(get_feed_inputs(cycle)) == expected_input_length, test_name