hestia-earth-models 0.64.14__py3-none-any.whl → 0.65.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 (112) hide show
  1. hestia_earth/models/agribalyse2016/fuelElectricity.py +1 -1
  2. hestia_earth/models/cache_sites.py +15 -24
  3. hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsLandTransformation.py +6 -9
  4. hestia_earth/models/cycle/input/hestiaAggregatedData.py +46 -22
  5. hestia_earth/models/cycle/pre_checks/cache_sources.py +3 -25
  6. hestia_earth/models/cycle/product/economicValueShare.py +2 -2
  7. hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandTransformation.py +11 -33
  8. hestia_earth/models/faostat2018/landTransformation100YearAverageDuringCycle.py +34 -0
  9. hestia_earth/models/faostat2018/landTransformation20YearAverageDuringCycle.py +34 -0
  10. hestia_earth/models/faostat2018/utils.py +47 -3
  11. hestia_earth/models/hestia/landCover.py +5 -5
  12. hestia_earth/models/hestia/seed_emissions.py +275 -0
  13. hestia_earth/models/ipcc2019/aboveGroundBiomass.py +2 -2
  14. hestia_earth/models/ipcc2019/belowGroundBiomass.py +8 -2
  15. hestia_earth/models/ipcc2019/biomass_utils.py +11 -4
  16. hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py +19 -10
  17. hestia_earth/models/ipcc2019/co2ToAirAboveGroundBiomassStockChange.py +2 -1
  18. hestia_earth/models/ipcc2019/co2ToAirBelowGroundBiomassStockChange.py +2 -1
  19. hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +8 -7
  20. hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChange.py +2 -1
  21. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +28 -34
  22. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +8 -12
  23. hestia_earth/models/ipcc2019/organicCarbonPerHa_utils.py +13 -30
  24. hestia_earth/models/linkedImpactAssessment/{landTransformationFromCropland20YearAverageInputsProduction.py → landTransformation100YearAverageInputsProduction.py} +5 -2
  25. hestia_earth/models/linkedImpactAssessment/{landTransformationFromCropland100YearAverageInputsProduction.py → landTransformation20YearAverageInputsProduction.py} +5 -2
  26. hestia_earth/models/linkedImpactAssessment/utils.py +69 -12
  27. hestia_earth/models/mocking/search-results.json +444 -444
  28. hestia_earth/models/pooreNemecek2018/excretaKgN.py +45 -41
  29. hestia_earth/models/pooreNemecek2018/excretaKgVs.py +89 -63
  30. hestia_earth/models/pooreNemecek2018/saplingsDepreciatedAmountPerCycle.py +8 -8
  31. hestia_earth/models/pooreNemecek2018/utils.py +60 -19
  32. hestia_earth/models/schererPfister2015/nErosionSoilFlux.py +4 -3
  33. hestia_earth/models/schererPfister2015/pErosionSoilFlux.py +4 -3
  34. hestia_earth/models/schererPfister2015/utils.py +12 -9
  35. hestia_earth/models/site/management.py +70 -55
  36. hestia_earth/models/site/pre_checks/cache_sources.py +2 -20
  37. hestia_earth/models/utils/__init__.py +12 -1
  38. hestia_earth/models/utils/aggregated.py +1 -1
  39. hestia_earth/models/utils/blank_node.py +20 -12
  40. hestia_earth/models/utils/cache_sources.py +15 -0
  41. hestia_earth/models/utils/crop.py +5 -0
  42. hestia_earth/models/utils/indicator.py +3 -1
  43. hestia_earth/models/version.py +1 -1
  44. {hestia_earth_models-0.64.14.dist-info → hestia_earth_models-0.65.0.dist-info}/METADATA +2 -2
  45. {hestia_earth_models-0.64.14.dist-info → hestia_earth_models-0.65.0.dist-info}/RECORD +75 -104
  46. tests/models/cml2001Baseline/test_abioticResourceDepletionMineralsAndMetals.py +1 -1
  47. tests/models/cycle/input/test_hestiaAggregatedData.py +5 -2
  48. tests/models/environmentalFootprintV3/test_soilQualityIndexLandTransformation.py +39 -28
  49. tests/models/{hyde32/test_landTransformationFromForest20YearAverageDuringCycle.py → faostat2018/test_landTransformation100YearAverageDuringCycle.py} +5 -5
  50. tests/models/{hyde32/test_landTransformationFromForest100YearAverageDuringCycle.py → faostat2018/test_landTransformation20YearAverageDuringCycle.py} +5 -5
  51. tests/models/faostat2018/test_utils.py +28 -0
  52. tests/models/hestia/test_landCover.py +2 -1
  53. tests/models/hestia/test_seed_emissions.py +27 -0
  54. tests/models/ipcc2019/test_aboveGroundBiomass.py +40 -4
  55. tests/models/ipcc2019/test_belowGroundBiomass.py +40 -4
  56. tests/models/ipcc2019/test_co2ToAirAboveGroundBiomassStockChange.py +52 -15
  57. tests/models/ipcc2019/test_co2ToAirBelowGroundBiomassStockChange.py +50 -14
  58. tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChange.py +53 -32
  59. tests/models/ipcc2019/test_organicCarbonPerHa.py +91 -108
  60. tests/models/ipcc2019/test_organicCarbonPerHa_tier_1_utils.py +33 -50
  61. tests/models/ipcc2019/test_organicCarbonPerHa_tier_2_utils.py +0 -52
  62. tests/models/linkedImpactAssessment/test_freshwaterWithdrawalsInputsProduction.py +6 -4
  63. tests/models/linkedImpactAssessment/test_landOccupationInputsProduction.py +6 -4
  64. tests/models/linkedImpactAssessment/{test_landTransformationFromForest100YearAverageInputsProduction.py → test_landTransformation100YearAverageInputsProduction.py} +7 -5
  65. tests/models/linkedImpactAssessment/{test_landTransformationFromForest20YearAverageInputsProduction.py → test_landTransformation20YearAverageInputsProduction.py} +7 -5
  66. tests/models/pooreNemecek2018/test_excretaKgN.py +2 -2
  67. tests/models/pooreNemecek2018/test_excretaKgVs.py +1 -1
  68. tests/models/pooreNemecek2018/test_utils.py +26 -0
  69. tests/models/site/test_management.py +10 -27
  70. tests/models/test_cache_sites.py +40 -12
  71. tests/models/utils/test_blank_node.py +0 -8
  72. tests/models/utils/test_cache_sources.py +21 -0
  73. hestia_earth/models/blonkConsultants2016/landTransformationFromForest20YearAverageDuringCycle.py +0 -90
  74. hestia_earth/models/faostat2018/landTransformationFromCropland100YearAverage.py +0 -74
  75. hestia_earth/models/faostat2018/landTransformationFromCropland20YearAverage.py +0 -74
  76. hestia_earth/models/hyde32/__init__.py +0 -13
  77. hestia_earth/models/hyde32/landTransformationFromCropland100YearAverageDuringCycle.py +0 -60
  78. hestia_earth/models/hyde32/landTransformationFromCropland20YearAverageDuringCycle.py +0 -60
  79. hestia_earth/models/hyde32/landTransformationFromForest100YearAverageDuringCycle.py +0 -60
  80. hestia_earth/models/hyde32/landTransformationFromForest20YearAverageDuringCycle.py +0 -60
  81. hestia_earth/models/hyde32/landTransformationFromOtherNaturalVegetation100YearAverageDuringCycle.py +0 -61
  82. hestia_earth/models/hyde32/landTransformationFromOtherNaturalVegetation20YearAverageDuringCycle.py +0 -61
  83. hestia_earth/models/hyde32/landTransformationFromPermanentPasture100YearAverageDuringCycle.py +0 -61
  84. hestia_earth/models/hyde32/landTransformationFromPermanentPasture20YearAverageDuringCycle.py +0 -61
  85. hestia_earth/models/hyde32/utils.py +0 -72
  86. hestia_earth/models/linkedImpactAssessment/landTransformationFromForest100YearAverageInputsProduction.py +0 -36
  87. hestia_earth/models/linkedImpactAssessment/landTransformationFromForest20YearAverageInputsProduction.py +0 -36
  88. hestia_earth/models/linkedImpactAssessment/landTransformationFromOtherNaturalVegetation100YearAverageInputsProduction.py +0 -36
  89. hestia_earth/models/linkedImpactAssessment/landTransformationFromOtherNaturalVegetation20YearAverageInputsProduction.py +0 -36
  90. hestia_earth/models/linkedImpactAssessment/landTransformationFromPermanentPasture100YearAverageInputsProduction.py +0 -36
  91. hestia_earth/models/linkedImpactAssessment/landTransformationFromPermanentPasture20YearAverageInputsProduction.py +0 -36
  92. tests/models/blonkConsultants2016/test_landTransformationFromForest20YearAverageDuringCycle.py +0 -36
  93. tests/models/cycle/pre_checks/test_cache_sources.py +0 -25
  94. tests/models/faostat2018/test_landTransformationFromCropland100YearAverage.py +0 -40
  95. tests/models/faostat2018/test_landTransformationFromCropland20YearAverage.py +0 -40
  96. tests/models/hyde32/__init__.py +0 -0
  97. tests/models/hyde32/test_landTransformationFromCropland100YearAverageDuringCycle.py +0 -21
  98. tests/models/hyde32/test_landTransformationFromCropland20YearAverageDuringCycle.py +0 -21
  99. tests/models/hyde32/test_landTransformationFromOtherNaturalVegetation100YearAverageDuringCycle.py +0 -23
  100. tests/models/hyde32/test_landTransformationFromOtherNaturalVegetation20YearAverageDuringCycle.py +0 -21
  101. tests/models/hyde32/test_landTransformationFromPermanentPasture100YearAverageDuringCycle.py +0 -21
  102. tests/models/hyde32/test_landTransformationFromPermanentPasture20YearAverageDuringCycle.py +0 -21
  103. tests/models/linkedImpactAssessment/test_landTransformationFromCropland100YearAverageInputsProduction.py +0 -23
  104. tests/models/linkedImpactAssessment/test_landTransformationFromCropland20YearAverageInputsProduction.py +0 -23
  105. tests/models/linkedImpactAssessment/test_landTransformationFromOtherNaturalVegetation100YearAverageInputsProduction.py +0 -23
  106. tests/models/linkedImpactAssessment/test_landTransformationFromOtherNaturalVegetation20YearAverageInputsProduction.py +0 -23
  107. tests/models/linkedImpactAssessment/test_landTransformationFromPermanentPasture100YearAverageInputsProduction.py +0 -24
  108. tests/models/linkedImpactAssessment/test_landTransformationFromPermanentPasture20YearAverageInputsProduction.py +0 -24
  109. tests/models/site/pre_checks/test_cache_sources.py +0 -21
  110. {hestia_earth_models-0.64.14.dist-info → hestia_earth_models-0.65.0.dist-info}/LICENSE +0 -0
  111. {hestia_earth_models-0.64.14.dist-info → hestia_earth_models-0.65.0.dist-info}/WHEEL +0 -0
  112. {hestia_earth_models-0.64.14.dist-info → hestia_earth_models-0.65.0.dist-info}/top_level.txt +0 -0
