hestia-earth-models 0.59.7__py3-none-any.whl → 0.60.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.

Potentially problematic release.


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

Files changed (39) hide show
  1. hestia_earth/models/cache_sites.py +4 -2
  2. hestia_earth/models/ipcc2019/animal/__init__.py +0 -0
  3. hestia_earth/models/ipcc2019/animal/pastureGrass.py +298 -0
  4. hestia_earth/models/ipcc2019/{co2ToAirSoilCarbonStockChangeManagementChange.py → co2ToAirSoilOrganicCarbonStockChangeManagementChange.py} +2 -2
  5. hestia_earth/models/ipcc2019/pastureGrass.py +73 -447
  6. hestia_earth/models/ipcc2019/pastureGrass_utils.py +415 -0
  7. hestia_earth/models/mocking/search-results.json +215 -207
  8. hestia_earth/models/site/pre_checks/cache_geospatialDatabase.py +14 -2
  9. hestia_earth/models/utils/completeness.py +17 -14
  10. hestia_earth/models/utils/feedipedia.py +23 -23
  11. hestia_earth/models/utils/property.py +3 -1
  12. hestia_earth/models/version.py +1 -1
  13. {hestia_earth_models-0.59.7.dist-info → hestia_earth_models-0.60.0.dist-info}/LICENSE +1 -1
  14. {hestia_earth_models-0.59.7.dist-info → hestia_earth_models-0.60.0.dist-info}/METADATA +1 -1
  15. {hestia_earth_models-0.59.7.dist-info → hestia_earth_models-0.60.0.dist-info}/RECORD +39 -34
  16. tests/models/cycle/animal/input/test_properties.py +3 -1
  17. tests/models/cycle/animal/test_properties.py +4 -2
  18. tests/models/cycle/input/test_properties.py +3 -1
  19. tests/models/cycle/product/test_properties.py +2 -1
  20. tests/models/cycle/test_coldCarcassWeightPerHead.py +1 -0
  21. tests/models/cycle/test_coldDressedCarcassWeightPerHead.py +1 -0
  22. tests/models/cycle/test_energyContentLowerHeatingValue.py +1 -0
  23. tests/models/cycle/test_feedConversionRatio.py +10 -0
  24. tests/models/cycle/test_readyToCookWeightPerHead.py +1 -0
  25. tests/models/ipcc2006/test_n2OToAirCropResidueDecompositionDirect.py +4 -1
  26. tests/models/ipcc2019/animal/__init__.py +0 -0
  27. tests/models/ipcc2019/animal/test_pastureGrass.py +45 -0
  28. tests/models/ipcc2019/test_ch4ToAirEntericFermentation.py +32 -8
  29. tests/models/ipcc2019/{test_co2ToAirSoilCarbonStockChangeManagementChange.py → test_co2ToAirSoilOrganicCarbonStockChangeManagementChange.py} +1 -1
  30. tests/models/ipcc2019/test_n2OToAirCropResidueDecompositionDirect.py +6 -1
  31. tests/models/ipcc2019/test_n2OToAirInorganicFertiliserDirect.py +6 -1
  32. tests/models/ipcc2019/test_n2OToAirOrganicFertiliserDirect.py +6 -1
  33. tests/models/ipcc2019/test_pastureGrass.py +32 -8
  34. tests/models/pooreNemecek2018/test_excretaKgN.py +5 -0
  35. tests/models/pooreNemecek2018/test_excretaKgVs.py +5 -0
  36. tests/models/pooreNemecek2018/test_no3ToGroundwaterSoilFlux.py +1 -0
  37. tests/models/test_cache_sites.py +22 -7
  38. {hestia_earth_models-0.59.7.dist-info → hestia_earth_models-0.60.0.dist-info}/WHEEL +0 -0
  39. {hestia_earth_models-0.59.7.dist-info → hestia_earth_models-0.60.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,45 @@
1
+ from unittest.mock import patch
2
+ import json
3
+ from tests.utils import fixtures_path, fake_new_input
4
+
5
+ from tests.models.ipcc2019.test_pastureGrass import MILK_YIELD_TERMS, WOOL_TERMS, TERMS_BY_ID
6
+ from hestia_earth.models.ipcc2019.animal.pastureGrass import MODEL, MODEL_KEY, run
7
+
8
+ class_path = f"hestia_earth.models.{MODEL}.{MODEL_KEY.replace('/', '.')}"
9
+ class_path_utils = f"hestia_earth.models.{MODEL}.pastureGrass_utils"
10
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{MODEL_KEY}"
11
+
12
+
13
+ def fake_download_hestia(term_id: str, *args): return TERMS_BY_ID[term_id]
14
+
15
+
16
+ @patch(f"{class_path_utils}.download_hestia", side_effect=fake_download_hestia)
17
+ @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
18
+ @patch(f"{class_path}.get_wool_terms", return_value=WOOL_TERMS)
19
+ @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=MILK_YIELD_TERMS)
20
+ @patch(f"{class_path}._new_input", side_effect=fake_new_input)
21
+ def test_run_with_feed(*args):
22
+ with open(f"{fixtures_folder}/with-feed/cycle.jsonld", encoding='utf-8') as f:
23
+ cycle = json.load(f)
24
+
25
+ with open(f"{fixtures_folder}/with-feed/result.jsonld", encoding='utf-8') as f:
26
+ expected = json.load(f)
27
+
28
+ value = run(cycle)
29
+ assert value == expected
30
+
31
+
32
+ @patch(f"{class_path_utils}.download_hestia", side_effect=fake_download_hestia)
33
+ @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
34
+ @patch(f"{class_path}.get_wool_terms", return_value=WOOL_TERMS)
35
+ @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=MILK_YIELD_TERMS)
36
+ @patch(f"{class_path}._new_input", side_effect=fake_new_input)
37
+ def test_run_with_goats(*args):
38
+ with open(f"{fixtures_folder}/with-goats/cycle.jsonld", encoding='utf-8') as f:
39
+ cycle = json.load(f)
40
+
41
+ with open(f"{fixtures_folder}/with-goats/result.jsonld", encoding='utf-8') as f:
42
+ expected = json.load(f)
43
+
44
+ value = run(cycle)
45
+ assert value == expected
@@ -7,7 +7,18 @@ from hestia_earth.models.ipcc2019.ch4ToAirEntericFermentation import MODEL, TERM
7
7
  class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
