Skip to content

Commit

Permalink
test: add more snapshot tests (#429)
Browse files Browse the repository at this point in the history
* WIP

* added more snapshottests

* fixed paths

* try fixing tests

* perf(packaging): exclude edi-energy-mirror (#436)

exclude edi-energy-mirror

* update snapshot

* WIP proof of concept

* WIP

---------

Co-authored-by: kevin <[email protected]>
Co-authored-by: kevin <[email protected]>
  • Loading branch information
3 people authored Sep 11, 2024
1 parent d168701 commit f9bce1e
Show file tree
Hide file tree
Showing 10 changed files with 17,482 additions and 3,550 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand Down
5 changes: 5 additions & 0 deletions dev_requirements/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ annotated-types==0.7.0
# via pydantic
click==8.1.7
# via kohlrahbi (pyproject.toml)
colorama==0.4.6
# via
# click
# colorlog
# pytest
colorlog==6.8.2
# via kohlrahbi (pyproject.toml)
coverage==7.6.1
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ source = "vcs"
version-file = "src/kohlrahbi/version.py"

[tool.hatch.build.targets.sdist]
exclude = ["/unittests"]
exclude = ["/unittests", "/edi_energy_mirror"]

[tool.hatch.build.targets.wheel]
only-include = ["src"]
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ annotated-types==0.7.0
# via pydantic
click==8.1.7
# via kohlrahbi (pyproject.toml)
colorama==0.4.6
# via
# click
# colorlog
colorlog==6.8.2
# via kohlrahbi (pyproject.toml)
efoli==1.1.0
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ deps =
-r dev_requirements/requirements-test.txt
syrupy
setenv = PYTHONPATH = {toxinidir}/src
commands = python -m pytest --basetemp={envtmpdir} {posargs} --snapshot-update
commands = python -m pytest -m snapshot --basetemp={envtmpdir} {posargs} --snapshot-update

[testenv:lint]
# the lint environment is called by the Github Action that runs the linter
Expand Down
88 changes: 88 additions & 0 deletions unittests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,91 @@

path_to_test_edi_energy_mirror_repo: Path = Path(__file__).parent / "test-edi-energy-mirror-repo"
path_to_test_files_fv2310 = path_to_test_edi_energy_mirror_repo / "edi_energy_de" / Path("FV2310")
# list of pruefis to check against in test_current_state
current_state_pruefis = [
"13002",
"13014",
"13023",
"15002",
"17002",
"17010",
"17114",
"17129",
"17201",
"17208",
"17301",
"19002",
"19007",
"19016",
"19103",
"19120",
"19131",
"19204",
"19301",
"19302",
"21002",
"21010",
"21015",
"21030",
"21039",
"23001",
"23009",
"25001",
"25003",
"25004",
"25006",
"25009",
"27001",
"27003",
"29001",
"29002",
"31001",
"31003",
"31007",
"31011",
"33004",
"35001",
"35004",
"37000",
"37002",
"37005",
"39000",
"39002",
"44001",
"44005",
"44009",
"44016",
"44023",
"44040",
"44053",
"44103",
"44105",
"44112",
"44117",
"44138",
"44140",
"44148",
"44163",
"44180",
"55003",
"55009",
"55014",
"55035",
"55041",
"55062",
"55074",
"55075",
"55077",
"55081",
"55086",
"55093",
"55105",
"55115",
"55127",
"55147",
"55157",
"55182",
"55200",
"55213",
"55555",
]
490 changes: 490 additions & 0 deletions unittests/__snapshots__/test_ahb.ambr

Large diffs are not rendered by default.

20,373 changes: 16,873 additions & 3,500 deletions unittests/__snapshots__/test_current_state.ambr

Large diffs are not rendered by default.

39 changes: 4 additions & 35 deletions unittests/test_ahb.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,14 @@
from unittests import path_to_test_edi_energy_mirror_repo, path_to_test_files_fv2310


@pytest.mark.snapshot
class TestAhb:
def test_extract_pruefis_from_docx(self) -> None:
"""
extract_pruefis_from_docx.
"""
input_path = path_to_test_files_fv2310 / Path(
"COMDISAHB-informatorischeLesefassung1.0dKonsolidierteLesefassungmitFehlerkorrekturenStand19.06.2023_20230719_20231001.docx"
)
pruefis = extract_pruefis_from_docx(input_path)
assert (
"29001" in pruefis
and pruefis["29001"]
== "COMDISAHB-informatorischeLesefassung1.0dKonsolidierteLesefassungmitFehlerkorrekturenStand19.06.2023_20230719_20231001.docx"
)
assert (
"29002" in pruefis
and pruefis["29002"]
== "COMDISAHB-informatorischeLesefassung1.0dKonsolidierteLesefassungmitFehlerkorrekturenStand19.06.2023_20230719_20231001.docx"
)

def test_find_pruefidentifikatoren(self):
def test_find_pruefidentifikatoren(self, snapshot):
"""
test find_pruefidentifikatoren.
"""
pruefis = find_pruefidentifikatoren(path_to_test_files_fv2310)
assert (
"29001" in pruefis
and pruefis["29001"]
== "COMDISAHB-informatorischeLesefassung1.0dKonsolidierteLesefassungmitFehlerkorrekturenStand19.06.2023_20230719_20231001.docx"
)
assert (
"17201" in pruefis
and pruefis["17201"] == "ORDERSORDRSPAHBMaBiS-informatorischeLesefassung2.2c_99991231_20231001.docx"
)
assert (
"37001" in pruefis
and pruefis["37001"]
== "PARTINAHB-informatorischeLesefassung1.0cKonsolidierteLesefassungmitFehlerkorrekturenStand29.09.2023_20240402_20231001.docx"
)
pruefis = find_pruefidentifikatoren(Path(__file__).parents[1] / "edi_energy_mirror/edi_energy_de/FV2310")
assert pruefis == snapshot

def test_get_ahb_documents_path(self):
"""
Expand Down
27 changes: 14 additions & 13 deletions unittests/test_current_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from click.testing import CliRunner, Result

from kohlrahbi import cli
from unittests import path_to_test_edi_energy_mirror_repo, path_to_test_files_fv2310
from unittests import current_state_pruefis

# Setup basic configuration for logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
Expand All @@ -25,6 +25,7 @@ def get_csv_paths(root_dir) -> list[Path]:
return [path for path in root_path.rglob("*.csv")]


@pytest.mark.snapshot
class TestCli:
"""
This class contains the unit tests for the CLI tool.
Expand All @@ -36,29 +37,32 @@ class TestCli:
pytest.param(
[
"ahb",
"--assume-yes",
"--format-version",
"FV2310",
"FV2404",
"--file-type",
"csv",
"-p",
pruefi,
],
{"exit_code": 0, "output_snippet": ""},
id="proof of concept",
id=pruefi,
)
for pruefi in current_state_pruefis
],
)
def test_kohlrahbi_cli_with_valid_arguments(
self, argument_options: list[str], expected_response: dict[str, Union[str, int]], snapshot
self, argument_options: list[str], expected_response: dict[str, Union[str, int]], snapshot, tmp_path
):
"""
This test runs the CLI tool with valid arguments and checks if the output is as expected.
"""

actual_output_dir = path_to_test_files_fv2310 / "actual-output"
actual_output_dir = tmp_path / "actual-output"

argument_options.extend(
[
"--edi-energy-mirror-path",
str(path_to_test_edi_energy_mirror_repo),
str(Path(__file__).parents[1] / "edi_energy_mirror"),
"--output-path",
str(actual_output_dir),
]
Expand All @@ -76,10 +80,7 @@ def test_kohlrahbi_cli_with_valid_arguments(

# Check if the generated files are the same as the expected files

path_to_actual_csv_files = get_csv_paths(actual_output_dir)
path_to_actual_csv_file = get_csv_paths(actual_output_dir)

actual_csv_dict: dict[str, str] = {}
for file in path_to_actual_csv_files:
with open(file, "r", encoding="utf-8") as actual_csv:
actual_csv_dict[file.name] = actual_csv.read()
assert snapshot == actual_csv_dict
with open(path_to_actual_csv_file[0], "r", encoding="utf-8") as actual_csv:
assert snapshot == actual_csv.read()

0 comments on commit f9bce1e

Please sign in to comment.