62 lines
1.7 KiB
Python

"""Tests for the string tool module."""
from typing import Any
import pytest
from aki_prj23_transparenzregister.utils import string_tools
def test_import() -> None:
"""Tests if the import is possible."""
assert string_tools
@pytest.mark.parametrize(
("value", "expected"),
[
("None ", "None"),
(" ", None),
("", None),
("\t", None),
("\n", None),
(" Some String ", "Some String"),
("Some String", "Some String"),
],
)
def test_simplify_string(value: str | None, expected: str | None) -> None:
"""Tests the sting simplification."""
assert string_tools.simplify_string(value) == expected
@pytest.mark.parametrize("value", [0, 0.1, True, ("1",), {}, set()])
def test_simplify_string_type_error(value: Any) -> None:
"""Tests if the type error is thrown when the value is the wrong type."""
with pytest.raises(TypeError):
assert string_tools.simplify_string(value)
@pytest.mark.parametrize(
("value", "expected"),
[
("10.10.1111", "1111-10-10"),
("10.10.98", "1998-10-10"),
],
)
def test_transform_date_to_iso(value: str, expected: str) -> None:
result = string_tools.transform_date_to_iso(value)
assert result == expected
@pytest.mark.parametrize(
("value", "expected_result"),
[
(None, None),
('"Siemes Verwaltungs-GmbH"', "Siemes Verwaltungs-GmbH"),
('"Hans"-Wurst GmbH', '"Hans"-Wurst GmbH'),
('Hans-Wurst GmbH"', "Hans-Wurst GmbH"),
],
)
def test_remove_trailing_and_leading_quotes(value: str, expected_result: str) -> None:
result = string_tools.remove_traling_and_leading_quotes(value)
assert result == expected_result