9
 
10
+ TERMS_BY_ID = {
11
+ 'energyContentHigherHeatingValue': {'units': 'MJ / kg'},
12
+ 'energyDigestibilityRuminants': {'units': '%'},
13
+ 'energyDigestibilityPoultry': {'units': '%'},
14
+ 'neutralDetergentFibreContent': {'units': '%'}
15
+ }
10
16
 
17
+
18
+ def fake_download_hestia(term_id: str, *args): return TERMS_BY_ID[term_id]
19
+
20
+
21
+ @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
11
22
  @patch(f"{class_path}.get_default_digestibility", return_value=70)
12
23
  @patch(f"{class_path}.find_primary_product", return_value={'term': {'@id': 'pig'}})
13
24
  @patch(f"{class_path}._get_lookup_value", return_value=0)
@@ -41,6 +52,8 @@ def test_should_run(mock_feed, mock_lookup_value, *args):
41
52
  assert should_run is True
42
53
 
43
54
 
55
+ @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
56
+ @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
44
57
  # patch get_node_property to read value from lookups only
45
58
  @patch('hestia_earth.models.utils.property.get_node_property', return_value=None)
46
59
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
@@ -55,6 +68,8 @@ def test_run(*args):
55
68
  assert result == expected
56
69
 
57
70
 
71
+ @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
72
+ @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
58
73
  # patch get_node_property to read value from lookups only
59
74
  @patch('hestia_earth.models.utils.property.get_node_property', return_value=None)
60
75
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
@@ -70,9 +85,9 @@ def test_run_dairy(*args):
70
85
 
71
86
 
72
87
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=['milkYieldPerBuffaloRaw'])
88
+ @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
73
89
  # patch get_node_property to read value from lookups only
74
90
  @patch('hestia_earth.models.utils.property.get_node_property', return_value={})
75
- @patch('hestia_earth.models.utils.property.download_hestia', return_value={})
76
91
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
77
92
  def test_run_with_milkYield(*args):
