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

chore: switch to syrupy snapshot tests #63

Merged
merged 2 commits into from
Dec 9, 2024
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
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ test_packaging = [
"twine==6.0.1"
]
tests = [
"pytest==8.3.4"
"pytest==8.3.4",
"syrupy==4.8.0"
]
type_check = [
"mypy==1.13.0"
Expand All @@ -69,6 +70,9 @@ profile = "black"
[tool.pylint."MESSAGES CONTROL"]
max-line-length = 120

[tool.pytest.ini_options]
markers = ["snapshot: mark a test as a snapshot test"]

[project.scripts]
xml2json = "fundamend.cli:cli"
# fundamend is the package in the src directory
Expand Down
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ deps =
setenv = PYTHONPATH = {toxinidir}/src
commands = python -m pytest --basetemp={envtmpdir} {posargs} -vv

[testenv:snapshots]
deps =
-r requirements.txt
.[tests]
setenv = PYTHONPATH = {toxinidir}/src
commands = python -m pytest -m snapshot --basetemp={envtmpdir} {posargs} --snapshot-update

[testenv:linting]
# the linting environment is called by the Github Action that runs the linter
deps =
Expand Down
10 changes: 10 additions & 0 deletions unittests/__snapshots__/test_ahbreader.ambr

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions unittests/__snapshots__/test_migreader.ambr

Large diffs are not rendered by default.

7,041 changes: 0 additions & 7,041 deletions unittests/example_ahb_utilts_11c.py

This file was deleted.

7,006 changes: 0 additions & 7,006 deletions unittests/example_ahb_utilts_11d.py

This file was deleted.

8,450 changes: 0 additions & 8,450 deletions unittests/example_migs.py

This file was deleted.

17 changes: 8 additions & 9 deletions unittests/test_ahbreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
from pathlib import Path

import pytest
from syrupy.assertion import SnapshotAssertion

from fundamend.models.anwendungshandbuch import Anwendungsfall, Anwendungshandbuch, Bedingung, Paket, UbBedingung
from fundamend.reader import AhbReader

from .example_ahb_utilts_11c import ahb_utilts_11c
from .example_ahb_utilts_11d import ahb_utilts_11d


@pytest.mark.parametrize(
"ahb_xml_file_path, expected_date",
Expand Down Expand Up @@ -134,26 +132,27 @@ def test_get_anwendungsfall(ahb_xml_file_path: Path, pruefidentifikator: str, ex
assert actual is None


@pytest.mark.snapshot
@pytest.mark.parametrize(
"ahb_xml_file_path, expected",
"ahb_xml_file_path",
[
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1c_Lesefassung_2023_12_12_ZPbXedn.xml",
ahb_utilts_11c,
id="UTILTS_AHB_1.1c_Lesefassung_2023_12_12_ZPbXedn.xml",
),
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1d_Konsultationsfassung_2024_04_02.xml",
ahb_utilts_11d,
id="UTILTS_AHB_1.1d_Konsultationsfassung_2024_04_02.xml",
),
pytest.param(
Path(__file__).parent
/ "example_files"
/ "UTILTS_AHB_1.1d_Konsultationsfassung_2024_04_02_with_Uebertragungsdatei.xml",
ahb_utilts_11d,
id="UTILTS_AHB_1.1d_Konsultationsfassung_2024_04_02_with_Uebertragungsdatei.xml",
),
],
)
def test_get_anwendungshandbuch(ahb_xml_file_path: Path, expected: Anwendungshandbuch) -> None:
def test_get_anwendungshandbuch(ahb_xml_file_path: Path, snapshot: SnapshotAssertion) -> None:
reader = AhbReader(ahb_xml_file_path)
actual = reader.read()
assert actual is not None
Expand All @@ -173,4 +172,4 @@ def test_get_anwendungshandbuch(ahb_xml_file_path: Path, expected: Anwendungshan
for awf in actual.anwendungsfaelle:
assert any(awf.segments)
assert any(awf.segment_groups)
assert actual == expected
snapshot.assert_match(actual)
17 changes: 9 additions & 8 deletions unittests/test_migreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
from pathlib import Path

import pytest
from syrupy.assertion import SnapshotAssertion

from fundamend.models.messageimplementationguide import MessageImplementationGuide
from fundamend.reader import MigReader

from .example_migs import utilts_mig_11c, utilts_mig_11d


@pytest.mark.parametrize(
"mig_xml_file_path, expected_date",
Expand Down Expand Up @@ -72,27 +71,29 @@ def test_get_format(mig_xml_file_path: Path, expected: str) -> None:
assert actual == expected


@pytest.mark.snapshot
@pytest.mark.parametrize(
"mig_xml_file_path, expected",
"mig_xml_file_path",
[
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_MIG_1.1c_Lesefassung_2023_12_12.xml", utilts_mig_11c
Path(__file__).parent / "example_files" / "UTILTS_MIG_1.1c_Lesefassung_2023_12_12.xml",
id="UTILTS_MIG_1.1c_Lesefassung_2023_12_12.xml",
),
pytest.param(
Path(__file__).parent / "example_files" / "UTILTS_MIG_1.1d_Konsultationsfassung_2024_04_02.xml",
utilts_mig_11d,
id="UTILTS_MIG_1.1d_Konsultationsfassung_2024_04_02.xml",
),
pytest.param(
Path(__file__).parent
/ "example_files"
/ "UTILTS_MIG_1.1d_Konsultationsfassung_2024_04_02_with_Uebertragungsdatei.xml",
utilts_mig_11d,
id="UTILTS_MIG_1.1d_Konsultationsfassung_2024_04_02_with_Uebertragungsdatei.xml",
),
],
)
def test_read_mig(mig_xml_file_path: Path, expected: MessageImplementationGuide) -> None:
def test_read_mig(mig_xml_file_path: Path, snapshot: SnapshotAssertion) -> None:
reader = MigReader(mig_xml_file_path)
actual = reader.read()
assert actual is not None
assert isinstance(actual, MessageImplementationGuide)
assert actual == expected
snapshot.assert_match(actual)
21 changes: 16 additions & 5 deletions unittests/test_pydantic_features.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
from pathlib import Path

import pytest

try:
from pydantic import RootModel, TypeAdapter
except ImportError:
pytest.skip("Only available with pydantic", allow_module_level=True)

from fundamend import Anwendungshandbuch, MessageImplementationGuide

from .example_ahb_utilts_11c import ahb_utilts_11c
from .example_ahb_utilts_11d import ahb_utilts_11d
from .example_migs import utilts_mig_11c, utilts_mig_11d
from fundamend import AhbReader, Anwendungshandbuch, MessageImplementationGuide, MigReader

ahb_utilts_11c = AhbReader(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1c_Lesefassung_2023_12_12_ZPbXedn.xml"
).read()
ahb_utilts_11d = AhbReader(
Path(__file__).parent / "example_files" / "UTILTS_AHB_1.1d_Konsultationsfassung_2024_04_02.xml"
).read()
utilts_mig_11c = MigReader(
Path(__file__).parent / "example_files" / "UTILTS_MIG_1.1c_Lesefassung_2023_12_12.xml"
).read()
utilts_mig_11d = MigReader(
Path(__file__).parent / "example_files" / "UTILTS_MIG_1.1d_Konsultationsfassung_2024_04_02.xml"
).read()


def test_json_schema_export_mig() -> None:
Expand Down
Loading