diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c6a32c2..4bed644 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,6 +30,10 @@ jobs: run: python -m pip install --upgrade pip setuptools wheel pytest pytest-mock - name: Setup package run: python -m pip install . - - name: run tests - run: pytest + - name: run unit tests + run: pytest tests/test_unit.py + - name: install dependencies for integration tests + run: sudo apt update && sudo apt install -y pandoc plantuml + - name: run integration tests + run: pytest tests/test_integration.py diff --git a/tests/test_integration.py b/tests/test_integration.py new file mode 100644 index 0000000..0b66dc2 --- /dev/null +++ b/tests/test_integration.py @@ -0,0 +1,35 @@ +import os +import subprocess + +from pathlib import Path + +import pytest + +__TEST_BASE_DIR__ = Path(os.path.dirname(__file__)) / "testdata" + + +@pytest.mark.parametrize( + "filename, expected_content", + [ + ("single-diagram", ["\\includegraphics{plantuml-images/"]), + ("single-diagram-with-config", ["\\includegraphics", "width=0.6"]), + ("single-diagram-with-filename-and-subdirectory", ["\\includegraphics", "images/example.png"]), + ("single-diagram-with-filename-without-subdirectory", ["\\includegraphics", "example.png"]), + ( + "single-diagram-reference", + ["\\includegraphics", "images/example.png", "\\includegraphics{images/example.png}"], + ), + ], +) +def test_digrams(mocker, tmp_path, filename, expected_content): + input_file = str(__TEST_BASE_DIR__ / f"{filename}.md") + output_file = str(tmp_path / f"{filename}.tex") + + cmd = subprocess.run(["pandoc", input_file, "-o", output_file, "--filter", "pandoc-plantuml"]) + assert cmd.returncode == 0 + + with open(output_file) as f: + content = f.read() + + for line in expected_content: + assert line in content diff --git a/tests/testdata/single-diagram-reference.md b/tests/testdata/single-diagram-reference.md new file mode 100644 index 0000000..6a8d6ad --- /dev/null +++ b/tests/testdata/single-diagram-reference.md @@ -0,0 +1,8 @@ +# Single PlantUML diagram which referenced later + +```{ .plantuml width=60% plantuml-filename=images/example.png } +[producer] -> [consumer]: data streaming +``` + +# Reference +![And here's the reference](images/example.png) diff --git a/tests/testdata/single-diagram-with-config.md b/tests/testdata/single-diagram-with-config.md new file mode 100644 index 0000000..9b9cd08 --- /dev/null +++ b/tests/testdata/single-diagram-with-config.md @@ -0,0 +1,5 @@ +# Single PlantUML diagram with config + +```{ .plantuml width=60% } +[producer] -> [consumer]: data streaming +``` diff --git a/tests/testdata/single-diagram-with-filename-and-subdirectory.md b/tests/testdata/single-diagram-with-filename-and-subdirectory.md new file mode 100644 index 0000000..3a88823 --- /dev/null +++ b/tests/testdata/single-diagram-with-filename-and-subdirectory.md @@ -0,0 +1,5 @@ +# Single PlantUML diagram with filename and sub-directory + +```{ .plantuml width=60% plantuml-filename=images/example.png } +[producer] -> [consumer]: data streaming +``` diff --git a/tests/testdata/single-diagram-with-filename-without-subdirectory.md b/tests/testdata/single-diagram-with-filename-without-subdirectory.md new file mode 100644 index 0000000..ba795d0 --- /dev/null +++ b/tests/testdata/single-diagram-with-filename-without-subdirectory.md @@ -0,0 +1,5 @@ +# Single PlantUML diagram with filename without sub-directory + +```{ .plantuml width=60% plantuml-filename=example.png } +[producer] -> [consumer]: data streaming +``` diff --git a/tests/testdata/single-diagram.md b/tests/testdata/single-diagram.md new file mode 100644 index 0000000..0f41fe4 --- /dev/null +++ b/tests/testdata/single-diagram.md @@ -0,0 +1,9 @@ +# Single PlantUML digaram + +```plantuml +Alice -> Bob: Authentication Request +Bob --> Alice: Authentication Response + +Alice -> Bob: Another authentication Request +Alice <-- Bob: another authentication Response +```