78
93
  with open(f"{fixtures_folder}/with-milkYield/cycle.jsonld", encoding="utf-8") as f:
@@ -85,9 +100,10 @@ def test_run_with_milkYield(*args):
85
100
  assert result == expected
86
101
 
87
102
 
103
+ @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
104
+ @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
88
105
  # patch get_node_property to read value from lookups only
89
106
  @patch('hestia_earth.models.utils.property.get_node_property', return_value={})
90
- @patch('hestia_earth.models.utils.property.download_hestia', return_value={})
91
107
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
92
108
  def test_run_non_dairy(*args):
93
109
  with open(f"{fixtures_folder}/non-dairy-buffalo-cows/cycle.jsonld", encoding="utf-8") as f:
@@ -100,9 +116,10 @@ def test_run_non_dairy(*args):
100
116
  assert result == expected
101
117
 
102
118
 
119
+ @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
120
+ @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
103
121
  # patch get_node_property to read value from lookups only
104
122
  @patch('hestia_earth.models.utils.property.get_node_property', return_value={})
105
- @patch('hestia_earth.models.utils.property.download_hestia', return_value={})
106
123
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
107
124
  def test_run_with_ionophores(*args):
108
125
  with open(f"{fixtures_folder}/with-ionophores/cycle.jsonld", encoding="utf-8") as f:
@@ -115,9 +132,10 @@ def test_run_with_ionophores(*args):
115
132
  assert result == expected
116
133
 
117
134
 
135
+ @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
136
+ @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
118
137
  # patch get_node_property to read value from lookups only
119
138
  @patch('hestia_earth.models.utils.property.get_node_property', return_value={})
120
- @patch('hestia_earth.models.utils.property.download_hestia', return_value={})
121
139
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
122
140
  def test_run_without_ionophores(*args):
123
141
  with open(f"{fixtures_folder}/without-ionophores/cycle.jsonld", encoding="utf-8") as f:
@@ -130,9 +148,10 @@ def test_run_without_ionophores(*args):
130
148
  assert result == expected
131
149
 
132
150
 
151
+ @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
152
+ @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
133
153
  # patch get_node_property to read value from lookups only
134
154
  @patch('hestia_earth.models.utils.property.get_node_property', return_value={})
135
- @patch('hestia_earth.models.utils.property.download_hestia', return_value={})
136
155
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
137
156
  def test_run_no_feed(*args):
138
157
  with open(f"{fixtures_folder}/no-feed/cycle.jsonld", encoding="utf-8") as f:
@@ -142,9 +161,10 @@ def test_run_no_feed(*args):
142
161
  assert result == []
143
162
 
144
163
 
164
+ @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
165
+ @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
145
166
  # patch get_node_property to read value from lookups only
146
167
  @patch('hestia_earth.models.utils.property.get_node_property', return_value={})
147
- @patch('hestia_earth.models.utils.property.download_hestia', return_value={})
148
168
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
149
169
  def test_run_with_system(*args):
150
170
  with open(f"{fixtures_folder}/with-system/cycle.jsonld", encoding="utf-8") as f:
@@ -157,9 +177,13 @@ def test_run_with_system(*args):
157
177
  assert result == expected
158
178
 
159
179
 
180
+ def fake_get_node_property(*args):
181
+ print(*args)
182
+ return {}
183
+
184
+
160
185
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
161
- # patch get_node_property to read value from lookups only
162
- @patch('hestia_earth.models.utils.property.download_hestia', return_value={})
186
+ @patch("hestia_earth.models.utils.property.download_hestia", return_value={})
163
187
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
164
188
  def test_run_default(*args):
165
189
  with open(f"{fixtures_folder}/default-value/cycle.jsonld", encoding="utf-8") as f:
@@ -5,7 +5,7 @@ from unittest.mock import patch
5
5
 
6
6
  from hestia_earth.schema import MeasurementMethodClassification
7
7
 
