-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
78 lines (57 loc) · 2.23 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from __future__ import annotations
from importlib import metadata
from types import SimpleNamespace
from delb import Document, TagNode
OFFICE_NS = "urn:oasis:names:tc:opendocument:xmlns:office:1.0"
ODT_MIMETYPE = "application/vnd.oasis.opendocument.text"
class OpenDocumentText(Document):
@staticmethod
def __class_test__(root: TagNode, config: SimpleNamespace) -> bool:
if root.namespace != OFFICE_NS:
return False
if root.local_name != "document":
return False
try:
return root.attributes[OFFICE_NS:"mimetype"] == ODT_MIMETYPE
except KeyError:
return False
def test_custom_loader():
url = "remote://the_book_of_brian.xml"
root = Document(url).root
assert root.local_name == "document"
assert root["url"] == url
def test_header_properties():
document = Document(
"https://textgridlab.org/1.0/tgcrud-public/rest/textgrid:1265r.0/data"
)
assert document.tei_header.title == "Das erste dadaistische Manifest"
assert document.tei_header.authors == ["Ball, Hugo"]
document.config.tei_header.yelling = True
assert document.tei_header.title == "DAS ERSTE DADAISTISCHE MANIFEST"
document = Document(
"https://textgridlab.org/1.0/tgcrud-public/rest/textgrid:1265r.0/data",
tei_header_yelling=True
)
assert document.tei_header.title == "DAS ERSTE DADAISTISCHE MANIFEST"
def test_subclass():
stub = f'<document xmlns="{OFFICE_NS}" mimetype="{ODT_MIMETYPE}"/>'
assert isinstance(Document(stub), OpenDocumentText)
stub = stub.replace("open", "closed")
document = Document(stub)
assert isinstance(document, Document)
assert not isinstance(document, OpenDocumentText)
if __name__ == "__main__":
# this isn't trying to import the package as it shall test that delb's loading of
# entrypoints works
try:
metadata.metadata("delb-reference-plugins")
except metadata.PackageNotFoundError:
print(
"The package that includes the extensions must be installed in order to "
"use these."
)
raise SystemExit(1)
test_custom_loader()
test_header_properties()
test_subclass()
print("Everything worked as expected.")