hestia-earth-models 0.62.0__py3-none-any.whl → 0.62.1__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 (58) hide show
  1. hestia_earth/models/blonkConsultants2016/utils.py +3 -2
  2. hestia_earth/models/cycle/post_checks/__init__.py +3 -2
  3. hestia_earth/models/cycle/post_checks/otherSites.py +40 -0
  4. hestia_earth/models/cycle/pre_checks/__init__.py +2 -1
  5. hestia_earth/models/cycle/pre_checks/otherSites.py +42 -0
  6. hestia_earth/models/cycle/pre_checks/site.py +1 -1
  7. hestia_earth/models/ecoinventV3AndEmberClimate/utils.py +1 -1
  8. hestia_earth/models/emepEea2019/utils.py +4 -3
  9. hestia_earth/models/geospatialDatabase/heavyWinterPrecipitation.py +1 -1
  10. hestia_earth/models/ipcc2019/animal/pastureGrass.py +6 -6
  11. hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +30 -4
  12. hestia_earth/models/ipcc2019/n2OToAirExcretaDirect.py +6 -2
  13. hestia_earth/models/ipcc2019/n2OToAirExcretaIndirect.py +1 -1
  14. hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserDirect.py +1 -1
  15. hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserIndirect.py +1 -1
  16. hestia_earth/models/ipcc2019/n2OToAirOrganicFertiliserIndirect.py +1 -1
  17. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +4 -2
  18. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +2 -1
  19. hestia_earth/models/ipcc2019/pastureGrass.py +3 -3
  20. hestia_earth/models/ipcc2019/pastureGrass_utils.py +41 -41
  21. hestia_earth/models/mocking/search-results.json +89 -89
  22. hestia_earth/models/schererPfister2015/utils.py +2 -2
  23. hestia_earth/models/site/brackishWater.py +1 -1
  24. hestia_earth/models/site/flowingWater.py +1 -1
  25. hestia_earth/models/site/freshWater.py +1 -1
  26. hestia_earth/models/site/management.py +29 -11
  27. hestia_earth/models/site/pre_checks/cache_sources.py +9 -13
  28. hestia_earth/models/site/salineWater.py +1 -1
  29. hestia_earth/models/stehfestBouwman2006/n2OToAirCropResidueDecompositionDirect.py +12 -2
  30. hestia_earth/models/stehfestBouwman2006/n2OToAirExcretaDirect.py +12 -2
  31. hestia_earth/models/stehfestBouwman2006/n2OToAirInorganicFertiliserDirect.py +11 -1
  32. hestia_earth/models/stehfestBouwman2006/n2OToAirOrganicFertiliserDirect.py +11 -1
  33. hestia_earth/models/stehfestBouwman2006/noxToAirCropResidueDecomposition.py +12 -2
  34. hestia_earth/models/stehfestBouwman2006/noxToAirExcreta.py +12 -2
  35. hestia_earth/models/stehfestBouwman2006/noxToAirInorganicFertiliser.py +11 -1
  36. hestia_earth/models/stehfestBouwman2006/noxToAirOrganicFertiliser.py +11 -1
  37. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirCropResidueDecomposition.py +12 -2
  38. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirExcreta.py +12 -2
  39. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirInorganicFertiliser.py +11 -1
  40. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirOrganicFertiliser.py +11 -1
  41. hestia_earth/models/utils/blank_node.py +106 -110
  42. hestia_earth/models/utils/constant.py +2 -0
  43. hestia_earth/models/utils/lookup.py +19 -6
  44. hestia_earth/models/utils/source.py +1 -1
  45. hestia_earth/models/version.py +1 -1
  46. {hestia_earth_models-0.62.0.dist-info → hestia_earth_models-0.62.1.dist-info}/METADATA +2 -2
  47. {hestia_earth_models-0.62.0.dist-info → hestia_earth_models-0.62.1.dist-info}/RECORD +58 -53
  48. tests/models/cycle/post_checks/test_otherSites.py +15 -0
  49. tests/models/cycle/pre_checks/test_otherSites.py +21 -0
  50. tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +5 -3
  51. tests/models/ipcc2019/test_organicCarbonPerHa.py +1 -0
  52. tests/models/site/pre_checks/test_cache_sources.py +6 -10
  53. tests/models/site/test_management.py +162 -2
  54. tests/models/utils/test_blank_node.py +0 -281
  55. tests/models/utils/test_lookup.py +10 -0
  56. {hestia_earth_models-0.62.0.dist-info → hestia_earth_models-0.62.1.dist-info}/LICENSE +0 -0
  57. {hestia_earth_models-0.62.0.dist-info → hestia_earth_models-0.62.1.dist-info}/WHEEL +0 -0
  58. {hestia_earth_models-0.62.0.dist-info → hestia_earth_models-0.62.1.dist-info}/top_level.txt +0 -0
