summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kvmd/apps/__init__.py2
-rw-r--r--kvmd/validators/kvm.py8
-rw-r--r--testenv/tests/validators/test_kvm.py48
3 files changed, 53 insertions, 5 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index 9c8f5c03..c03fc48b 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -84,8 +84,8 @@ from ..validators.kvm import valid_stream_resolution
from ..validators.kvm import valid_hid_key
from ..validators.kvm import valid_hid_mouse_move
from ..validators.kvm import valid_ugpio_driver
-from ..validators.kvm import valid_ugpio_mode
from ..validators.kvm import valid_ugpio_channel
+from ..validators.kvm import valid_ugpio_mode
from ..validators.kvm import valid_ugpio_view_table
from ..validators.hw import valid_gpio_pin
diff --git a/kvmd/validators/kvm.py b/kvmd/validators/kvm.py
index 0374ebd8..b06edf95 100644
--- a/kvmd/validators/kvm.py
+++ b/kvmd/validators/kvm.py
@@ -111,15 +111,15 @@ def valid_ugpio_driver(arg: Any, variants: Optional[Set[str]]=None) -> str:
return arg
-def valid_ugpio_mode(arg: Any) -> str:
- return check_string_in_list(arg, "GPIO mode", ["input", "output"])
-
-
def valid_ugpio_channel(arg: Any) -> str:
name = "GPIO channel"
return check_len(check_re_match(arg, name, r"^[a-zA-Z_][a-zA-Z0-9_-]*$"), name, 255)
+def valid_ugpio_mode(arg: Any) -> str:
+ return check_string_in_list(arg, "GPIO mode", ["input", "output"])
+
+
def valid_ugpio_view_table(arg: Any) -> List[List[str]]:
try:
return [list(map(str, row)) for row in list(arg)]
diff --git a/testenv/tests/validators/test_kvm.py b/testenv/tests/validators/test_kvm.py
index 61f5a7be..cab03198 100644
--- a/testenv/tests/validators/test_kvm.py
+++ b/testenv/tests/validators/test_kvm.py
@@ -20,6 +20,7 @@
# ========================================================================== #
+from typing import Callable
from typing import Any
import pytest
@@ -38,6 +39,9 @@ from kvmd.validators.kvm import valid_hid_key
from kvmd.validators.kvm import valid_hid_mouse_move
from kvmd.validators.kvm import valid_hid_mouse_button
from kvmd.validators.kvm import valid_hid_mouse_wheel
+from kvmd.validators.kvm import valid_ugpio_driver
+from kvmd.validators.kvm import valid_ugpio_channel
+from kvmd.validators.kvm import valid_ugpio_mode
# =====
@@ -197,3 +201,47 @@ def test_ok__valid_hid_mouse_wheel__p200() -> None:
def test_fail__valid_hid_mouse_wheel(arg: Any) -> None:
with pytest.raises(ValidatorError):
print(valid_hid_mouse_wheel(arg))
+
+
+# =====
[email protected]("validator", [valid_ugpio_driver, valid_ugpio_channel])
+ "test-",
+ "glados",
+ "test",
+ "_",
+ "_foo_bar_",
+ " aix",
+ "a" * 255,
+])
+def test_ok__valid_ugpio_item(validator: Callable[[Any], str], arg: Any) -> None:
+ assert validator(arg) == arg.strip()
+
+
[email protected]("validator", [valid_ugpio_driver, valid_ugpio_channel])
+ "ั‚ะตัั‚",
+ "-molestia",
+ "te~st",
+ "-",
+ "-foo_bar",
+ "a" * 256,
+ " ",
+ "",
+ None,
+])
+def test_fail__valid_ugpio_item(validator: Callable[[Any], str], arg: Any) -> None:
+ with pytest.raises(ValidatorError):
+ print(validator(arg))
+
+
+# =====
[email protected]("arg", ["Input ", " OUTPUT "])
+def test_ok__valid_ugpio_mode(arg: Any) -> None:
+ assert valid_ugpio_mode(arg) == arg.strip().lower()
+
+
[email protected]("arg", ["test", "", None])
+def test_fail__valid_ugpio_mode(arg: Any) -> None:
+ with pytest.raises(ValidatorError):
+ print(valid_ugpio_mode(arg))