diff --git a/python/tests/test_file.py b/python/tests/test_file.py
index c3b68ee48..4bd944aef 100644
--- a/python/tests/test_file.py
+++ b/python/tests/test_file.py
@@ -98,12 +98,6 @@ def test_open_as_type(txt_path):
assert file.file_type() == pyodr.FileType.text_file
-def test_open_with_options(txt_path):
- options = pyodr.DecodeOptions(as_file_type=pyodr.FileType.text_file)
- file = pyodr.open(str(txt_path), options)
- assert file.file_type() == pyodr.FileType.text_file
-
-
def test_open_carries_csv_options(tmp_path):
path = tmp_path / "semicolons.csv"
path.write_text("a;b\n1;2\n", encoding="utf-8")
@@ -170,28 +164,6 @@ def test_open_from_memory_as_type(odt_path):
assert pyodr.open(file, options).is_archive_file()
-def test_decoded_file_from_file(odt_path):
- file = pyodr.File.from_memory(odt_path.read_bytes())
-
- assert pyodr.open(file).file_type() == pyodr.FileType.opendocument_text
- assert pyodr.open(
- file, pyodr.DecodeOptions(as_file_type=pyodr.FileType.zip)
- ).is_archive_file()
-
- options = pyodr.DecodeOptions(as_file_type=pyodr.FileType.zip)
- assert pyodr.open(file, options).is_archive_file()
-
-
-def test_document_file_from_file(odt_path):
- file = pyodr.File.from_memory(odt_path.read_bytes())
-
- document_file = pyodr.open(file).as_document_file()
- assert document_file.file_type() == pyodr.FileType.opendocument_text
- assert document_file.file_meta().type == pyodr.FileType.opendocument_text
-
- assert document_file.document_type() == pyodr.DocumentType.text
-
-
def test_document_file_from_disk_and_from_memory(odt_path):
from_disk = pyodr.open(str(odt_path)).as_document_file()
from_memory = pyodr.open(
@@ -199,6 +171,7 @@ def test_document_file_from_disk_and_from_memory(odt_path):
).as_document_file()
assert from_disk.file_type() == pyodr.FileType.opendocument_text
+ assert from_memory.file_meta().type == from_disk.file_type()
assert from_memory.file_type() == from_disk.file_type()
assert from_memory.document_type() == from_disk.document_type()
assert (
diff --git a/python/tests/test_html.py b/python/tests/test_html.py
index 174563310..74c679d9a 100644
--- a/python/tests/test_html.py
+++ b/python/tests/test_html.py
@@ -11,6 +11,12 @@ def translate_offline(path, tmp_path):
return service.bring_offline(str(output))
+def render(path, config):
+ service = pyodr.html.translate(pyodr.open(str(path)), config)
+ content, _ = service.list_views()[0].write_html()
+ return content
+
+
def test_html_config_defaults():
config = pyodr.HtmlConfig()
assert config.embed_images
@@ -87,70 +93,52 @@ def test_viewport_mode_reaches_the_html(odt_path):
# The C++ suite covers the mode matrix; this only proves the config crosses
# the binding. A text document without margins is reflowing content, so
# `automatic` resolves to `actual_size`.
- def render(config):
- file = pyodr.open(str(odt_path))
- service = pyodr.html.translate(file, config)
- content, _ = service.list_views()[0].write_html()
- return content
-
assert (
''
- in render(pyodr.HtmlConfig())
+ in render(odt_path, pyodr.HtmlConfig())
)
fit_width = pyodr.HtmlConfig()
fit_width.viewport_mode = pyodr.HtmlViewportMode.fit_width
assert (
''
- in render(fit_width)
+ in render(odt_path, fit_width)
)
# only paged content has a width to fit, hence the margins
by_view = pyodr.HtmlConfig()
by_view.viewport_mode = pyodr.HtmlViewportMode.fit_width_by_view
by_view.text_document_margin = True
- assert "--odr-fit:view" in render(by_view)
+ assert "--odr-fit:view" in render(odt_path, by_view)
raw = pyodr.HtmlConfig()
raw.viewport_content = "width=420"
- assert '' in render(raw)
+ assert '' in render(odt_path, raw)
def test_editing_scope_reaches_the_html(odt_path):
# proves the scope crosses the binding; the C++ suite covers the rest
- def render(config):
- file = pyodr.open(str(odt_path))
- service = pyodr.html.translate(file, config)
- content, _ = service.list_views()[0].write_html()
- return content
-
# the attribute, not the name: the script names it too
- assert 'data-odr-editing-scope="' not in render(pyodr.HtmlConfig())
+ assert 'data-odr-editing-scope="' not in render(odt_path, pyodr.HtmlConfig())
config = pyodr.HtmlConfig()
config.editable = True
config.editing_scope = pyodr.HtmlEditingScope.paragraph
- assert 'data-odr-editing-scope="paragraph"' in render(config)
+ assert 'data-odr-editing-scope="paragraph"' in render(odt_path, config)
def test_min_content_margin_reaches_the_html(odt_path):
# The C++ suite covers where the floor lands; this only proves it crosses
# the binding, unset sides and all.
- def render(config):
- file = pyodr.open(str(odt_path))
- service = pyodr.html.translate(file, config)
- content, _ = service.list_views()[0].write_html()
- return content
-
default = pyodr.HtmlConfig()
assert default.min_content_margin.top is None
- assert ":root{--odr-min-margin" not in render(default)
+ assert ":root{--odr-min-margin" not in render(odt_path, default)
config = pyodr.HtmlConfig()
config.min_content_margin.top = pyodr.Measure("12px")
config.min_content_margin.left = pyodr.Measure("1cm")
- html = render(config)
+ html = render(odt_path, config)
assert ":root{--odr-min-margin-top:12px;--odr-min-margin-left:1cm;}" in html
assert "--odr-min-margin-right:" not in html
diff --git a/python/tests/test_http_server.py b/python/tests/test_http_server.py
index 7f3acfe5b..cf78ec6a0 100644
--- a/python/tests/test_http_server.py
+++ b/python/tests/test_http_server.py
@@ -90,10 +90,13 @@ def test_stop_waits_for_listen():
thread = threading.Thread(target=server.listen, daemon=True)
thread.start()
- while not server.is_running():
- time.sleep(0.001)
-
- server.stop()
+ deadline = time.monotonic() + 5
+ try:
+ while not server.is_running():
+ assert thread.is_alive() and time.monotonic() < deadline
+ time.sleep(0.001)
+ finally:
+ server.stop()
# the accept loop is gone for good by now, which is what makes dropping the
# server right after safe
assert not server.is_running()
diff --git a/python/tests/test_logger.py b/python/tests/test_logger.py
index 744ee4d18..2287939cf 100644
--- a/python/tests/test_logger.py
+++ b/python/tests/test_logger.py
@@ -8,9 +8,11 @@ def __init__(self, level=pyodr.LogLevel.verbose):
super().__init__()
self.level = level
self.messages = []
+ self.consulted = []
self.flushes = 0
def will_log(self, level):
+ self.consulted.append(level)
return level >= self.level
def log(self, time, level, message, location):
@@ -56,9 +58,7 @@ def test_custom_sink_receives_library_diagnostics(odt_path):
"""A logger passed to `open` is actually used by the library."""
sink = CollectingLogger()
pyodr.open(str(odt_path), logger=pyodr.Logger(sink))
- # The odt path logs at least one diagnostic; at minimum it must not crash
- # and the sink must have been consulted.
- assert isinstance(sink.messages, list)
+ assert sink.consulted
def test_logger_accepted_by_entry_points(odt_path):