@@ -5,6 +5,7 @@ import pytest
5
5
  from hestia_earth.schema import TermTermType
6
6
 
7
7
  from hestia_earth.models.site.management import MODEL, MODEL_KEY, run, _should_run
8
+ from hestia_earth.models.utils.blank_node import condense_nodes
8
9
  from tests.utils import fixtures_path
9
10
 
10
11
  CLASS_PATH = f"hestia_earth.models.{MODEL}.{MODEL_KEY}"
@@ -14,7 +15,8 @@ TERM_BY_ID = {
14
15
  'genericCropPlant': {'@type': 'Term', '@id': 'genericCropPlant', 'termType': TermTermType.LANDCOVER.value},
15
16
  'wheatPlant': {'@type': 'Term', '@id': 'wheatPlant', 'termType': TermTermType.LANDCOVER.value},
16
17
  'oatPlant': {'@type': 'Term', '@id': 'oatPlant', 'termType': TermTermType.LANDCOVER.value},
17
- 'agatiTree': {'@type': 'Term', '@id': 'agatiTree', 'termType': TermTermType.LANDCOVER.value}
18
+ 'agatiTree': {'@type': 'Term', '@id': 'agatiTree', 'termType': TermTermType.LANDCOVER.value},
19
+ 'wildGarlicPlant': {'@type': 'Term', '@id': 'wildGarlicPlant', 'termType': TermTermType.LANDCOVER.value},
18
20
  }
19
21
 
20
22
 
@@ -28,6 +30,152 @@ def lookup_side_effect(*args, **kwargs):
28
30
  return True
29
31
 
30
32
 
