Skip to content

Commit

Permalink
test: move dump reading helper to dumps module
Browse files Browse the repository at this point in the history
  • Loading branch information
jrdh committed Nov 8, 2023
1 parent 543017e commit a4f4c10
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 37 deletions.
2 changes: 1 addition & 1 deletion tests/helpers/samples/artefact.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 29 additions & 1 deletion tests/helpers/samples/dumps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import Optional
from typing import Optional, Tuple
from uuid import uuid4


Expand Down Expand Up @@ -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>:<index>=<value>
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
2 changes: 1 addition & 1 deletion tests/helpers/samples/image.py
Original file line number Diff line number Diff line change
@@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/samples/indexlot.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/samples/preparation.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/samples/specimen.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/samples/taxonomy.py
Original file line number Diff line number Diff line change
@@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/samples/threed.py
Original file line number Diff line number Diff line change
@@ -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"""
Expand Down
29 changes: 0 additions & 29 deletions tests/helpers/samples/utils.py

This file was deleted.

0 comments on commit a4f4c10

Please sign in to comment.