8
- from hestia_earth.models.ipcc2019.co2ToAirSoilCarbonStockChangeManagementChange import (
8
+ from hestia_earth.models.ipcc2019.co2ToAirSoilOrganicCarbonStockChangeManagementChange import (
9
9
  _calc_soc_stock_change,
10
10
  _convert_c_to_co2,
11
11
  _get_max_measurement_method,
@@ -8,9 +8,10 @@ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
9
 
10
10
 
11
+ @patch(f"{class_path}.has_flooded_rice", return_value=False)
11
12
  @patch(f"{class_path}._is_term_type_complete", return_value=False)
12
13
  @patch(f"{class_path}.get_crop_residue_decomposition_N_total", return_value=0)
13
- def test_should_run(mock_N_total, mock_complete):
14
+ def test_should_run(mock_N_total, mock_complete, *args):
14
15
  # no N => no run
15
16
  should_run, *args = _should_run({})
16
17
  assert not should_run
@@ -26,6 +27,7 @@ def test_should_run(mock_N_total, mock_complete):
26
27
  assert should_run is True
27
28
 
28
29
 
30
+ @patch(f"{class_path}.has_flooded_rice", return_value=False)
29
31
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
30
32
  def test_run(*args):
31
33
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
@@ -38,6 +40,7 @@ def test_run(*args):
38
40
  assert value == expected
39
41
 
40
42
 
43
+ @patch(f"{class_path}.has_flooded_rice", return_value=False)
41
44
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
42
45
  def test_run_wet(*args):
43
46
  with open(f"{fixtures_folder}/ecoClimateZone-wet/cycle.jsonld", encoding='utf-8') as f:
@@ -50,6 +53,7 @@ def test_run_wet(*args):
50
53
  assert value == expected
51
54
 
52
55
 
56
+ @patch(f"{class_path}.has_flooded_rice", return_value=False)
53
57
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
54
58
  def test_run_dry(*args):
55
59
  with open(f"{fixtures_folder}/ecoClimateZone-dry/cycle.jsonld", encoding='utf-8') as f:
@@ -62,6 +66,7 @@ def test_run_dry(*args):
62
66
  assert value == expected
63
67
 
64
68
 
69
+ @patch(f"{class_path}.has_flooded_rice", return_value=True)
65
70
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
66
71
  def test_run_flooded_rice(*args):
67
72
  with open(f"{fixtures_folder}/with-flooded-rice/cycle.jsonld", encoding='utf-8') as f:
@@ -8,9 +8,10 @@ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
9
 
10
10
 
11
+ @patch(f"{class_path}.has_flooded_rice", return_value=False)
11
12
  @patch(f"{class_path}._is_term_type_complete", return_value=False)
12
13
  @patch(f"{class_path}.get_inorganic_fertiliser_N_total", return_value=0)
13
- def test_should_run(mock_N_total, mock_complete):
14
+ def test_should_run(mock_N_total, mock_complete, *args):
14
15
  # no N => no run
15
16
  should_run, *args = _should_run({})
16
17
  assert not should_run
@@ -26,6 +27,7 @@ def test_should_run(mock_N_total, mock_complete):
26
27
  assert should_run is True
27
28
 
28
29
 
30
+ @patch(f"{class_path}.has_flooded_rice", return_value=False)
29
31
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
30
32
  def test_run(*args):
31
33
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
@@ -38,6 +40,7 @@ def test_run(*args):
38
40
  assert value == expected
39
41
 
40
42
 
43
+ @patch(f"{class_path}.has_flooded_rice", return_value=False)
41
44
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
42
45
  def test_run_wet(*args):
43
46
  with open(f"{fixtures_folder}/ecoClimateZone-wet/cycle.jsonld", encoding='utf-8') as f:
@@ -50,6 +53,7 @@ def test_run_wet(*args):
50
53
  assert value == expected
51
54
 
52
55
 
56
+ @patch(f"{class_path}.has_flooded_rice", return_value=False)
53
57
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
54
58
  def test_run_dry(*args):
55
59
  with open(f"{fixtures_folder}/ecoClimateZone-dry/cycle.jsonld", encoding='utf-8') as f:
@@ -62,6 +66,7 @@ def test_run_dry(*args):
62
66
  assert value == expected
63
67
 
64
68
 
69
+ @patch(f"{class_path}.has_flooded_rice", return_value=True)
65
70
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
66
71
  def test_run_flooded_rice(*args):
67
72
  with open(f"{fixtures_folder}/with-flooded-rice/cycle.jsonld", encoding='utf-8') as f:
@@ -8,9 +8,10 @@ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
9
 
10
10
 
11
+ @patch(f"{class_path}.has_flooded_rice", return_value=False)
11
12
  @patch(f"{class_path}._is_term_type_complete", return_value=False)
12
13
  @patch(f"{class_path}.get_organic_fertiliser_N_total", return_value=0)
13
- def test_should_run(mock_N_total, mock_complete):
14
+ def test_should_run(mock_N_total, mock_complete, *args):
14
15
  # no N => no run
15
16
  should_run, *args = _should_run({})
16
17
  assert not should_run
@@ -26,6 +27,7 @@ def test_should_run(mock_N_total, mock_complete):
26
27
  assert should_run is True
27
28
 
28
29
 
30
+ @patch(f"{class_path}.has_flooded_rice", return_value=False)
29
31
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
30
32
  def test_run(*args):
31
33
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
@@ -38,6 +40,7 @@ def test_run(*args):
38
40
  assert value == expected
39
41
 
40
42
 
43
+ @patch(f"{class_path}.has_flooded_rice", return_value=False)
41
44
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
42
45
  def test_run_wet(*args):
43
46
  with open(f"{fixtures_folder}/ecoClimateZone-wet/cycle.jsonld", encoding='utf-8') as f:
@@ -50,6 +53,7 @@ def test_run_wet(*args):
50
53
  assert value == expected
51
54
 
52
55
 
56
+ @patch(f"{class_path}.has_flooded_rice", return_value=False)
53
57
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
54
58
  def test_run_dry(*args):
55
59
  with open(f"{fixtures_folder}/ecoClimateZone-dry/cycle.jsonld", encoding='utf-8') as f:
@@ -62,6 +66,7 @@ def test_run_dry(*args):
62
66
  assert value == expected
63
67
 
64
68
 
69
+ @patch(f"{class_path}.has_flooded_rice", return_value=True)
65
70
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
66
71
  def test_run_flooded_rice(*args):
67
72
  with open(f"{fixtures_folder}/with-flooded-rice/cycle.jsonld", encoding='utf-8') as f:
@@ -5,15 +5,37 @@ from tests.utils import fixtures_path, fake_new_input
5
5
  from hestia_earth.models.ipcc2019.pastureGrass import MODEL, MODEL_KEY, run
6
6
 
7
7
  class_path = f"hestia_earth.models.{MODEL}.{MODEL_KEY}"
8
+ class_path_utils = f"{class_path}_utils"
8
9
  fixtures_folder = f"{fixtures_path}/{MODEL}/{MODEL_KEY}"
9
10
  MILK_YIELD_TERMS = ['milkYieldPerCowRaw', 'milkYieldPerSheepRaw']
10
11
  WOOL_TERMS = ['woolSheepGreasy']
11
-
12
-
13
- def fake_download_hestia(term_id: str, *args): return {'@id': term_id, 'termType': 'forage'}
14
-
15
-
16
- @patch(f"{class_path}.download_hestia", side_effect=fake_download_hestia)
12
+ TERMS_BY_ID = {
13
+ 'surinameGrassFreshForage': {
14
+ '@id': 'surinameGrassFreshForage',
15
+ 'termType': 'forage',
16
+ 'defaultProperties': [
17
+ {'term': {'@id': 'energyContentHigherHeatingValue'}, 'value': 4.8508},
18
+ {'term': {'@id': 'energyDigestibilityRuminants'}, 'value': 52.7}
19
+ ]
20
+ },
21
+ 'alangAlangFreshForage': {
22
+ '@id': 'alangAlangFreshForage',
23
+ 'termType': 'forage',
24
+ 'defaultProperties': [
25
+ {'term': {'@id': 'energyContentHigherHeatingValue'}, 'value': 5.9334},
26
+ {'term': {'@id': 'energyDigestibilityRuminants'}, 'value': 54.7}
27
+ ]
28
+ },
29
+ 'energyContentHigherHeatingValue': {'units': 'MJ / kg'},
30
+ 'energyDigestibilityRuminants': {'units': '%'},
31
+ }
32
+
33
+
34
+ def fake_download_hestia(term_id: str, *args): return TERMS_BY_ID[term_id]
35
+
36
+
37
+ @patch(f"{class_path_utils}.download_hestia", side_effect=fake_download_hestia)
38
+ @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
17
39
  @patch(f"{class_path}.get_wool_terms", return_value=WOOL_TERMS)
18
40
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=MILK_YIELD_TERMS)
19
41
  @patch(f"{class_path}._new_input", side_effect=fake_new_input)
@@ -28,7 +50,8 @@ def test_run(*args):
28
50
  assert value == expected
29
51
 
30
52
 
31
- @patch(f"{class_path}.download_hestia", side_effect=fake_download_hestia)
53
+ @patch(f"{class_path_utils}.download_hestia", side_effect=fake_download_hestia)
54
+ @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
32
55
  @patch(f"{class_path}.get_wool_terms", return_value=WOOL_TERMS)
33
56
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=MILK_YIELD_TERMS)
34
57
  @patch(f"{class_path}._new_input", side_effect=fake_new_input)