33
+ @pytest.mark.parametrize(
34
+ "test_name,input_nodes,expected_output_nodes",
35
+ [
36
+ (
37
+ "No match",
38
+ [
39
+ {"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
40
+ "value": [2]},
41
+ {"startDate": "2003", "endDate": "2004", "term": {"@id": "bananaPlant", "units": "% area"},
42
+ "value": [2]},
43
+ ],
44
+ [
45
+ {"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
46
+ "value": [2]},
47
+ {"startDate": "2003", "endDate": "2004", "term": {"@id": "bananaPlant", "units": "% area"},
48
+ "value": [2]},
49
+ ],
50
+ ),
51
+ (
52
+ "No continuity",
53
+ [
54
+ {"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
55
+ "value": [2]},
56
+ {"startDate": "2004", "endDate": "2005", "term": {"@id": "treeNutTree", "units": "% area"},
57
+ "value": [2]},
58
+ ],
59
+ [
60
+ {"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
61
+ "value": [2]},
62
+ {"startDate": "2004", "endDate": "2005", "term": {"@id": "treeNutTree", "units": "% area"},
63
+ "value": [2]},
64
+ ],
65
+ ),
66
+ (
67
+ "No continuity (multiple values differ)",
68
+ [
69
+ {"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
70
+ "value": [10, 20]},
71
+ {"startDate": "2003", "endDate": "2004", "term": {"@id": "treeNutTree", "units": "% area"},
72
+ "value": [10, 30]},
73
+ ],
74
+ [
75
+ {"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
76
+ "value": [10, 20]},
77
+ {"startDate": "2003", "endDate": "2004", "term": {"@id": "treeNutTree", "units": "% area"},
78
+ "value": [10, 30]},
79
+ ],
80
+ ),
81
+ (
82
+ "2->1 condense (YYYY dates)",
83
+ [
84
+ {"startDate": "2001", "endDate": "2001", "term": {"@id": "treeNutTree", "units": "% area"},
85
+ "value": [10, 20]},
86
+ {"startDate": "2002", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
87
+ "value": [10, 20]},
88
+ ],
89
+ [
90
+ {"startDate": "2001-01-01", "endDate": "2002-12-31", "term": {"@id": "treeNutTree", "units": "% area"},
91
+ "value": [10, 20]}
92
+ ],
93
+ ),
94
+ (
95
+ "4->2 condense (YYYY-MM dates)",
96
+ [
97
+ {"startDate": "2001-01", "endDate": "2001-12", "term": {"@id": "treeNutTree", "units": "% area"},
98
+ "value": [2]},
99
+ {"startDate": "2002-01", "endDate": "2002-03", "term": {"@id": "treeNutTree", "units": "% area"},
100
+ "value": [2]},
101
+ ],
102
+ [
103
+ {"startDate": "2001-01-01", "endDate": "2002-03-31", "term": {"@id": "treeNutTree", "units": "% area"},
104
+ "value": [2]}
105
+ ],
106
+ ),
107
+ (
108
+ "2->1 condense (YYYY-MM-DD dates)",
109
+ [
110
+ {"startDate": "2001-01-01", "endDate": "2001-12-31", "term": {"@id": "treeNutTree", "units": "% area"},
111
+ "value": [2]},
112
+ {"startDate": "2002-01-01", "endDate": "2002-05-04", "term": {"@id": "treeNutTree", "units": "% area"},
113
+ "value": [2]},
114
+ ],
115
+ [
116
+ {"startDate": "2001-01-01", "endDate": "2002-05-04", "term": {"@id": "treeNutTree", "units": "% area"},
117
+ "value": [2]}
118
+ ],
119
+ ),
120
+ (
121
+ "3->1 condense",
122
+ [
123
+ {"startDate": "2001-01-01", "endDate": "2001-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
124
+ "value": [9]},
125
+ {"startDate": "2002-01-01", "endDate": "2002-10-31", "term": {"@id": "bananaPlant", "units": "% area"},
126
+ "value": [9]},
127
+ {"startDate": "2002-11-01", "endDate": "2004-04-05", "term": {"@id": "bananaPlant", "units": "% area"},
128
+ "value": [9]},
129
+ ],
130
+ [
131
+ {"startDate": "2001-01-01", "endDate": "2004-04-05", "term": {"@id": "bananaPlant", "units": "% area"},
132
+ "value": [9]}
133
+ ],
134
+ ),
135
+ (
136
+ "3->2 partial condense",
137
+ [
138
+ {"startDate": "2001-01-01", "endDate": "2001-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
139
+ "value": [9]},
140
+ {"startDate": "2012-02-01", "endDate": "2012-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
141
+ "value": [9]},
142
+ {"startDate": "2002-01-01", "endDate": "2003-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
143
+ "value": [9]},
144
+ ],
145
+ [
146
+ {"startDate": "2001-01-01", "endDate": "2003-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
147
+ "value": [9]},
148
+ {"startDate": "2012-02-01", "endDate": "2012-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
149
+ "value": [9]}
150
+ ],
151
+ ),
152
+ (
153
+ "7->2 multi-condense",
154
+ [
155
+ {"startDate": "2001-01-01", "endDate": "2001-11-30", "term": {"@id": "bananaPlant", "units": "% area"},
156
+ "value": [7]},
157
+ {"startDate": "2012-02-01", "endDate": "2012-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
158
+ "value": [7]},
159
+ {"startDate": "2001-12-01", "endDate": "2001-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
160
+ "value": [7]},
161
+ {"startDate": "2002-01-01", "endDate": "2002-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
162
+ "value": [7]},
163
+ {"startDate": "2013-01-01", "endDate": "2013-05-20", "term": {"@id": "bananaPlant", "units": "% area"},
164
+ "value": [7]},
165
+ ],
166
+ [
167
+ {"startDate": "2001-01-01", "endDate": "2002-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
168
+ "value": [7]},
169
+ {"startDate": "2012-02-01", "endDate": "2013-05-20", "term": {"@id": "bananaPlant", "units": "% area"},
170
+ "value": [7]}
171
+ ],
172
+ ),
173
+ ]
174
+ )
175
+ def test_condense_nodes(test_name, input_nodes, expected_output_nodes):
176
+ assert condense_nodes(input_nodes) == expected_output_nodes
177
+
178
+
31
179
  @patch(f"{CLASS_PATH}.download_hestia", side_effect=lambda id, *args: TERM_BY_ID[id])
