From 2211124ecba827c916882f3a291d8b227ea5fdcf Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Wed, 9 Sep 2020 03:58:43 +0300 Subject: tests --- testenv/tests/validators/test_hw.py | 2 ++ testenv/tests/validators/test_kvm.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'testenv/tests') diff --git a/testenv/tests/validators/test_hw.py b/testenv/tests/validators/test_hw.py index a10a5feb..912f8f5e 100644 --- a/testenv/tests/validators/test_hw.py +++ b/testenv/tests/validators/test_hw.py @@ -82,6 +82,7 @@ def test_fail__valid_gpio_pin_optional(arg: Any) -> None: "_", "_foo_bar_", " aix", + "a" * 255, ]) def test_ok__valid_otg_gadget(arg: Any) -> None: assert valid_otg_gadget(arg) == arg.strip() @@ -93,6 +94,7 @@ def test_ok__valid_otg_gadget(arg: Any) -> None: "te~st", "-", "-foo_bar", + "a" * 256, " ", "", None, diff --git a/testenv/tests/validators/test_kvm.py b/testenv/tests/validators/test_kvm.py index 0fdf6a9a..61f5a7be 100644 --- a/testenv/tests/validators/test_kvm.py +++ b/testenv/tests/validators/test_kvm.py @@ -29,6 +29,7 @@ from kvmd.keyboard.mappings import KEYMAP from kvmd.validators import ValidatorError from kvmd.validators.kvm import valid_atx_power_action from kvmd.validators.kvm import valid_atx_button +from kvmd.validators.kvm import valid_info_fields from kvmd.validators.kvm import valid_log_seek from kvmd.validators.kvm import valid_stream_quality from kvmd.validators.kvm import valid_stream_fps @@ -63,6 +64,20 @@ def test_fail__valid_atx_button(arg: Any) -> None: print(valid_atx_button(arg)) +# ===== +@pytest.mark.parametrize("arg", [" foo ", "bar", "foo, ,bar,", " ", " , ", ""]) +def test_ok__valid_info_fields(arg: Any) -> None: + value = valid_info_fields(arg, set(["foo", "bar"])) + assert type(value) == set # pylint: disable=unidiomatic-typecheck + assert value == set(filter(None, map(str.strip, str(arg).split(",")))) + + +@pytest.mark.parametrize("arg", ["xxx", "yyy", "foo,xxx", None]) +def test_fail__valid_info_fields(arg: Any) -> None: + with pytest.raises(ValidatorError): + print(valid_info_fields(arg, set(["foo", "bar"]))) + + # ===== @pytest.mark.parametrize("arg", ["0 ", 0, 1, 13]) def test_ok__valid_log_seek(arg: Any) -> None: -- cgit v1.2.3