diff --git a/tests/helpers/samples/artefact.py b/tests/helpers/samples/artefact.py index e6acf59..e48fd86 100644 --- a/tests/helpers/samples/artefact.py +++ b/tests/helpers/samples/artefact.py @@ -1,5 +1,5 @@ +from tests.helpers.samples.dumps import read_emu_extract from tests.helpers.samples.image import SAMPLE_IMAGE_ID -from tests.helpers.samples.utils import read_emu_extract # this is taken from ecatalogue.export.20170830.gz but with the MulMultiMediaRefs # replaced with a single reference to the SAMPLE_IMAGE_ID diff --git a/tests/helpers/samples/dumps.py b/tests/helpers/samples/dumps.py index 1f2d6fa..36b28ea 100644 --- a/tests/helpers/samples/dumps.py +++ b/tests/helpers/samples/dumps.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import Optional +from typing import Optional, Tuple from uuid import uuid4 @@ -54,3 +54,31 @@ def create_eaudit(irn_to_delete: str, table_to_delete_from: str) -> dict: "AudTable": table_to_delete_from, "AudKey": irn_to_delete, } + + +def read_emu_extract(text: str) -> Tuple[str, dict]: + data = {} + for line in text.split("\n"): + line = line.strip() + if not line: + continue + + # the format is := + field, value = line.split("=", 1) + field = field.split(":", 1)[0] + + existing = data.get(field) + if existing is None: + # the value isn't in the data dict, add it + data[field] = value + else: + if isinstance(existing, tuple): + # there is an existing set of values in the data dict, add + # the new value in a new tuple + data[field] = (*existing, value) + else: + # there is an existing value (just one) in the data dict, + # add the new value in a new tuple + data[field] = (existing, value) + + return data["irn"], data diff --git a/tests/helpers/samples/image.py b/tests/helpers/samples/image.py index d14bcc6..718478a 100644 --- a/tests/helpers/samples/image.py +++ b/tests/helpers/samples/image.py @@ -1,4 +1,4 @@ -from tests.helpers.samples.utils import read_emu_extract +from tests.helpers.samples.dumps import read_emu_extract # this is taken from emultimedia.export.20230510.gz raw_data = f""" diff --git a/tests/helpers/samples/indexlot.py b/tests/helpers/samples/indexlot.py index aa2d9a1..02d260b 100644 --- a/tests/helpers/samples/indexlot.py +++ b/tests/helpers/samples/indexlot.py @@ -1,5 +1,5 @@ +from tests.helpers.samples.dumps import read_emu_extract from tests.helpers.samples.image import SAMPLE_IMAGE_ID -from tests.helpers.samples.utils import read_emu_extract # this is taken from ecatalogue.export.20231008.gz but with the MulMultiMediaRefs # replaced with a single reference to the SAMPLE_IMAGE_ID diff --git a/tests/helpers/samples/preparation.py b/tests/helpers/samples/preparation.py index bc1ae08..43f4378 100644 --- a/tests/helpers/samples/preparation.py +++ b/tests/helpers/samples/preparation.py @@ -1,5 +1,5 @@ +from tests.helpers.samples.dumps import read_emu_extract from tests.helpers.samples.specimen import SAMPLE_SPECIMEN_ID -from tests.helpers.samples.utils import read_emu_extract # this is taken from ecatalogue.export.20231008.gz but with the EntPreSpecimenRef field # replaced with a single reference to the SAMPLE_SPECIMEN_ID diff --git a/tests/helpers/samples/specimen.py b/tests/helpers/samples/specimen.py index 6497c81..7aa9981 100644 --- a/tests/helpers/samples/specimen.py +++ b/tests/helpers/samples/specimen.py @@ -1,5 +1,5 @@ +from tests.helpers.samples.dumps import read_emu_extract from tests.helpers.samples.image import SAMPLE_IMAGE_ID -from tests.helpers.samples.utils import read_emu_extract # this is taken from ecatalogue.export.20231019.gz but with the MulMultiMediaRefs # replaced with a single reference to the SAMPLE_IMAGE_ID diff --git a/tests/helpers/samples/taxonomy.py b/tests/helpers/samples/taxonomy.py index fb6e907..bbfc7f3 100644 --- a/tests/helpers/samples/taxonomy.py +++ b/tests/helpers/samples/taxonomy.py @@ -1,4 +1,4 @@ -from tests.helpers.samples.utils import read_emu_extract +from tests.helpers.samples.dumps import read_emu_extract # this is taken from etaxonomy.export.20210930.gz raw_data = f""" diff --git a/tests/helpers/samples/threed.py b/tests/helpers/samples/threed.py index 636dab0..9255637 100644 --- a/tests/helpers/samples/threed.py +++ b/tests/helpers/samples/threed.py @@ -1,4 +1,4 @@ -from tests.helpers.samples.utils import read_emu_extract +from tests.helpers.samples.dumps import read_emu_extract # this is taken from emultimedia.export.20211117.gz raw_data = f""" diff --git a/tests/helpers/samples/utils.py b/tests/helpers/samples/utils.py deleted file mode 100644 index 12bb6b5..0000000 --- a/tests/helpers/samples/utils.py +++ /dev/null @@ -1,29 +0,0 @@ -from typing import Tuple - - -def read_emu_extract(text: str) -> Tuple[str, dict]: - data = {} - for line in text.split("\n"): - line = line.strip() - if not line: - continue - - # the format is := - field, value = line.split("=", 1) - field = field.split(":", 1)[0] - - existing = data.get(field) - if existing is None: - # the value isn't in the data dict, add it - data[field] = value - else: - if isinstance(existing, tuple): - # there is an existing set of values in the data dict, add - # the new value in a new tuple - data[field] = (*existing, value) - else: - # there is an existing value (just one) in the data dict, - # add the new value in a new tuple - data[field] = (existing, value) - - return data["irn"], data