hestia-earth-models 0.60.1__py3-none-any.whl → 0.61.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.
- hestia_earth/models/cycle/cycleDuration.py +61 -22
- hestia_earth/models/cycle/startDate.py +16 -11
- hestia_earth/models/cycle/startDateDefinition.py +69 -0
- hestia_earth/models/impact_assessment/emissions.py +1 -3
- hestia_earth/models/ipcc2019/pastureGrass.py +1 -1
- hestia_earth/models/linkedImpactAssessment/__init__.py +8 -162
- hestia_earth/models/linkedImpactAssessment/emissions.py +168 -0
- hestia_earth/models/{impact_assessment → linkedImpactAssessment}/utils.py +1 -1
- hestia_earth/models/mocking/search-results.json +257 -229
- hestia_earth/models/{impact_assessment → pooreNemecek2018}/freshwaterWithdrawalsDuringCycle.py +1 -1
- hestia_earth/models/site/brackishWater.py +43 -0
- hestia_earth/models/site/freshWater.py +43 -0
- hestia_earth/models/site/salineWater.py +43 -0
- hestia_earth/models/utils/__init__.py +4 -4
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.60.1.dist-info → hestia_earth_models-0.61.1.dist-info}/METADATA +2 -2
- {hestia_earth_models-0.60.1.dist-info → hestia_earth_models-0.61.1.dist-info}/RECORD +49 -41
- tests/models/cycle/test_cycleDuration.py +15 -27
- tests/models/cycle/test_startDate.py +7 -7
- tests/models/cycle/test_startDateDefinition.py +31 -0
- tests/models/linkedImpactAssessment/__init__.py +0 -0
- tests/models/linkedImpactAssessment/test_emissions.py +22 -0
- tests/models/{impact_assessment → linkedImpactAssessment}/test_freshwaterWithdrawalsInputsProduction.py +4 -4
- tests/models/{impact_assessment → linkedImpactAssessment}/test_landOccupationInputsProduction.py +4 -4
- tests/models/{impact_assessment → linkedImpactAssessment}/test_landTransformationFromCropland100YearAverageInputsProduction.py +4 -4
- tests/models/{impact_assessment → linkedImpactAssessment}/test_landTransformationFromCropland20YearAverageInputsProduction.py +4 -4
- tests/models/{impact_assessment → linkedImpactAssessment}/test_landTransformationFromForest100YearAverageInputsProduction.py +4 -4
- tests/models/{impact_assessment → linkedImpactAssessment}/test_landTransformationFromForest20YearAverageInputsProduction.py +4 -4
- tests/models/{impact_assessment → linkedImpactAssessment}/test_landTransformationFromOtherNaturalVegetation100YearAverageInputsProduction.py +4 -4
- tests/models/{impact_assessment → linkedImpactAssessment}/test_landTransformationFromOtherNaturalVegetation20YearAverageInputsProduction.py +4 -4
- tests/models/linkedImpactAssessment/test_landTransformationFromPermanentPasture100YearAverageInputsProduction.py +24 -0
- tests/models/linkedImpactAssessment/test_landTransformationFromPermanentPasture20YearAverageInputsProduction.py +24 -0
- tests/models/{impact_assessment → pooreNemecek2018}/test_freshwaterWithdrawalsDuringCycle.py +1 -1
- tests/models/site/test_brackishWater.py +32 -0
- tests/models/site/test_freshWater.py +32 -0
- tests/models/site/test_salineWater.py +32 -0
- hestia_earth/models/cycle/endDate.py +0 -50
- tests/models/cycle/test_endDate.py +0 -24
- tests/models/impact_assessment/test_landTransformationFromPermanentPasture100YearAverageInputsProduction.py +0 -23
- tests/models/impact_assessment/test_landTransformationFromPermanentPasture20YearAverageInputsProduction.py +0 -23
- tests/models/test_linkedImpactAssessment.py +0 -33
- /hestia_earth/models/{impact_assessment → linkedImpactAssessment}/freshwaterWithdrawalsInputsProduction.py +0 -0
- /hestia_earth/models/{impact_assessment → linkedImpactAssessment}/landOccupationInputsProduction.py +0 -0
- /hestia_earth/models/{impact_assessment → linkedImpactAssessment}/landTransformationFromCropland100YearAverageInputsProduction.py +0 -0
- /hestia_earth/models/{impact_assessment → linkedImpactAssessment}/landTransformationFromCropland20YearAverageInputsProduction.py +0 -0
- /hestia_earth/models/{impact_assessment → linkedImpactAssessment}/landTransformationFromForest100YearAverageInputsProduction.py +0 -0
- /hestia_earth/models/{impact_assessment → linkedImpactAssessment}/landTransformationFromForest20YearAverageInputsProduction.py +0 -0
- /hestia_earth/models/{impact_assessment → linkedImpactAssessment}/landTransformationFromOtherNaturalVegetation100YearAverageInputsProduction.py +0 -0
- /hestia_earth/models/{impact_assessment → linkedImpactAssessment}/landTransformationFromOtherNaturalVegetation20YearAverageInputsProduction.py +0 -0
- /hestia_earth/models/{impact_assessment → linkedImpactAssessment}/landTransformationFromPermanentPasture100YearAverageInputsProduction.py +0 -0
- /hestia_earth/models/{impact_assessment → linkedImpactAssessment}/landTransformationFromPermanentPasture20YearAverageInputsProduction.py +0 -0
- {hestia_earth_models-0.60.1.dist-info → hestia_earth_models-0.61.1.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.60.1.dist-info → hestia_earth_models-0.61.1.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.60.1.dist-info → hestia_earth_models-0.61.1.dist-info}/top_level.txt +0 -0
|
@@ -2,16 +2,16 @@ from unittest.mock import patch
|
|
|
2
2
|
import json
|
|
3
3
|
from tests.utils import fixtures_path, fake_new_indicator, fake_load_impacts
|
|
4
4
|
|
|
5
|
-
from hestia_earth.models.
|
|
5
|
+
from hestia_earth.models.linkedImpactAssessment.landTransformationFromCropland20YearAverageInputsProduction import (
|
|
6
6
|
TERM_ID, run
|
|
7
7
|
)
|
|
8
8
|
|
|
9
|
-
class_path = f"hestia_earth.models.
|
|
10
|
-
fixtures_folder = f"{fixtures_path}/
|
|
9
|
+
class_path = f"hestia_earth.models.linkedImpactAssessment.{TERM_ID}"
|
|
10
|
+
fixtures_folder = f"{fixtures_path}/linkedImpactAssessment/{TERM_ID}"
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
@patch('hestia_earth.models.utils.input.load_impacts', side_effect=fake_load_impacts)
|
|
14
|
-
@patch('hestia_earth.models.
|
|
14
|
+
@patch('hestia_earth.models.linkedImpactAssessment.utils._new_indicator', side_effect=fake_new_indicator)
|
|
15
15
|
def test_run(*args):
|
|
16
16
|
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
|
17
17
|
impact = json.load(f)
|
|
@@ -2,16 +2,16 @@ from unittest.mock import patch
|
|
|
2
2
|
import json
|
|
3
3
|
from tests.utils import fixtures_path, fake_new_indicator, fake_load_impacts
|
|
4
4
|
|
|
5
|
-
from hestia_earth.models.
|
|
5
|
+
from hestia_earth.models.linkedImpactAssessment.landTransformationFromForest100YearAverageInputsProduction import (
|
|
6
6
|
TERM_ID, run
|
|
7
7
|
)
|
|
8
8
|
|
|
9
|
-
class_path = f"hestia_earth.models.
|
|
10
|
-
fixtures_folder = f"{fixtures_path}/
|
|
9
|
+
class_path = f"hestia_earth.models.linkedImpactAssessment.{TERM_ID}"
|
|
10
|
+
fixtures_folder = f"{fixtures_path}/linkedImpactAssessment/{TERM_ID}"
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
@patch('hestia_earth.models.utils.input.load_impacts', side_effect=fake_load_impacts)
|
|
14
|
-
@patch('hestia_earth.models.
|
|
14
|
+
@patch('hestia_earth.models.linkedImpactAssessment.utils._new_indicator', side_effect=fake_new_indicator)
|
|
15
15
|
def test_run(*args):
|
|
16
16
|
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
|
17
17
|
impact = json.load(f)
|
|
@@ -2,16 +2,16 @@ from unittest.mock import patch
|
|
|
2
2
|
import json
|
|
3
3
|
from tests.utils import fixtures_path, fake_new_indicator, fake_load_impacts
|
|
4
4
|
|
|
5
|
-
from hestia_earth.models.
|
|
5
|
+
from hestia_earth.models.linkedImpactAssessment.landTransformationFromForest20YearAverageInputsProduction import (
|
|
6
6
|
TERM_ID, run
|
|
7
7
|
)
|
|
8
8
|
|
|
9
|
-
class_path = f"hestia_earth.models.
|
|
10
|
-
fixtures_folder = f"{fixtures_path}/
|
|
9
|
+
class_path = f"hestia_earth.models.linkedImpactAssessment.{TERM_ID}"
|
|
10
|
+
fixtures_folder = f"{fixtures_path}/linkedImpactAssessment/{TERM_ID}"
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
@patch('hestia_earth.models.utils.input.load_impacts', side_effect=fake_load_impacts)
|
|
14
|
-
@patch('hestia_earth.models.
|
|
14
|
+
@patch('hestia_earth.models.linkedImpactAssessment.utils._new_indicator', side_effect=fake_new_indicator)
|
|
15
15
|
def test_run(*args):
|
|
16
16
|
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
|
17
17
|
impact = json.load(f)
|
|
@@ -2,16 +2,16 @@ from unittest.mock import patch
|
|
|
2
2
|
import json
|
|
3
3
|
from tests.utils import fixtures_path, fake_new_indicator, fake_load_impacts
|
|
4
4
|
|
|
5
|
-
from hestia_earth.models.
|
|
5
|
+
from hestia_earth.models.linkedImpactAssessment.landTransformationFromOtherNaturalVegetation100YearAverageInputsProduction import ( # noqa: E501
|
|
6
6
|
TERM_ID, run
|
|
7
7
|
)
|
|
8
8
|
|
|
9
|
-
class_path = f"hestia_earth.models.
|
|
10
|
-
fixtures_folder = f"{fixtures_path}/
|
|
9
|
+
class_path = f"hestia_earth.models.linkedImpactAssessment.{TERM_ID}"
|
|
10
|
+
fixtures_folder = f"{fixtures_path}/linkedImpactAssessment/{TERM_ID}"
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
@patch('hestia_earth.models.utils.input.load_impacts', side_effect=fake_load_impacts)
|
|
14
|
-
@patch('hestia_earth.models.
|
|
14
|
+
@patch('hestia_earth.models.linkedImpactAssessment.utils._new_indicator', side_effect=fake_new_indicator)
|
|
15
15
|
def test_run(*args):
|
|
16
16
|
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
|
17
17
|
impact = json.load(f)
|
|
@@ -2,16 +2,16 @@ from unittest.mock import patch
|
|
|
2
2
|
import json
|
|
3
3
|
from tests.utils import fixtures_path, fake_new_indicator, fake_load_impacts
|
|
4
4
|
|
|
5
|
-
from hestia_earth.models.
|
|
5
|
+
from hestia_earth.models.linkedImpactAssessment.landTransformationFromOtherNaturalVegetation20YearAverageInputsProduction import ( # noqa: E501
|
|
6
6
|
TERM_ID, run
|
|
7
7
|
)
|
|
8
8
|
|
|
9
|
-
class_path = f"hestia_earth.models.
|
|
10
|
-
fixtures_folder = f"{fixtures_path}/
|
|
9
|
+
class_path = f"hestia_earth.models.linkedImpactAssessment.{TERM_ID}"
|
|
10
|
+
fixtures_folder = f"{fixtures_path}/linkedImpactAssessment/{TERM_ID}"
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
@patch('hestia_earth.models.utils.input.load_impacts', side_effect=fake_load_impacts)
|
|
14
|
-
@patch('hestia_earth.models.
|
|
14
|
+
@patch('hestia_earth.models.linkedImpactAssessment.utils._new_indicator', side_effect=fake_new_indicator)
|
|
15
15
|
def test_run(*args):
|
|
16
16
|
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
|
17
17
|
impact = json.load(f)
|
|
@@ -0,0 +1,24 @@
|
|
|
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 import (
|
|
6
|
+
landTransformationFromPermanentPasture100YearAverageInputsProduction
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
TERM_ID = landTransformationFromPermanentPasture100YearAverageInputsProduction.TERM_ID
|
|
10
|
+
class_path = f"hestia_earth.models.linkedImpactAssessment.{TERM_ID}"
|
|
11
|
+
fixtures_folder = f"{fixtures_path}/linkedImpactAssessment/{TERM_ID}"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@patch('hestia_earth.models.utils.input.load_impacts', side_effect=fake_load_impacts)
|
|
15
|
+
@patch('hestia_earth.models.linkedImpactAssessment.utils._new_indicator', side_effect=fake_new_indicator)
|
|
16
|
+
def test_run(*args):
|
|
17
|
+
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
|
18
|
+
impact = json.load(f)
|
|
19
|
+
|
|
20
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
|
21
|
+
expected = json.load(f)
|
|
22
|
+
|
|
23
|
+
value = landTransformationFromPermanentPasture100YearAverageInputsProduction.run(impact)
|
|
24
|
+
assert value == expected
|
|
@@ -0,0 +1,24 @@
|
|
|
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 import (
|
|
6
|
+
landTransformationFromPermanentPasture20YearAverageInputsProduction
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
TERM_ID = landTransformationFromPermanentPasture20YearAverageInputsProduction.TERM_ID
|
|
10
|
+
class_path = f"hestia_earth.models.linkedImpactAssessment.{TERM_ID}"
|
|
11
|
+
fixtures_folder = f"{fixtures_path}/linkedImpactAssessment/{TERM_ID}"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@patch('hestia_earth.models.utils.input.load_impacts', side_effect=fake_load_impacts)
|
|
15
|
+
@patch('hestia_earth.models.linkedImpactAssessment.utils._new_indicator', side_effect=fake_new_indicator)
|
|
16
|
+
def test_run(*args):
|
|
17
|
+
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
|
18
|
+
impact = json.load(f)
|
|
19
|
+
|
|
20
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
|
21
|
+
expected = json.load(f)
|
|
22
|
+
|
|
23
|
+
value = landTransformationFromPermanentPasture20YearAverageInputsProduction.run(impact)
|
|
24
|
+
assert value == expected
|
tests/models/{impact_assessment → pooreNemecek2018}/test_freshwaterWithdrawalsDuringCycle.py
RENAMED
|
@@ -2,7 +2,7 @@ from unittest.mock import patch
|
|
|
2
2
|
import json
|
|
3
3
|
from tests.utils import fixtures_path, fake_new_indicator
|
|
4
4
|
|
|
5
|
-
from hestia_earth.models.
|
|
5
|
+
from hestia_earth.models.pooreNemecek2018.freshwaterWithdrawalsDuringCycle import MODEL, TERM_ID, run, _should_run
|
|
6
6
|
|
|
7
7
|
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
|
8
8
|
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
import json
|
|
3
|
+
from tests.utils import fixtures_path, fake_new_measurement
|
|
4
|
+
|
|
5
|
+
from hestia_earth.models.site.brackishWater import MODEL, TERM_ID, _should_run, run
|
|
6
|
+
|
|
7
|
+
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
|
8
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_should_run():
|
|
12
|
+
# no measuremrent => no run
|
|
13
|
+
site = {'measurements': []}
|
|
14
|
+
should_run = _should_run(site)
|
|
15
|
+
assert not should_run
|
|
16
|
+
|
|
17
|
+
# with measuremrent => run
|
|
18
|
+
site = {'measurements': [{'term': {'@id': 'waterSalinity'}, 'value': [1500]}]}
|
|
19
|
+
should_run = _should_run(site)
|
|
20
|
+
assert should_run is True
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@patch(f"{class_path}._new_measurement", side_effect=fake_new_measurement)
|
|
24
|
+
def test_run(*args):
|
|
25
|
+
with open(f"{fixtures_folder}/site.jsonld", encoding='utf-8') as f:
|
|
26
|
+
site = json.load(f)
|
|
27
|
+
|
|
28
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
|
29
|
+
expected = json.load(f)
|
|
30
|
+
|
|
31
|
+
value = run(site)
|
|
32
|
+
assert value == expected
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
import json
|
|
3
|
+
from tests.utils import fixtures_path, fake_new_measurement
|
|
4
|
+
|
|
5
|
+
from hestia_earth.models.site.freshWater import MODEL, TERM_ID, _should_run, run
|
|
6
|
+
|
|
7
|
+
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
|
8
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_should_run():
|
|
12
|
+
# no measuremrent => no run
|
|
13
|
+
site = {'measurements': []}
|
|
14
|
+
should_run = _should_run(site)
|
|
15
|
+
assert not should_run
|
|
16
|
+
|
|
17
|
+
# with measuremrent => run
|
|
18
|
+
site = {'measurements': [{'term': {'@id': 'waterSalinity'}, 'value': [200]}]}
|
|
19
|
+
should_run = _should_run(site)
|
|
20
|
+
assert should_run is True
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@patch(f"{class_path}._new_measurement", side_effect=fake_new_measurement)
|
|
24
|
+
def test_run(*args):
|
|
25
|
+
with open(f"{fixtures_folder}/site.jsonld", encoding='utf-8') as f:
|
|
26
|
+
site = json.load(f)
|
|
27
|
+
|
|
28
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
|
29
|
+
expected = json.load(f)
|
|
30
|
+
|
|
31
|
+
value = run(site)
|
|
32
|
+
assert value == expected
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
import json
|
|
3
|
+
from tests.utils import fixtures_path, fake_new_measurement
|
|
4
|
+
|
|
5
|
+
from hestia_earth.models.site.salineWater import MODEL, TERM_ID, _should_run, run
|
|
6
|
+
|
|
7
|
+
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
|
8
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_should_run():
|
|
12
|
+
# no measuremrent => no run
|
|
13
|
+
site = {'measurements': []}
|
|
14
|
+
should_run = _should_run(site)
|
|
15
|
+
assert not should_run
|
|
16
|
+
|
|
17
|
+
# with measuremrent => run
|
|
18
|
+
site = {'measurements': [{'term': {'@id': 'waterSalinity'}, 'value': [20000]}]}
|
|
19
|
+
should_run = _should_run(site)
|
|
20
|
+
assert should_run is True
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@patch(f"{class_path}._new_measurement", side_effect=fake_new_measurement)
|
|
24
|
+
def test_run(*args):
|
|
25
|
+
with open(f"{fixtures_folder}/site.jsonld", encoding='utf-8') as f:
|
|
26
|
+
site = json.load(f)
|
|
27
|
+
|
|
28
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
|
29
|
+
expected = json.load(f)
|
|
30
|
+
|
|
31
|
+
value = run(site)
|
|
32
|
+
assert value == expected
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Start Date
|
|
3
|
-
|
|
4
|
-
This model updates the [Cycle endDate](https://hestia.earth/schema/Cycle#endDate) to be in the following format:
|
|
5
|
-
`YYYY-MM-DD`.
|
|
6
|
-
"""
|
|
7
|
-
from hestia_earth.utils.date import is_in_days
|
|
8
|
-
from hestia_earth.utils.tools import non_empty_list
|
|
9
|
-
|
|
10
|
-
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
11
|
-
from hestia_earth.models.utils import last_day_of_month
|
|
12
|
-
from . import MODEL
|
|
13
|
-
|
|
14
|
-
REQUIREMENTS = {
|
|
15
|
-
"Cycle": {
|
|
16
|
-
"endDate": ""
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
RETURNS = {
|
|
20
|
-
"The endDate as a string": ""
|
|
21
|
-
}
|
|
22
|
-
MODEL_KEY = 'endDate'
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def _last_day(date: str):
|
|
26
|
-
last_day = last_day_of_month(date[0:4], date[5:7])
|
|
27
|
-
return str(last_day.day)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def _run(cycle: dict):
|
|
31
|
-
value = cycle.get('endDate')
|
|
32
|
-
month = '12' if len(value) == 4 else ''
|
|
33
|
-
day = '31' if len(value) == 4 else _last_day(value)
|
|
34
|
-
return '-'.join(non_empty_list([value, month, day]))
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def _should_run(cycle: dict):
|
|
38
|
-
has_endDate = cycle.get('endDate') is not None
|
|
39
|
-
has_incorrect_format = has_endDate and not is_in_days(cycle.get('endDate'))
|
|
40
|
-
|
|
41
|
-
logRequirements(cycle, model=MODEL, key=MODEL_KEY,
|
|
42
|
-
has_endDate=has_endDate,
|
|
43
|
-
has_incorrect_format=has_incorrect_format)
|
|
44
|
-
|
|
45
|
-
should_run = all([has_endDate, has_incorrect_format])
|
|
46
|
-
logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY)
|
|
47
|
-
return should_run
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def run(cycle: dict): return _run(cycle) if _should_run(cycle) else None
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
from hestia_earth.models.cycle.endDate import _should_run, run
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def test_should_run():
|
|
5
|
-
# no endDate => no run
|
|
6
|
-
cycle = {}
|
|
7
|
-
should_run = _should_run(cycle)
|
|
8
|
-
assert not should_run
|
|
9
|
-
|
|
10
|
-
# with endDate full date => no run
|
|
11
|
-
cycle['endDate'] = '2020-01-01'
|
|
12
|
-
should_run = _should_run(cycle)
|
|
13
|
-
assert not should_run
|
|
14
|
-
|
|
15
|
-
# with endDate missing days => run
|
|
16
|
-
cycle['endDate'] = '2020-01'
|
|
17
|
-
should_run = _should_run(cycle)
|
|
18
|
-
assert should_run is True
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def test_run():
|
|
22
|
-
assert run({'endDate': '2020-01'}) == '2020-01-31'
|
|
23
|
-
assert run({'endDate': '2020-02'}) == '2020-02-29'
|
|
24
|
-
assert run({'endDate': '2020'}) == '2020-12-31'
|
|
@@ -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.impact_assessment.landTransformationFromPermanentPasture100YearAverageInputsProduction import (
|
|
6
|
-
TERM_ID, run
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
class_path = f"hestia_earth.models.impact_assessment.{TERM_ID}"
|
|
10
|
-
fixtures_folder = f"{fixtures_path}/impact_assessment/{TERM_ID}"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
@patch('hestia_earth.models.utils.input.load_impacts', side_effect=fake_load_impacts)
|
|
14
|
-
@patch('hestia_earth.models.impact_assessment.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.impact_assessment.landTransformationFromPermanentPasture20YearAverageInputsProduction import (
|
|
6
|
-
TERM_ID, run
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
class_path = f"hestia_earth.models.impact_assessment.{TERM_ID}"
|
|
10
|
-
fixtures_folder = f"{fixtures_path}/impact_assessment/{TERM_ID}"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
@patch('hestia_earth.models.utils.input.load_impacts', side_effect=fake_load_impacts)
|
|
14
|
-
@patch('hestia_earth.models.impact_assessment.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,33 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import json
|
|
3
|
-
from unittest.mock import patch
|
|
4
|
-
from hestia_earth.utils.tools import non_empty_list
|
|
5
|
-
from tests.utils import fixtures_path, fake_new_emission
|
|
6
|
-
|
|
7
|
-
from hestia_earth.models.linkedImpactAssessment import MODEL, run
|
|
8
|
-
|
|
9
|
-
class_path = f"hestia_earth.models.{MODEL}"
|
|
10
|
-
fixtures_folder = os.path.join(fixtures_path, MODEL)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def fake_load_impacts(inputs):
|
|
14
|
-
def _load_impact(input: dict):
|
|
15
|
-
impact = input.get('impactAssessment')
|
|
16
|
-
if impact:
|
|
17
|
-
node_id = impact.get('@id', impact.get('id'))
|
|
18
|
-
with open(f"{fixtures_path}/impact_assessment/{node_id}.jsonld", encoding='utf-8') as f:
|
|
19
|
-
return {**input, 'impactAssessment': json.load(f)}
|
|
20
|
-
return non_empty_list(map(_load_impact, inputs))
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@patch(F"{class_path}.load_impacts", side_effect=fake_load_impacts)
|
|
24
|
-
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
|
25
|
-
def test_run(*args):
|
|
26
|
-
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
|
27
|
-
cycle = json.load(f)
|
|
28
|
-
|
|
29
|
-
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
|
30
|
-
expected = json.load(f)
|
|
31
|
-
|
|
32
|
-
result = run('all', cycle)
|
|
33
|
-
assert result == expected
|
|
File without changes
|
/hestia_earth/models/{impact_assessment → linkedImpactAssessment}/landOccupationInputsProduction.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|