32
180
  @patch(f"{CLASS_PATH}.related_cycles")
33
181
  def test_should_run(mock_related_cycles, *args):
@@ -121,7 +269,19 @@ def test_should_run(mock_related_cycles, *args):
121
269
  ("Example 1", f"{fixtures_folder}/inputs/example1"),
122
270
  ("Example 2", f"{fixtures_folder}/inputs/example2"),
123
271
  ("Example 3", f"{fixtures_folder}/inputs/example3"),
124
- ("Example 4", f"{fixtures_folder}/inputs/example4")
272
+ ("Example 4", f"{fixtures_folder}/inputs/example4"),
273
+ ("Condense Nodes", f"{fixtures_folder}/inputs/condense_nodes")
274
+ # Expected:
275
+ # - appleTree (81) x 3 condenses 2020-03-01 to 2021-02-15
276
+ # - animalManureUsed (true) x 2 condenses 2001-04-01 to 2001-12-31
277
+ # - treeNutTree, lebbekTree (82) does not condense [different terms]
278
+ # - organicFertiliserUsed (true|false) does not condense [different values]
279
+ # - glassOrHighAccessibleCover (83) does not condense [different date ranges (overlapping)]
280
+ # - durianTree (84) does not condense [different date ranges (disjoint)]
281
+ # - irrigatedSurfaceIrrigationContinuouslyFlooded (85) does not condense ["%" units]
282
+ # - sassafrasTree (86) x 2 condenses 2001-01-01 to 2004-12-31
283
+ # - bananaPlant (87) does not condense [non-consecutive years]
284
+ # - durianTree (89) does not condense [dates overwritten See 808]
125
285
  ]
126
286
  )
127
287
  @patch(f"{CLASS_PATH}.download_hestia", side_effect=lambda id, *args: TERM_BY_ID[id])
@@ -12,13 +12,10 @@ from hestia_earth.models.utils.blank_node import (
12
12
  _get_datestr_format,
13
13
  _run_required,
14
14
  _run_model_required,
15
- _should_run_array_treatment,
16
- ArrayTreatment,
17
15
  cumulative_nodes_match,
18
16
  DatestrFormat,
19
17
  DatestrGapfillMode,
20
18
  DatetimeRange,
21
- get_node_value,
22
19
  group_nodes_by_year,
23
20
  group_nodes_by_year_and_month,
24
21
  GroupNodesByYearMode,
@@ -63,282 +60,6 @@ def test_run_model_required():
63
60
  })
64
61
 
65
62
 
