-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pytest has better support for parameterized tests. Each test iteration appears as a separate dot by the test runner and can run in isolation. Reviewed-by: François Freitag
- Loading branch information
Showing
3 changed files
with
48 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import json | ||
import pathlib | ||
|
||
import docx | ||
import pytest | ||
|
||
from html2docx import html2docx | ||
|
||
|
||
def generate_testdata(): | ||
datadir = pathlib.Path(__file__).parent.joinpath("data") | ||
for html_path in datadir.glob("*.html"): | ||
spec_path = datadir.joinpath(f"{html_path.stem}.json") | ||
yield html_path, spec_path | ||
|
||
|
||
@pytest.mark.parametrize("html_path,spec_path", generate_testdata()) | ||
def test_html2docx(html_path, spec_path): | ||
title = html_path.name | ||
with html_path.open() as fp: | ||
html = fp.read() | ||
with spec_path.open() as fp: | ||
spec = json.load(fp) | ||
|
||
buf = html2docx(html, title=title) | ||
doc = docx.Document(buf) | ||
|
||
assert doc.core_properties.title == title | ||
assert len(doc.paragraphs) == len(spec) | ||
for p, p_spec in zip(doc.paragraphs, spec): | ||
assert p.text == p_spec["text"] | ||
assert p.style.name == p_spec.get("style", "Normal") | ||
|
||
runs_spec = p_spec["runs"] | ||
assert len(p.runs) == len(runs_spec) | ||
for run, run_spec in zip(p.runs, runs_spec): | ||
assert run.text == run_spec["text"] | ||
assert run.bold is run_spec.get( | ||
"bold", False | ||
), f"Wrong bold for text '{run.text}'." | ||
assert run.italic is run_spec.get( | ||
"italic", False | ||
), f"Wrong italic for text '{run.text}'." | ||
assert run.underline is run_spec.get( | ||
"underline", False | ||
), f"Wrong underline for text '{run.text}'." |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters