Skip to content

Commit

Permalink
Merge branch 'undefined'
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Nov 5, 2024
2 parents e871e7e + 001c67e commit 33c69c6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ dmypy.json
.pyre/

dev
ecoinvent_interface/data/
ecoinvent_interface/data/mappings/
10 changes: 8 additions & 2 deletions ecoinvent_interface/process_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,22 @@ class ProcessFileType(Enum):
ZIPPED_FILE_TYPES = (ProcessFileType.lci, ProcessFileType.lcia, ProcessFileType.upr)


def as_tuple(version_string: str) -> tuple[int, int]:
return tuple([int(x) for x in version_string.split(".")])


class EcoinventProcess(InterfaceBase):
def set_release(self, version: str, system_model: str) -> None:
if version not in self.list_versions():
raise ValueError(f"Given version {version} not found")
self.version = version

system_model = SYSTEM_MODELS.get(system_model, system_model)
if system_model not in self.list_system_models(self.version):
if system_model == "undefined" and as_tuple(version) >= (3, 10):
pass
elif system_model not in self.list_system_models(self.version):
raise ValueError(
f"Given system model '{system_model}' not available in {version}"
f"Given system model '{system_model}' not available in {version}" # NOQA E713
)
self.system_model = system_model

Expand Down
38 changes: 37 additions & 1 deletion tests/test_process_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
from pypdf import PdfReader

from ecoinvent_interface import EcoinventProcess, ProcessFileType, Settings
from ecoinvent_interface.process_interface import MissingProcess, get_cached_mapping
from ecoinvent_interface.process_interface import (
MissingProcess,
as_tuple,
get_cached_mapping,
)
from ecoinvent_interface.storage import md5

try:
Expand All @@ -27,6 +31,17 @@ def process(tmp_path):
return ep


@pytest.fixture
def undefined(tmp_path):
get_cached_mapping.cache_clear()

settings = Settings(output_path=str(tmp_path))
custom_headers = {"ecoinvent-api-client-library-is-test": "true"}
ep = EcoinventProcess(settings=settings, custom_headers=custom_headers)
ep.set_release(version="3.10", system_model="undefined")
return ep


@pytest.fixture
def nuclear(process):
process.select_process(dataset_id="1")
Expand Down Expand Up @@ -145,6 +160,22 @@ def test_get_basic_info(nuclear):
assert nuclear.get_basic_info() == expected


def test_get_basic_info_undefined(undefined):
undefined.select_process(dataset_id="42140")
expected = {
"index": 42140,
"version": "3.10",
"system_model": "undefined",
"activity_name": "1,1-difluoroethane production",
"geography": {"comment": None, "short_name": "GLO", "long_name": "Global"},
"reference_product": "",
"has_access": True,
"unit": None,
"sector": "Chemicals",
}
assert undefined.get_basic_info() == expected


def test_get_documentation(nuclear):
result = nuclear.get_documentation()
assert result["id"] == "b0eb27dd-b87f-4ae9-9f69-57d811443a30"
Expand Down Expand Up @@ -183,3 +214,8 @@ def test_get_file_undefined(nuclear, tmp_path):
# Manually verified to be readable and correct type
assert md5(fp) == "052f51f3fbb79a13a78753e9ff40428a"
assert PdfReader(fp)


def test_as_tuple():
assert as_tuple("3.10") == (3, 10)
assert as_tuple("3.10") > (3, 9)

0 comments on commit 33c69c6

Please sign in to comment.