66
- # --- test should_run_array_treatment ---
67
-
68
-
69
- def test_should_run_array_treatment_true():
70
- VALUE = [24, 87, 34, 12]
71
- assert _should_run_array_treatment(VALUE) is True
72
-
73
-
74
- def test_should_run_array_treatment_false_empty_list():
75
- VALUE = []
76
- assert _should_run_array_treatment(VALUE) is False
77
-
78
-
79
- def test_should_run_array_treatment_false_not_iterable():
80
- VALUE = 1
81
- assert _should_run_array_treatment(VALUE) is False
82
-
83
-
84
- # --- test get_node_value ---
85
-
86
-
87
- FULL_TILLAGE_AS_PRACTICE = {
88
- "@type": "Practice",
89
- "term": {
90
- "@type": "Term",
91
- "@id": "fullTillage"
92
- },
93
- "value": [50, 50, 60, 70]
94
- }
95
-
96
- FULL_TILLAGE_AS_MANAGEMENT = {
97
- "@type": "Management",
98
- "term": {
99
- "@type": "Term",
100
- "@id": "fullTillage"
101
- },
102
- "value": 100
103
- }
104
-
105
- EXPECTED_EMPTY_LIST = 0
106
-
107
-
108
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
109
- def test_get_node_value_list_reduce_default(*args):
110
- """
111
- Should return the reduced value of the value list using the array treatment specified in the term lookup
112
- (or ArrayTreatment.FIRST if no lookup value available).
113
-
114
- The lookup array treatment for `fullTillage` is `first`, therefore a return value of `50` is expected.
115
- """
116
- EXPECTED = 50
117
- result = get_node_value(FULL_TILLAGE_AS_PRACTICE)
118
- assert result == EXPECTED
119
-
120
-
121
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
122
- def test_get_node_value_list_reduce_mean(*args):
123
- """
124
- Should return the mean value of the value list.
125
-
126
- `statistics.mean` function is used here.
127
- """
128
- EXPECTED = 57.5
129
- result = get_node_value(
130
- FULL_TILLAGE_AS_PRACTICE, array_treatment=ArrayTreatment.MEAN
131
- )
132
- assert result == EXPECTED
133
-
134
-
135
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
136
- def test_get_node_value_list_reduce_mode(*args):
137
- """
138
- Should return the mode value of the value list.
139
-
140
- `statistics.mode` function is used here.
141
- """
142
- EXPECTED = 50
143
- result = get_node_value(
144
- FULL_TILLAGE_AS_PRACTICE, array_treatment=ArrayTreatment.MODE
145
- )
146
- assert result == EXPECTED
147
-
148
-
149
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
150
- def test_get_node_value_list_reduce_sum(*args):
151
- """
152
- Should return the sum value of the value list.
153
- """
154
- EXPECTED = 230
155
- result = get_node_value(
156
- FULL_TILLAGE_AS_PRACTICE, array_treatment=ArrayTreatment.SUM
157
- )
158
- assert result == EXPECTED
159
-
160
-
161
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
162
- def test_get_node_value_list_reduce_first(*args):
163
- """
164
- Should return the first value of the value list.
165
- """
166
- EXPECTED = 50
167
- result = get_node_value(
168
- FULL_TILLAGE_AS_PRACTICE, array_treatment=ArrayTreatment.FIRST
169
- )
170
- assert result == EXPECTED
171
-
172
-
173
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
174
- def test_get_node_value_list_reduce_last(*args):
175
- """
176
- Should return the last value of the value list.
177
- """
178
- EXPECTED = 70
179
- result = get_node_value(
180
- FULL_TILLAGE_AS_PRACTICE, array_treatment=ArrayTreatment.LAST
181
- )
182
- assert result == EXPECTED
183
-
184
-
185
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
186
- def test_get_node_value_list_bools_reduce_mean(*args):
187
- """
188
- If value is list of bools, the `satistics.mean` interprets them as integers (0 or 1),
189
- therefore number is returned.
190
- """
191
- EXPECTED = 1/3
192
- NODE = {"value": [False, False, True]}
193
- result = get_node_value(
194
- NODE, array_treatment=ArrayTreatment.MEAN
195
- )
196
- assert result == EXPECTED
197
-
198
-
199
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
200
- def test_get_node_value_list_bools_reduce_mode(*args):
201
- """
202
- If value is list of bools, the `satistics.mode` interprets them as bools and returns the most
203
- common bool value as expected.
204
- """
205
- EXPECTED = False
206
- NODE = {"value": [False, False, True]}
207
- result = get_node_value(
208
- NODE, array_treatment=ArrayTreatment.MODE
209
- )
210
- assert result == EXPECTED
211
- assert isinstance(result, bool)
212
-
213
-
214
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
215
- def test_get_node_value_list_bools_reduce_sum(*args):
216
- """
217
- If value is list of bools, the built-in `sum` interprets them as integers (0 or 1),
218
- therefore number is returned.
219
- """
220
- EXPECTED = 1
221
- NODE = {"value": [False, False, True]}
222
- result = get_node_value(
223
- NODE, array_treatment=ArrayTreatment.SUM
224
- )
225
- assert result == EXPECTED
226
-
227
-
228
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
229
- def test_get_node_value_empty_list_reduce_default(*args):
230
- """
231
- Empty list return as 0 if keyword arg `reduce_value_list` = `True`.
232
- """
233
- NODE = {"value": []}
234
- result = get_node_value(NODE)
235
- assert result == EXPECTED_EMPTY_LIST
236
-
237
-
238
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
239
- def test_get_node_value_empty_list_reduce_mean(*args):
240
- """
241
- Empty list return as 0 if keyword arg `reduce_value_list` = `True`.
242
- """
243
- NODE = {"value": []}
244
- result = get_node_value(
245
- NODE, array_treatment=ArrayTreatment.MEAN
246
- )
247
- assert result == EXPECTED_EMPTY_LIST
248
-
249
-
250
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
251
- def test_get_node_value_empty_list_reduce_mode(*args):
252
- """
253
- Empty list return as 0 if keyword arg `reduce_value_list` = `True`.
254
- """
255
- NODE = {"value": []}
256
- result = get_node_value(
257
- NODE, array_treatment=ArrayTreatment.MODE
258
- )
259
- assert result == EXPECTED_EMPTY_LIST
260
-
261
-
262
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
263
- def test_get_node_value_empty_list_reduce_sum(*args):
264
- """
265
- Empty list return as 0 if keyword arg `reduce_value_list` = `True`.
266
- """
267
- NODE = {"value": []}
268
- result = get_node_value(
269
- NODE, array_treatment=ArrayTreatment.SUM
270
- )
271
- assert result == EXPECTED_EMPTY_LIST
272
-
273
-
274
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
275
- def test_get_node_value_empty_list_reduce_first(*args):
276
- """
277
- Empty list return as 0 if keyword arg `reduce_value_list` = `True`.
278
- """
279
- NODE = {"value": []}
280
- result = get_node_value(
281
- NODE, array_treatment=ArrayTreatment.FIRST
282
- )
283
- assert result == EXPECTED_EMPTY_LIST
284
-
285
-
286
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
287
- def test_get_node_value_empty_list_reduce_last(*args):
288
- """
289
- Empty list return as 0 if keyword arg `reduce_value_list` = `True`.
290
- """
291
- NODE = {"value": []}
292
- result = get_node_value(
293
- NODE, array_treatment=ArrayTreatment.LAST
294
- )
295
- assert result == EXPECTED_EMPTY_LIST
296
-
297
-
298
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
299
- def test_get_node_value_float(*args):
300
- """
301
- Non-list values are returned directly, even if if keyword arg `reduce_value_list` = `True`.
302
- """
303
- EXPECTED = 100
304
- result = get_node_value(FULL_TILLAGE_AS_MANAGEMENT)
305
- assert result == EXPECTED
306
-
307
-
308
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
309
- def test_get_node_value_bool_true(*args):
310
- """
311
- Non-list values are returned directly, even if if keyword arg `reduce_value_list` = `True`.
312
- """
313
- EXPECTED = True
314
- NODE = {"value": True}
315
- result = get_node_value(NODE)
316
- assert result == EXPECTED
317
-
318
-
319
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
320
- def test_get_node_value_bool_false(*args):
321
- """
322
- Non-list values are returned directly, even if if keyword arg `reduce_value_list` = `True`.
323
- """
324
- EXPECTED = False
325
- NODE = {"value": False}
326
- result = get_node_value(NODE)
327
- assert result == EXPECTED
328
- assert isinstance(result, bool)
329
-
330
-
331
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.FIRST)
332
- def test_get_node_value_no_value(*args):
333
- """
334
- Missing values are returned as 0.
335
- """
336
- EXPECTED = 0
337
- NODE = {}
338
- result = get_node_value(NODE)
339
- assert result == EXPECTED
340
-
341
-
342
63
  # --- test cumulative_nodes_match ---
