Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run test suite with pytest #9

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Run test suite with pytest
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
jdufresne committed Mar 25, 2019
commit bf8e37d23c09f902aa492025f7372b61bbe3fc3b
46 changes: 46 additions & 0 deletions tests/test_html2docx.py
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}'."
48 changes: 0 additions & 48 deletions tests/tests.py

This file was deleted.

3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ envlist =
minversion = 1.9

[testenv]
commands = python -m unittest
commands = pytest {posargs}
deps = pytest

[testenv:black]
commands = black --target-version=py36 --check --diff .
Expand Down