@@ -43,7 +66,8 @@ def test_run_with_feed(*args):
43
66
  assert value == expected
44
67
 
45
68
 
46
- @patch(f"{class_path}.download_hestia", side_effect=fake_download_hestia)
69
+ @patch(f"{class_path_utils}.download_hestia", side_effect=fake_download_hestia)
70
+ @patch("hestia_earth.models.utils.property.download_hestia", side_effect=fake_download_hestia)
47
71
  @patch(f"{class_path}.get_wool_terms", return_value=WOOL_TERMS)
48
72
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=MILK_YIELD_TERMS)
49
73
  @patch(f"{class_path}._new_input", side_effect=fake_new_input)
@@ -59,6 +59,7 @@ def test_should_run(mock_animal_produced, mock_get_feed, *args):
59
59
  assert should_run is True
60
60
 
61
61
 
62
+ @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
62
63
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
63
64
  def test_run(*args):
64
65
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
@@ -71,6 +72,7 @@ def test_run(*args):
71
72
  assert value == expected
72
73
 
73
74
 
75
+ @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
74
76
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
75
77
  def test_run_with_liveweight(*args):
76
78
  with open(f"{fixtures_folder}/with-liveweight/cycle.jsonld", encoding='utf-8') as f:
@@ -83,6 +85,7 @@ def test_run_with_liveweight(*args):
83
85
  assert value == expected
