|
| 1 | +import pytest |
| 2 | + |
| 3 | +import csv2cmi |
| 4 | + |
| 5 | + |
| 6 | +@pytest.fixture |
| 7 | +def table(): |
| 8 | + table |
| 9 | + |
| 10 | + |
| 11 | +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 |
| 19 | + |
| 20 | + |
| 21 | +def test_create_date_invalid(): |
| 22 | + with pytest.raises(ValueError): |
| 23 | + csv2cmi.CMI.create_date("not-a-date") |
| 24 | + |
| 25 | + |
| 26 | +def test_create_place_name(): |
| 27 | + tei_placename = csv2cmi.CMI.create_place_name("Berlin") |
| 28 | + assert tei_placename.tag == "placeName" |
| 29 | + assert tei_placename.text == "Berlin" |
| 30 | + |
| 31 | + |
| 32 | +def test_create_place_name_with_uri(): |
| 33 | + tei_placename = csv2cmi.CMI.create_place_name("Mokhdān", "https://www.geonames.org/123456") |
| 34 | + assert tei_placename.tag == "placeName" |
| 35 | + assert tei_placename.attrib["ref"] == "https://www.geonames.org/123456" |
| 36 | + assert tei_placename.text == "Mokhdān" |
| 37 | + |
| 38 | + |
| 39 | +def test_generate_id_and_uuid(): |
| 40 | + id1 = csv2cmi.CMI.generate_id("test") |
| 41 | + id2 = csv2cmi.CMI.generate_id("test") |
| 42 | + assert id1 != id2 |
| 43 | + cmi = csv2cmi.CMI() |
| 44 | + uuid1 = cmi.generate_uuid() |
| 45 | + uuid2 = cmi.generate_uuid() |
| 46 | + assert uuid1 != uuid2 |
0 commit comments