Skip to content

Commit 21fb82d

Browse files
committed
Add test cases
1 parent 2202cdb commit 21fb82d

6 files changed

Lines changed: 39 additions & 0 deletions

File tree

tests/converter_test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Tests for the docxplain.converter module."""
2+
3+
import shutil
4+
from pathlib import Path
5+
6+
from docxplain.converter import convert_file
7+
8+
9+
def test_unchanged(tmp_path: Path) -> None:
10+
"""Test case where the plain text conversion matches the docx source."""
11+
repo_data = Path(__file__).parent.joinpath("data/unchanged")
12+
work_dir = tmp_path / "unchanged"
13+
shutil.copytree(repo_data, work_dir)
14+
docxpath = work_dir.joinpath("test_doc.docx")
15+
assert convert_file(str(docxpath)) is False
16+
17+
18+
def test_changed(tmp_path: Path) -> None:
19+
"""Test the case where the existing plain text conversion is different."""
20+
repo_data = Path(__file__).parent.joinpath("data/changed")
21+
work_dir = tmp_path / "changed"
22+
shutil.copytree(repo_data, work_dir)
23+
docxpath = work_dir.joinpath("test_doc.docx")
24+
assert convert_file(str(docxpath)) is True
25+
26+
27+
def test_new(tmp_path: Path) -> None:
28+
"""Test the case where the existing plain text conversion is different."""
29+
repo_data = Path(__file__).parent.joinpath("data/new")
30+
work_dir = tmp_path / "new"
31+
shutil.copytree(repo_data, work_dir)
32+
docxpath = work_dir.joinpath("test_doc.docx")
33+
assert convert_file(str(docxpath)) is True

tests/data/changed/test_doc.docx

11.7 KB
Binary file not shown.

tests/data/changed/test_doc.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Test document
2+
3+
Testing...

tests/data/new/test_doc.docx

11.7 KB
Binary file not shown.

tests/data/unchanged/test_doc.docx

11.7 KB
Binary file not shown.

tests/data/unchanged/test_doc.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Test document
2+
3+
Test content.

0 commit comments

Comments
 (0)