|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +_SKIP_TESTS = False |
| 6 | +try: |
| 7 | + from typer.testing import CliRunner |
| 8 | + |
| 9 | + from fundamend.cli import app |
| 10 | +except ImportError: |
| 11 | + _SKIP_TESTS = True |
| 12 | + |
| 13 | + |
| 14 | +def _copy_xml_file(inpath: Path, outpath: Path) -> None: |
| 15 | + with open(outpath, encoding="utf-8", mode="w") as outfile: |
| 16 | + with open(inpath, encoding="utf-8", mode="r") as infile: |
| 17 | + outfile.write(infile.read()) |
| 18 | + |
| 19 | + |
| 20 | +def test_cli_single_file_mig(tmp_path: Path) -> None: |
| 21 | + if _SKIP_TESTS: |
| 22 | + pytest.skip("Seems like typer is not installed") |
| 23 | + original_mig_file = Path(__file__).parent / "example_files" / "UTILTS_MIG_1.1c_Lesefassung_2023_12_12.xml" |
| 24 | + tmp_mig_path = tmp_path / "my_mig.xml" |
| 25 | + _copy_xml_file(original_mig_file, tmp_mig_path) |
| 26 | + runner = CliRunner() |
| 27 | + runner.invoke(app, [str(tmp_mig_path)]) |
| 28 | + assert (tmp_path / "my_mig.json").exists() |
| 29 | + |
| 30 | + |
| 31 | +def test_cli_single_file_ahb(tmp_path: Path) -> None: |
| 32 | + if _SKIP_TESTS: |
| 33 | + pytest.skip("Seems like typer is not installed") |
| 34 | + original_ahb_file = Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1d_Konsultationsfassung_2024_04_02.xml" |
| 35 | + tmp_ahb_path = tmp_path / "my_ahb.xml" |
| 36 | + _copy_xml_file(original_ahb_file, tmp_ahb_path) |
| 37 | + runner = CliRunner() |
| 38 | + runner.invoke(app, [str(tmp_ahb_path)]) |
| 39 | + assert (tmp_path / "my_ahb.json").exists() |
| 40 | + |
| 41 | + |
| 42 | +def test_cli_directory(tmp_path: Path) -> None: |
| 43 | + if _SKIP_TESTS: |
| 44 | + pytest.skip("Seems like typer is not installed") |
| 45 | + original_mig_file = Path(__file__).parent / "example_files" / "UTILTS_MIG_1.1c_Lesefassung_2023_12_12.xml" |
| 46 | + tmp_mig_path = tmp_path / "my_mig.xml" |
| 47 | + original_ahb_file = Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1d_Konsultationsfassung_2024_04_02.xml" |
| 48 | + tmp_ahb_path = tmp_path / "my_ahb.xml" |
| 49 | + _copy_xml_file(original_ahb_file, tmp_ahb_path) |
| 50 | + _copy_xml_file(original_mig_file, tmp_mig_path) |
| 51 | + runner = CliRunner() |
| 52 | + runner.invoke(app, [str(tmp_path)]) |
| 53 | + assert (tmp_path / "my_mig.json").exists() |
| 54 | + assert (tmp_path / "my_ahb.json").exists() |
0 commit comments