|
| 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 |
0 commit comments