84
86
 
85
87
 
88
+ @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
86
89
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
87
90
  def test_run_with_carcass(*args):
88
91
  with open(f"{fixtures_folder}/with-carcass/cycle.jsonld", encoding='utf-8') as f:
@@ -95,6 +98,7 @@ def test_run_with_carcass(*args):
95
98
  assert value == expected
96
99
 
97
100
 
101
+ @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
98
102
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
99
103
  def test_run_with_head(*args):
100
104
  with open(f"{fixtures_folder}/with-head/cycle.jsonld", encoding='utf-8') as f:
@@ -107,6 +111,7 @@ def test_run_with_head(*args):
107
111
  assert value == expected
108
112
 
109
113
 
114
+ @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
110
115
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
111
116
  def test_run_with_liveAquaticSpecies(*args):
112
117
  with open(f"{fixtures_folder}/with-liveAquaticSpecies/cycle.jsonld", encoding='utf-8') as f:
@@ -8,6 +8,7 @@ class_path = f"hestia_earth.models.{MODEL}.excretaKgVs"
8
8
  fixtures_folder = f"{fixtures_path}/{MODEL}/excretaKgVs"
9
9
 
10
10
 
11
+ @patch(f"{class_path}.get_node_property", return_value={'value': 1490.6951744738524})
11
12
  @patch(f"{class_path}.convert_to_carbon", return_value=5)
12
13
  @patch(f"{class_path}._get_carbonContent", return_value=5)
13
14
  @patch(f"{class_path}._get_conv_aq_ocsed", return_value=0.35)
@@ -78,6 +79,8 @@ def test_should_run(*args):
78
79
  assert should_run is True
79
80
 
80
81
 
82
+ @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
83
+ @patch(f"{class_path}.get_node_property", return_value={'value': 1490.6951744738524})
81
84
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
82
85
  def test_run(*args):