@@ -1,72 +0,0 @@
1
- from hestia_earth.schema import SiteSiteType
2
- from hestia_earth.utils.lookup import download_lookup, get_table_value, column_name, extract_grouped_data_closest_date
3
- from hestia_earth.utils.tools import safe_parse_float, safe_parse_date
4
-
5
- from hestia_earth.models.log import debugMissingLookup, debugValues, logRequirements, logShouldRun
6
- from hestia_earth.models.utils.indicator import _new_indicator
7
- from hestia_earth.models.utils.impact_assessment import get_product, get_site, get_region_id
8
- from hestia_earth.models.utils.cycle import land_occupation_per_kg
9
- from hestia_earth.models.utils.site import get_land_cover_term_id
10
- from . import MODEL
11
-
12
-
13
- def _get_emission_factor(term_id: str, impact_assessment: dict, average_years: str, from_site_type: SiteSiteType):
14
- end_date = safe_parse_date(impact_assessment.get('endDate'))
15
-
16
- site = get_site(impact_assessment)
17
- region_id = get_region_id(impact_assessment)
18
- to_site_type = site.get('siteType')
19
-
20
- if not to_site_type:
21
- # site type needed to get factors
22
- return None
23
-
24
- lookup_name = f"region-{to_site_type.replace(' ', '_')}-landTransformation{average_years}years.csv"
25
- lookup = download_lookup(lookup_name)
26
- value = get_table_value(lookup, 'termid', region_id, column_name(from_site_type.value))
27
- debugMissingLookup(lookup_name, 'termid', region_id, from_site_type.value, value, model=MODEL, term=term_id)
28
-
29
- return safe_parse_float(extract_grouped_data_closest_date(value, end_date.year), None) if end_date else None
30
-
31
-
32
- def _indicator(term_id: str, value: float, land_covert_term_id: str):
33
- indicator = _new_indicator(term_id, MODEL, land_covert_term_id)
34
- indicator['value'] = value
35
- return indicator
36
-
37
-
38
- def _run(impact_assessment: dict, term_id: str, land_occupation_m2: float, factor: float):
39
- land_covert_term_id = get_land_cover_term_id(get_site(impact_assessment).get('siteType'))
40
- value = land_occupation_m2 * (factor or 0)
41
- debugValues(impact_assessment, model=MODEL, term=term_id,
42
- value=value,
43
- land_covert_term_id=land_covert_term_id)
44
- return _indicator(term_id, value, land_covert_term_id)
45
-
46
-
47
- def _should_run(impact_assessment: dict, term_id: str, from_site_type: SiteSiteType, years: int):
48
- site = get_site(impact_assessment)
49
- has_site = bool(site)
50
- cycle = impact_assessment.get('cycle', {})
51
- product = get_product(impact_assessment)
52
- site = get_site(impact_assessment)
53
- land_occupation_m2_kg = land_occupation_per_kg(MODEL, term_id, cycle, site, product)
54
- land_transformation_factor = _get_emission_factor(term_id, impact_assessment, years, from_site_type)
55
-
56
- logRequirements(impact_assessment, model=MODEL, term=term_id,
57
- has_site=has_site,
58
- land_occupation_m2_kg=land_occupation_m2_kg,
59
- land_transformation_factor=land_transformation_factor)
60
-
61
- should_run = all([
62
- has_site,
63
- land_occupation_m2_kg is not None,
64
- land_occupation_m2_kg == 0 or land_transformation_factor is not None
65
- ])
66
- logShouldRun(impact_assessment, MODEL, term_id, should_run)
67
- return should_run, land_occupation_m2_kg, land_transformation_factor
68
-
69
-
70
- def run_land_transformation(impact_assessment: dict, term_id: str, from_site_type: SiteSiteType, years: int = 20):
71
- should_run, land_occupation_m2, factor = _should_run(impact_assessment, term_id, from_site_type, years)
72
- return [_run(impact_assessment, term_id, land_occupation_m2, factor)] if should_run else []
@@ -1,36 +0,0 @@
1
- from .utils import run_inputs_production
2
-
3
- REQUIREMENTS = {
4
- "ImpactAssessment": {
5
- "product": {"@type": "Term"},
6
- "cycle": {
7
- "@type": "Cycle",
8
- "products": [{
9
- "@type": "Product",
10
- "primary": "True",
11
- "value": "> 0",
12
- "economicValueShare": "> 0"
13
- }],
14
- "inputs": [{
15
- "@type": "Input",
16
- "impactAssessment": {
17
- "@type": "ImpactAssessment",
18
- "emissionsResourceUse": [{
19
- "@type": "Indicator",
20
- "term.@id": "landTransformationFromForest100YearAverageDuringCycle",
21
- "value": "> 0"
22
- }]
23
- }
24
- }]
25
- }
26
- }
27
- }
28
- RETURNS = {
29
- "Indicator": [{
30
- "value": ""
31
- }]
32
- }
33
- TERM_ID = 'landTransformationFromForest100YearAverageInputsProduction'
34
-
35
-
36
- def run(impact_assessment: dict): return run_inputs_production(impact_assessment, TERM_ID)
@@ -1,36 +0,0 @@
1
- from .utils import run_inputs_production
2
-
3
- REQUIREMENTS = {
4
- "ImpactAssessment": {
5
- "product": {"@type": "Term"},
6
- "cycle": {
7
- "@type": "Cycle",
8
- "products": [{
9
- "@type": "Product",
10
- "primary": "True",
11
- "value": "> 0",
12
- "economicValueShare": "> 0"
13
- }],
14
- "inputs": [{
15
- "@type": "Input",
16
- "impactAssessment": {
17
- "@type": "ImpactAssessment",
18
- "emissionsResourceUse": [{
19
- "@type": "Indicator",
20
- "term.@id": "landTransformationFromForest20YearAverageDuringCycle",
21
- "value": "> 0"
22
- }]
23
- }
24
- }]
25
- }
26
- }
27
- }
28
- RETURNS = {
29
- "Indicator": [{
30
- "value": ""
31
- }]
32
- }
33
- TERM_ID = 'landTransformationFromForest20YearAverageInputsProduction'
34
-
35
-
36
- def run(impact_assessment: dict): return run_inputs_production(impact_assessment, TERM_ID)
@@ -1,36 +0,0 @@
1
- from .utils import run_inputs_production
2
-
3
- REQUIREMENTS = {
4
- "ImpactAssessment": {
5
- "product": {"@type": "Term"},
6
- "cycle": {
7
- "@type": "Cycle",
8
- "products": [{
9
- "@type": "Product",
10
- "primary": "True",
11
- "value": "> 0",
12
- "economicValueShare": "> 0"
13
- }],
14
- "inputs": [{
15
- "@type": "Input",
16
- "impactAssessment": {
17
- "@type": "ImpactAssessment",
18
- "emissionsResourceUse": [{
19
- "@type": "Indicator",
20
- "term.@id": "landTransformationFromOtherNaturalVegetation100YearAverageDuringCycle",
21
- "value": "> 0"
22
- }]
23
- }
24
- }]
25
- }
26
- }
27
- }
28
- RETURNS = {
29
- "Indicator": [{
30
- "value": ""
31
- }]
32
- }
33
- TERM_ID = 'landTransformationFromOtherNaturalVegetation100YearAverageInputsProduction'
34
-
35
-
36
- def run(impact_assessment: dict): return run_inputs_production(impact_assessment, TERM_ID)
@@ -1,36 +0,0 @@
1
- from .utils import run_inputs_production
2
-
3
- REQUIREMENTS = {
4
- "ImpactAssessment": {
5
- "product": {"@type": "Term"},
6
- "cycle": {
7
- "@type": "Cycle",
8
- "products": [{
9
- "@type": "Product",
10
- "primary": "True",
11
- "value": "> 0",
12
- "economicValueShare": "> 0"
13
- }],
14
- "inputs": [{
15
- "@type": "Input",
16
- "impactAssessment": {
17
- "@type": "ImpactAssessment",
18
- "emissionsResourceUse": [{
19
- "@type": "Indicator",
20
- "term.@id": "landTransformationFromOtherNaturalVegetation20YearAverageDuringCycle",
21
- "value": "> 0"
22
- }]
23
- }
24
- }]
25
- }
26
- }
27
- }
28
- RETURNS = {
29
- "Indicator": [{
30
- "value": ""
31
- }]
32
- }
33
- TERM_ID = 'landTransformationFromOtherNaturalVegetation20YearAverageInputsProduction'
34
-
35
-
36
- def run(impact_assessment: dict): return run_inputs_production(impact_assessment, TERM_ID)
@@ -1,36 +0,0 @@
1
- from .utils import run_inputs_production
2
-
3
- REQUIREMENTS = {
4
- "ImpactAssessment": {
5
- "product": {"@type": "Term"},
6
- "cycle": {
7
- "@type": "Cycle",
8
- "products": [{
9
- "@type": "Product",
10
- "primary": "True",
11
- "value": "> 0",
12
- "economicValueShare": "> 0"
13
- }],
14
- "inputs": [{
15
- "@type": "Input",
16
- "impactAssessment": {
17
- "@type": "ImpactAssessment",
18
- "emissionsResourceUse": [{
19
- "@type": "Indicator",
20
- "term.@id": "landTransformationFromPermanentPasture100YearAverageDuringCycle",
21
- "value": "> 0"
22
- }]
23
- }
24
- }]
25
- }
26
- }
27
- }
28
- RETURNS = {
29
- "Indicator": [{
30
- "value": ""
31
- }]
32
- }
33
- TERM_ID = 'landTransformationFromPermanentPasture100YearAverageInputsProduction'
34
-
35
-
36
- def run(impact_assessment: dict): return run_inputs_production(impact_assessment, TERM_ID)
@@ -1,36 +0,0 @@
1
- from .utils import run_inputs_production
2
-
3
- REQUIREMENTS = {
4
- "ImpactAssessment": {
5
- "product": {"@type": "Term"},
6
- "cycle": {
7
- "@type": "Cycle",
8
- "products": [{
9
- "@type": "Product",
10
- "primary": "True",
11
- "value": "> 0",
12
- "economicValueShare": "> 0"
13
- }],
14
- "inputs": [{
15
- "@type": "Input",
16
- "impactAssessment": {
17
- "@type": "ImpactAssessment",
18
- "emissionsResourceUse": [{
19
- "@type": "Indicator",
20
- "term.@id": "landTransformationFromPermanentPasture20YearAverageDuringCycle",
21
- "value": "> 0"
22
- }]
23
- }
24
- }]
25
- }
26
- }
27
- }
28
- RETURNS = {
29
- "Indicator": [{
30
- "value": ""
31
- }]
32
- }
33
- TERM_ID = 'landTransformationFromPermanentPasture20YearAverageInputsProduction'
34
-
35
-
36
- def run(impact_assessment: dict): return run_inputs_production(impact_assessment, TERM_ID)
@@ -1,36 +0,0 @@
1
- from unittest.mock import patch
2
- import json
3
- from tests.utils import fixtures_path, fake_new_indicator
4
-
5
- from hestia_earth.models.blonkConsultants2016.landTransformationFromForest20YearAverageDuringCycle import (
6
- MODEL, TERM_ID, run, _should_run
7
- )
8
-
9
- class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
10
- fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
11
-
12
-
13
- @patch(f"{class_path}.land_occupation_per_kg", return_value=None)
14
- @patch(f"{class_path}.get_emission_factor", return_value=None)
15
- def test_should_run(mock_factor, mock_landOccupation):
16
- # with land occupation => no run
17
- mock_landOccupation.return_value = 10
18
- should_run, *args = _should_run({})
19
- assert not should_run
20
-
21
- # with emission factor => run
22
- mock_factor.return_value = 10
23
- should_run, *args = _should_run({})
24
- assert should_run is True
25
-
26
-
27
- @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
28
- def test_run(*args):
29
- with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
30
- cycle = json.load(f)
31
-
32
- with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
33
- expected = json.load(f)
34
-
35
- value = run(cycle)
36
- assert value == expected
@@ -1,25 +0,0 @@
1
- from unittest.mock import patch
2
-
3
- from hestia_earth.models.cycle.pre_checks.cache_sources import CACHE_KEY, CACHE_SOURCES_KEY, run, _should_run
4
-
5
- class_path = 'hestia_earth.models.cycle.pre_checks.cache_sources'
6
- sources = {'source a': {'@type': 'Source', '@id': 'source-1'}}
7
-
8
-
9
- @patch(f"{class_path}.find_sources")
10
- def test_should_run(mock_find_sources):
11
- # no sources => no run
12
- mock_find_sources.return_value = {}
13
- should_run, *args = _should_run({})
14
- assert not should_run
15
-
16
- # with sources => run
17
- mock_find_sources.return_value = sources
18
- should_run, *args = _should_run({})
19
- assert should_run is True
20
-
21
-
22
- @patch(f"{class_path}.find_sources", return_value=sources)
23
- def test_run(*args):
24
- result = run({})
25
- assert result.get(CACHE_KEY).get(CACHE_SOURCES_KEY) == sources
@@ -1,40 +0,0 @@
1
- from unittest.mock import patch
2
- import json
3
- from tests.utils import fixtures_path, fake_new_indicator
4
-
5
- from hestia_earth.models.faostat2018.landTransformationFromCropland100YearAverage import (
6
- MODEL, run, _should_run
7
- )
8
-
9
- class_path = f"hestia_earth.models.{MODEL}.landTransformationFromCropland100YearAverage"
10
- fixtures_folder = f"{fixtures_path}/{MODEL}/landTransformationFromCropland100YearAverage"
11
-
12
-
13
- @patch(f"{class_path}.find_term_match")
14
- def test_should_run(mock_find):
15
- # no indicator => no run
16
- mock_find.return_value = {}
17
- should_run, *args = _should_run({})
18
- assert not should_run
19
-
20
- # with indicator => run
21
- mock_find.return_value = {'value': 10}
22
- should_run, *args = _should_run({})
23
- assert should_run is True
24
-
25
- # with indicator value 0 => no run
26
- mock_find.return_value = {'value': 0}
27
- should_run, *args = _should_run({})
28
- assert not should_run
29
-
30
-
31
- @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
32
- def test_run(*args):
33
- with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
34
- cycle = json.load(f)
35
-
36
- with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
37
- expected = json.load(f)
38
-
39
- value = run(cycle)
40
- assert value == expected
@@ -1,40 +0,0 @@
1
- from unittest.mock import patch
2
- import json
3
- from tests.utils import fixtures_path, fake_new_indicator
4
-
5
- from hestia_earth.models.faostat2018.landTransformationFromCropland20YearAverage import (
6
- MODEL, run, _should_run
7
- )
8
-
9
- class_path = f"hestia_earth.models.{MODEL}.landTransformationFromCropland20YearAverage"
10
- fixtures_folder = f"{fixtures_path}/{MODEL}/landTransformationFromCropland20YearAverage"
11
-
12
-
13
- @patch(f"{class_path}.find_term_match")
14
- def test_should_run(mock_find):
15
- # no indicator => no run
16
- mock_find.return_value = {}
17
- should_run, *args = _should_run({})
18
- assert not should_run
19
-
20
- # with indicator => run
21
- mock_find.return_value = {'value': 10}
22
- should_run, *args = _should_run({})
23
- assert should_run is True
24
-
25
- # with indicator value 0 => no run
26
- mock_find.return_value = {'value': 0}
27
- should_run, *args = _should_run({})
28
- assert not should_run
29
-
30
-
31
- @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
32
- def test_run(*args):
33
- with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
34
- cycle = json.load(f)
35
-
36
- with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
37
- expected = json.load(f)
38
-
39
- value = run(cycle)
40
- assert value == expected
File without changes
@@ -1,21 +0,0 @@
1
- from unittest.mock import patch
2
- import json
3
- from tests.utils import fixtures_path, fake_new_indicator
4
-
5
- from hestia_earth.models.hyde32.landTransformationFromCropland100YearAverageDuringCycle import TERM_ID, run
6
-
7
- class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
8
- fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
9
-
10
-
11
- @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
12
- @patch('hestia_earth.models.hyde32.utils._new_indicator', side_effect=fake_new_indicator)
13
- def test_run(*args):
14
- with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
15
- cycle = json.load(f)
16
-
17
- with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
18
- expected = json.load(f)
19
-
20
- value = run(cycle)
21
- assert value == expected
@@ -1,21 +0,0 @@
1
- from unittest.mock import patch
2
- import json
3
- from tests.utils import fixtures_path, fake_new_indicator
4
-
5
- from hestia_earth.models.hyde32.landTransformationFromCropland20YearAverageDuringCycle import TERM_ID, run
6
-
7
- class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
8
- fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
9
-
10
-
11
- @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
12
- @patch('hestia_earth.models.hyde32.utils._new_indicator', side_effect=fake_new_indicator)
13
- def test_run(*args):
14
- with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
15
- cycle = json.load(f)
16
-
17
- with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
18
- expected = json.load(f)
19
-
20
- value = run(cycle)
21
- assert value == expected
@@ -1,23 +0,0 @@
1
- from unittest.mock import patch
2
- import json
3
- from tests.utils import fixtures_path, fake_new_indicator
4
-
5
- from hestia_earth.models.hyde32.landTransformationFromOtherNaturalVegetation100YearAverageDuringCycle import (
6
- TERM_ID, run
7
- )
8
-
9
- class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
10
- fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
11
-
12
-
13
- @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
14
- @patch('hestia_earth.models.hyde32.utils._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
- cycle = 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(cycle)
23
- assert value == expected
@@ -1,21 +0,0 @@
1
- from unittest.mock import patch
2
- import json
3
- from tests.utils import fixtures_path, fake_new_indicator
4
-
5
- from hestia_earth.models.hyde32.landTransformationFromOtherNaturalVegetation20YearAverageDuringCycle import TERM_ID, run
6
-
7
- class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
8
- fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
9
-
10
-
11
- @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
12
- @patch('hestia_earth.models.hyde32.utils._new_indicator', side_effect=fake_new_indicator)
13
- def test_run(*args):
14
- with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
15
- cycle = json.load(f)
16
-
17
- with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
18
- expected = json.load(f)
19
-
20
- value = run(cycle)
21
- assert value == expected
@@ -1,21 +0,0 @@
1
- from unittest.mock import patch
2
- import json
3
- from tests.utils import fixtures_path, fake_new_indicator
4
-
5
- from hestia_earth.models.hyde32.landTransformationFromPermanentPasture100YearAverageDuringCycle import TERM_ID, run
6
-
7
- class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
8
- fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
9
-
10
-
11
- @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
12
- @patch('hestia_earth.models.hyde32.utils._new_indicator', side_effect=fake_new_indicator)
13
- def test_run(*args):
14
- with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
15
- cycle = json.load(f)
16
-
17
- with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
18
- expected = json.load(f)
19
-
20
- value = run(cycle)
21
- assert value == expected
@@ -1,21 +0,0 @@
1
- from unittest.mock import patch
2
- import json
3
- from tests.utils import fixtures_path, fake_new_indicator
4
-
5
- from hestia_earth.models.hyde32.landTransformationFromPermanentPasture20YearAverageDuringCycle import TERM_ID, run
6
-
7
- class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
8
- fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
9
-
10
-
11
- @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
12
- @patch('hestia_earth.models.hyde32.utils._new_indicator', side_effect=fake_new_indicator)
13
- def test_run(*args):
14
- with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
15
- cycle = json.load(f)
16
-
17
- with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
18
- expected = json.load(f)
19
-
20
- value = run(cycle)
21
- assert value == expected
@@ -1,23 +0,0 @@
1
- from unittest.mock import patch
2
- import json
3
- from tests.utils import fixtures_path, fake_new_indicator, fake_load_impacts
4
-
5
- from hestia_earth.models.linkedImpactAssessment.landTransformationFromCropland100YearAverageInputsProduction import (
6
- TERM_ID, run
7
- )
8
-
9
- class_path = f"hestia_earth.models.linkedImpactAssessment.{TERM_ID}"
10
- fixtures_folder = f"{fixtures_path}/linkedImpactAssessment/{TERM_ID}"
11
-
12
-
13
- @patch('hestia_earth.models.utils.input.load_impacts', side_effect=fake_load_impacts)
14
- @patch('hestia_earth.models.linkedImpactAssessment.utils._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
@@ -1,23 +0,0 @@
1
- from unittest.mock import patch
2
- import json
3
- from tests.utils import fixtures_path, fake_new_indicator, fake_load_impacts
4
-
5
- from hestia_earth.models.linkedImpactAssessment.landTransformationFromCropland20YearAverageInputsProduction import (
6
- TERM_ID, run
7
- )
8
-
9
- class_path = f"hestia_earth.models.linkedImpactAssessment.{TERM_ID}"
10
- fixtures_folder = f"{fixtures_path}/linkedImpactAssessment/{TERM_ID}"
11
-
12
-
13
- @patch('hestia_earth.models.utils.input.load_impacts', side_effect=fake_load_impacts)
14
- @patch('hestia_earth.models.linkedImpactAssessment.utils._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
@@ -1,23 +0,0 @@
1
- from unittest.mock import patch
2
- import json
3
- from tests.utils import fixtures_path, fake_new_indicator, fake_load_impacts
4
-
5
- from hestia_earth.models.linkedImpactAssessment.landTransformationFromOtherNaturalVegetation100YearAverageInputsProduction import ( # noqa: E501
6
- TERM_ID, run
7
- )
8
-
9
- class_path = f"hestia_earth.models.linkedImpactAssessment.{TERM_ID}"
10
- fixtures_folder = f"{fixtures_path}/linkedImpactAssessment/{TERM_ID}"
11
-
12
-
13
- @patch('hestia_earth.models.utils.input.load_impacts', side_effect=fake_load_impacts)
14
- @patch('hestia_earth.models.linkedImpactAssessment.utils._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