Skip to content

Commit 87d174c

Browse files
authored
Merge pull request saw-leipzig#74 from rettinghaus/fix/tests
Clean up tests
2 parents 123bea3 + cc71fc2 commit 87d174c

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

csv2cmi.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,12 @@ def generate_id(id_prefix: str) -> str:
442442
generated_id = f"{id_prefix.strip()}-{token_hex(4)}"
443443
return generated_id
444444

445-
def generate_uuid(self) -> str:
445+
@staticmethod
446+
def generate_uuid() -> str:
446447
"""Generate a UUID of type xs:ID."""
447448
generated_uuid = str(UUID(bytes=bytes(random.getrandbits(8) for _ in range(16)), version=4))
448449
if generated_uuid[0].isdigit():
449-
return self.generate_uuid()
450+
return CMI.generate_uuid()
450451
return generated_uuid
451452

452453
def process_date(self, letter: dict, correspondent: Correspondents) -> Optional[Element]:

tests/test_cmi_methods.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
11
import pytest
22

3-
import csv2cmi
4-
5-
6-
@pytest.fixture
7-
def table():
8-
table
3+
from csv2cmi import CMI
94

105

116
def test_create_date_valid():
12-
assert csv2cmi.CMI.create_date("2016-04-01").attrib["when"] == "2016-04-01"
13-
assert csv2cmi.CMI.create_date("1673-05").attrib["when"] == "1673-05"
14-
assert csv2cmi.CMI.create_date("[..1760-12-03]").attrib["notAfter"] == "1760-12-03"
15-
assert csv2cmi.CMI.create_date("[1760-12..]").attrib["notBefore"] == "1760-12"
16-
assert csv2cmi.CMI.create_date("1979-10-12/").attrib["from"] == "1979-10-12"
17-
assert csv2cmi.CMI.create_date("/1985-04-12").attrib["to"] == "1985-04-12"
18-
assert csv2cmi.CMI.create_date("{-0400,-0390,-0370}") is not None
7+
assert CMI.create_date("2016-04-01").attrib["when"] == "2016-04-01"
8+
assert CMI.create_date("1673-05").attrib["when"] == "1673-05"
9+
assert CMI.create_date("[..1760-12-03]").attrib["notAfter"] == "1760-12-03"
10+
assert CMI.create_date("[1760-12..]").attrib["notBefore"] == "1760-12"
11+
assert CMI.create_date("1979-10-12/").attrib["from"] == "1979-10-12"
12+
assert CMI.create_date("/1985-04-12").attrib["to"] == "1985-04-12"
13+
assert CMI.create_date("{-0400,-0390,-0370}") is not None
1914

2015

2116
def test_create_date_invalid():
2217
with pytest.raises(ValueError):
23-
csv2cmi.CMI.create_date("not-a-date")
18+
CMI.create_date("not-a-date")
2419

2520

2621
def test_create_place_name():
27-
tei_placename = csv2cmi.CMI.create_place_name("Berlin")
22+
tei_placename = CMI.create_place_name("Berlin")
2823
assert tei_placename.tag == "placeName"
2924
assert tei_placename.text == "Berlin"
3025

3126

3227
def test_create_place_name_with_uri():
33-
tei_placename = csv2cmi.CMI.create_place_name("Mokhdān", "https://www.geonames.org/123456")
28+
tei_placename = CMI.create_place_name("Mokhdān", "https://www.geonames.org/123456")
3429
assert tei_placename.tag == "placeName"
3530
assert tei_placename.attrib["ref"] == "https://www.geonames.org/123456"
3631
assert tei_placename.text == "Mokhdān"
3732

3833

3934
def test_generate_id_and_uuid():
40-
id1 = csv2cmi.CMI.generate_id("test")
41-
id2 = csv2cmi.CMI.generate_id("test")
35+
id1 = CMI.generate_id("test")
36+
id2 = CMI.generate_id("test")
4237
assert id1 != id2
43-
cmi = csv2cmi.CMI()
44-
uuid1 = cmi.generate_uuid()
45-
uuid2 = cmi.generate_uuid()
38+
uuid1 = CMI.generate_uuid()
39+
uuid2 = CMI.generate_uuid()
4640
assert uuid1 != uuid2

tests/test_csv2cmi.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,4 @@ def test_missing_file(monkeypatch: pytest.MonkeyPatch):
3333
sys_argv = ["csv2cmi.py", "nonexistent.csv"]
3434
monkeypatch.setattr(sys, "argv", sys_argv)
3535
with pytest.raises(SystemExit):
36-
import runpy
37-
3836
runpy.run_module("csv2cmi", run_name="__main__")

0 commit comments

Comments
 (0)