83
86
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
@@ -90,6 +93,8 @@ def test_run(*args):
90
93
  assert value == expected
91
94
 
92
95
 
96
+ @patch("hestia_earth.models.utils.property.download_hestia", return_value={'units': '%'})
97
+ @patch(f"{class_path}.get_node_property", return_value={'value': 1490.6951744738524})
93
98
  @patch(f"{class_path}._new_product", side_effect=fake_new_product)
94
99
  def test_run_excretaKgN(*args):
95
100
  with open(f"{fixtures_folder}/with-excretaKgN/cycle.jsonld", encoding='utf-8') as f:
@@ -8,6 +8,7 @@ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
9
 
10
10
 
11
+ @patch(f"{class_path}.get_rice_paddy_terms", return_value=FLOODED_RICE_TERMS)
11
12
  @patch(f"{class_path}.find_primary_product", return_value={'term': {'@id': 'product'}})
12
13
  @patch(f"{class_path}.get_crop_residue_decomposition_N_total", return_value=10)
13
14
  @patch(f"{class_path}.most_relevant_measurement_value", return_value=0)
@@ -7,13 +7,14 @@ from hestia_earth.models.cache_sites import run
7
7
 
8
8
  class_path = 'hestia_earth.models.cache_sites'
9
9
  fixtures_folder = os.path.join(fixtures_path, 'cache_sites')
10
+ coordinates = [{"latitude": 46.47, "longitude": 2.94}]
10
11
 
11
12
 
12
13
  @patch(f"{class_path}._run_query", return_value=[10] * 100)
13
14
  def test_run(mock_run_query, *args):
14
15
  with open(f"{fixtures_folder}/data.json", encoding='utf-8') as f:
15
16
  data = json.load(f)
16
- with open(f"{fixtures_folder}/result.json", encoding='utf-8') as f:
17
+ with open(f"{fixtures_folder}/cache.json", encoding='utf-8') as f:
17
18
  cache = json.load(f)
18
19
  with open(f"{fixtures_folder}/params.json", encoding='utf-8') as f:
19
20
  params = json.load(f)
@@ -22,9 +23,6 @@ def test_run(mock_run_query, *args):
22
23
  expected = [site | {'_cache': cache} for site in data.get('nodes', [])]
23
24
  assert sites == expected
24
25
 
25
- # unique list of coordinates
26
- coordinates = [{"latitude": 46.47, "longitude": 2.94}]
27
-
28
26
  mock_run_query.assert_has_calls([
29
27
  call({
30
28
  "ee_type": "raster",
@@ -37,9 +35,15 @@ def test_run(mock_run_query, *args):
37
35
  "coordinates": coordinates
38
36
  })
39
37
  ])
40
- mock_run_query.reset_mock()
41
38
 
42
- # with regions
39
+
40
+ @patch(f"{class_path}._run_query", return_value=[10] * 100)
41
+ def test_run_include_region(mock_run_query, *args):
42
+ with open(f"{fixtures_folder}/data.json", encoding='utf-8') as f:
43
+ data = json.load(f)
44
+ with open(f"{fixtures_folder}/params.json", encoding='utf-8') as f:
45
+ params = json.load(f)
46
+
43
47
  run(data.get('nodes', []), [2019, 2020], include_region=True)
44
48
  mock_run_query.assert_has_calls([
45
49
  call({
@@ -53,4 +57,15 @@ def test_run(mock_run_query, *args):
53
57
  "coordinates": coordinates
54
58
  })
55
59
  ])
56
- mock_run_query.reset_mock()
60
+
61
+
62
+ @patch(f"{class_path}._run_query", return_value=[10] * 100)
63
+ def test_run_years_only(*args):
64
+ with open(f"{fixtures_folder}/data.json", encoding='utf-8') as f:
65
+ data = json.load(f)
66
+ with open(f"{fixtures_folder}/years-only/cache.json", encoding='utf-8') as f:
67
+ cache = json.load(f)
68
+
69
+ sites = run(data.get('nodes', []), [2019, 2020], years_only=True)
70
+ expected = [site | {'_cache': cache} for site in data.get('nodes', [])]
71
+ assert sites == expected