Skip to content

Commit

Permalink
Sorts test_document's contents
Browse files Browse the repository at this point in the history
  • Loading branch information
funkyfuture committed May 19, 2024
1 parent b29a1d5 commit 3cd443d
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,6 @@ def test_clone():
document.clone()


def test_reduce_whitespace():
document = Document(
"""
<root>
<title>
I Roy -
<hi>Touting I Self</hi>
</title>
<matrix xml:space="preserve">HB 243 A Re</matrix>
<matrix xml:space="preserve">HB 243 B\tRe</matrix>
</root>
"""
)

document.reduce_whitespace()
root = document.root

assert root.first_child.full_text == "I Roy - Touting I Self"
assert root.css_select("matrix")[0].full_text == "HB 243 A Re"
assert root.css_select("matrix")[1].full_text == "HB 243 B\tRe"

#

document = Document(
'<docImprint><hi rendition="#g">Veröffentlicht im</hi> <docDate>'
'<hi rendition="#g">Februar</hi> 1848</docDate>.</docImprint>'
)
document.reduce_whitespace()
assert document.root.full_text == "Veröffentlicht im Februar 1848."

document = Document("<root><lb/>Hello <lb/> <lb/> <lb/> world!</root>")
document.reduce_whitespace()
assert document.root.full_text == "Hello world!"


def test_contains():
document_a = Document("<root><a/></root>")
document_b = Document("<root><a/></root>")
Expand Down Expand Up @@ -113,14 +78,39 @@ class DocumentSubclass(Document):
)


def test_set_root():
document = Document("<root><node/></root>")
document.root = document.root[0].detach()
assert str(document) == '<?xml version="1.0" encoding="UTF-8"?><node/>'
def test_reduce_whitespace():
document = Document(
"""
<root>
<title>
I Roy -
<hi>Touting I Self</hi>
</title>
<matrix xml:space="preserve">HB 243 A Re</matrix>
<matrix xml:space="preserve">HB 243 B\tRe</matrix>
</root>
"""
)

document_2 = Document("<root><replacement/>parts</root>")
with pytest.raises(ValueError, match="detached node"):
document.root = document_2.root[0]
document.reduce_whitespace()
root = document.root

assert root.first_child.full_text == "I Roy - Touting I Self"
assert root.css_select("matrix")[0].full_text == "HB 243 A Re"
assert root.css_select("matrix")[1].full_text == "HB 243 B\tRe"

#

document = Document(
'<docImprint><hi rendition="#g">Veröffentlicht im</hi> <docDate>'
'<hi rendition="#g">Februar</hi> 1848</docDate>.</docImprint>'
)
document.reduce_whitespace()
assert document.root.full_text == "Veröffentlicht im Februar 1848."

document = Document("<root><lb/>Hello <lb/> <lb/> <lb/> world!</root>")
document.reduce_whitespace()
assert document.root.full_text == "Hello world!"


def test_root_siblings():
Expand Down Expand Up @@ -153,6 +143,16 @@ def test_root_siblings():
tail_nodes.pop(0)


def test_set_root():
document = Document("<root><node/></root>")
document.root = document.root[0].detach()
assert str(document) == '<?xml version="1.0" encoding="UTF-8"?><node/>'

document_2 = Document("<root><replacement/>parts</root>")
with pytest.raises(ValueError, match="detached node"):
document.root = document_2.root[0]


def test_xpath(files_path):
document = Document(files_path / "tei_marx_manifestws_1848.TEI-P5.xml")

Expand Down

0 comments on commit 3cd443d

Please sign in to comment.