1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
import pytest
from pathvalidate import Platform
from pathvalidate.error import ErrorReason, ValidationError, _to_error_code
class Test_to_error_code:
@pytest.mark.parametrize(
["value", "expected"],
[
[1, "PV0001"],
],
)
def test_normal(self, value, expected):
assert _to_error_code(value) == expected
class Test_str:
@pytest.mark.parametrize(
["value", "expected"],
[
[
ValidationError(
description="hoge",
platform=Platform.UNIVERSAL,
reason=ErrorReason.INVALID_CHARACTER,
),
"[PV1100] invalid characters found: platform=universal, description=hoge",
],
],
)
def test_normal(self, value, expected):
assert str(value) == expected
class Test_as_slog:
@pytest.mark.parametrize(
["value", "expected"],
[
[
ValidationError(
description="hoge",
platform=Platform.UNIVERSAL,
reason=ErrorReason.INVALID_CHARACTER,
),
{"code": "PV1100", "description": "hoge", "platform": "universal"},
],
],
)
def test_normal(self, value, expected):
assert value.as_slog() == expected
|