343
64
 
344
65
 
@@ -370,7 +91,6 @@ CROP_RESIDUE_NODES = [
370
91
  ]
371
92
 
372
93
 
373
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.MEAN)
374
94
  def test_cumulative_nodes_match_true(*args):
375
95
  result = cumulative_nodes_match(
376
96
  lambda node: node.get("term", {}).get("@id") in [
@@ -382,7 +102,6 @@ def test_cumulative_nodes_match_true(*args):
382
102
  assert result is True
383
103
 
384
104
 
385
- @patch(f"{class_path}._retrieve_array_treatment", return_value=ArrayTreatment.MEAN)
386
105
  def test_cumulative_nodes_match_false(*args):
387
106
  result = cumulative_nodes_match(
388
107
  lambda node: node.get("term", {}).get("@id") in ["aboveGroundCropResidueLeftOnField"],
@@ -0,0 +1,10 @@
1
+ from hestia_earth.models.utils.lookup import is_siteType_allowed
2
+
3
+
4
+ def test_is_siteType_allowed():
5
+ term = {'@id': 'pastureGrass', 'termType': 'landUseManagement'}
6
+ site = {'@type': 'Site', 'siteType': 'cropland'}
7
+ assert not is_siteType_allowed(site, term)
8
+
9
+ cycle = {'otherSites': [{'@type': 'Site', 'siteType': 'permanent pasture'}]}
10
+ assert is_siteType_allowed(cycle, term) is True