Skip to content

Commit f499ef8

Browse files
committed
Add test
1 parent 8022549 commit f499ef8

1 file changed

Lines changed: 30 additions & 9 deletions

File tree

‎tests/web/test_web_document.py‎

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
"""ELM Web Document class tests"""
3+
34
from pathlib import Path
45

56
import pytest
@@ -113,11 +114,29 @@ def test_doc_repr():
113114
c = PDFDocument(["a"] * 1543)
114115
c.attrs = {"A": "some text", "b": pd.DataFrame({"Test": ["a"] * 1953})}
115116

116-
expected_repr = ("PDFDocument with 1,543 pages\nAttrs:\n A:\tsome text\n"
117-
" b:\tDataFrame with 1,953 rows")
117+
expected_repr = (
118+
"PDFDocument with 1,543 pages\nAttrs:\n A:\tsome text\n"
119+
" b:\tDataFrame with 1,953 rows"
120+
)
118121
assert repr(c) == expected_repr
119122

120123

124+
def test_doc_repr_multiline_attr_shortened():
125+
"""Test repr shortens multiline attribute values to one line"""
126+
127+
doc = PDFDocument(["a"])
128+
long_key = "x" * 100
129+
multiline_val = "Line 1\nLine 2 with lots of extra text to shorten"
130+
doc.attrs = {long_key: multiline_val}
131+
132+
doc_repr = repr(doc)
133+
attr_line = doc_repr.split("\n")[-1]
134+
shown_val = attr_line.split("\t", maxsplit=1)[-1]
135+
136+
assert "\n" not in shown_val
137+
assert len(shown_val) <= 10
138+
139+
121140
@pytest.mark.parametrize("pages", ([], ["aaa"], ["\n\n", "\n", "\r3"]))
122141
def test_doc_is_empty(pages):
123142
"""Test that doc without any text returns ``True`` for `empty` property"""
@@ -129,13 +148,15 @@ def test_doc_is_empty(pages):
129148
def test_html_string_is_empty_doc():
130149
"""Test that doc with just html text is empty"""
131150

132-
html_str = ('<!DOCTYPE html><html><head></head><body style="height: 100%; '
133-
'width: 100%; overflow: hidden; margin:0px; background-color: '
134-
'rgb(38, 38, 38);"><embed '
135-
'name="0AA1AAF79D1EC03DEFB5B45B5529FA56" '
136-
'style="position:absolute; left: 0; top: 0;" width="100%" '
137-
'height="100%" src="about:blank" type="application/pdf" '
138-
'internalid="0AA1AAF79D1EC03DEFB5B45B5529FA56"></body></html>')
151+
html_str = (
152+
'<!DOCTYPE html><html><head></head><body style="height: 100%; '
153+
"width: 100%; overflow: hidden; margin:0px; background-color: "
154+
'rgb(38, 38, 38);"><embed '
155+
'name="0AA1AAF79D1EC03DEFB5B45B5529FA56" '
156+
'style="position:absolute; left: 0; top: 0;" width="100%" '
157+
'height="100%" src="about:blank" type="application/pdf" '
158+
'internalid="0AA1AAF79D1EC03DEFB5B45B5529FA56"></body></html>'
159+
)
139160
assert HTMLDocument([html_str]).empty
140161

141162

0 commit comments

Comments
 (0)