diff options
author | Devaev Maxim <[email protected]> | 2019-04-14 23:15:06 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-04-14 23:16:29 +0300 |
commit | bc0deaee5f487ec2bb752a9dbe78ffe51d2559e5 (patch) | |
tree | d14dc029c3ecb57dec1824427cdec479b15a5ddc /tests/validators | |
parent | 92260645c57689665c1fcd3f65b79a059d99d421 (diff) |
moved tests to testenv
Diffstat (limited to 'tests/validators')
-rw-r--r-- | tests/validators/__init__.py | 20 | ||||
-rw-r--r-- | tests/validators/test_auth.py | 130 | ||||
-rw-r--r-- | tests/validators/test_basic.py | 144 | ||||
-rw-r--r-- | tests/validators/test_hw.py | 72 | ||||
-rw-r--r-- | tests/validators/test_kvm.py | 169 | ||||
-rw-r--r-- | tests/validators/test_net.py | 122 | ||||
-rw-r--r-- | tests/validators/test_os.py | 118 |
7 files changed, 0 insertions, 775 deletions
diff --git a/tests/validators/__init__.py b/tests/validators/__init__.py deleted file mode 100644 index 1e91f7fa..00000000 --- a/tests/validators/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# ========================================================================== # -# # -# KVMD - The main Pi-KVM daemon. # -# # -# Copyright (C) 2018 Maxim Devaev <[email protected]> # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <https://www.gnu.org/licenses/>. # -# # -# ========================================================================== # diff --git a/tests/validators/test_auth.py b/tests/validators/test_auth.py deleted file mode 100644 index f3cdf939..00000000 --- a/tests/validators/test_auth.py +++ /dev/null @@ -1,130 +0,0 @@ -# ========================================================================== # -# # -# KVMD - The main Pi-KVM daemon. # -# # -# Copyright (C) 2018 Maxim Devaev <[email protected]> # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <https://www.gnu.org/licenses/>. # -# # -# ========================================================================== # - - -from typing import List -from typing import Any - -import pytest - -from kvmd.validators import ValidatorError -from kvmd.validators.auth import valid_user -from kvmd.validators.auth import valid_users_list -from kvmd.validators.auth import valid_passwd -from kvmd.validators.auth import valid_auth_token - - -# ===== [email protected]("arg", [ - "test-", - "glados", - "test", - "_", - "_foo_bar_", - " aix", -]) -def test_ok__valid_user(arg: Any) -> None: - assert valid_user(arg) == arg.strip() - - [email protected]("arg", [ - "тест", - "-molestia", - "te~st", - "-", - "-foo_bar", - " ", - "", - None, -]) -def test_fail__valid_user(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_user(arg)) - - -# ===== [email protected]("arg, retval", [ - ("foo, bar, ", ["foo", "bar"]), - ("foo bar", ["foo", "bar"]), - (["foo", "bar"], ["foo", "bar"]), - ("", []), - (" ", []), - (", ", []), - (", foo, ", ["foo"]), - ([], []), -]) -def test_ok__valid_users_list(arg: Any, retval: List) -> None: - assert valid_users_list(arg) == retval - - [email protected]("arg", [None, [None], [""], [" "], ["user,"]]) -def test_fail__valid_users_list(arg: Any) -> None: # pylint: disable=invalid-name - with pytest.raises(ValidatorError): - print(valid_users_list(arg)) - - -# ===== [email protected]("arg", [ - "glados", - "test", - "_", - "_foo_bar_", - " aix", - " ", - "", - " O(*#&@)FD*S)D(F ", -]) -def test_ok__valid_passwd(arg: Any) -> None: - assert valid_passwd(arg) == arg - - [email protected]("arg", [ - "тест", - "\n", - " \n", - "\n\n", - "\r", - None, -]) -def test_fail__valid_passwd(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_passwd(arg)) - - -# ===== [email protected]("arg", [ - ("0" * 64) + " ", - ("f" * 64) + " ", -]) -def test_ok__valid_auth_token(arg: Any) -> None: - assert valid_auth_token(arg) == arg.strip() - - [email protected]("arg", [ - ("F" * 64), - "0" * 63, - "0" * 65, - "", - None, -]) -def test_fail__valid_auth_token(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_auth_token(arg)) diff --git a/tests/validators/test_basic.py b/tests/validators/test_basic.py deleted file mode 100644 index 96feb666..00000000 --- a/tests/validators/test_basic.py +++ /dev/null @@ -1,144 +0,0 @@ -# ========================================================================== # -# # -# KVMD - The main Pi-KVM daemon. # -# # -# Copyright (C) 2018 Maxim Devaev <[email protected]> # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <https://www.gnu.org/licenses/>. # -# # -# ========================================================================== # - - -from typing import List -from typing import Any - -import pytest - -from kvmd.validators import ValidatorError -from kvmd.validators.basic import valid_bool -from kvmd.validators.basic import valid_number -from kvmd.validators.basic import valid_int_f1 -from kvmd.validators.basic import valid_float_f01 -from kvmd.validators.basic import valid_string_list - - -# ===== [email protected]("arg, retval", [ - ("1", True), - ("true", True), - ("TRUE", True), - ("yes ", True), - (1, True), - (True, True), - ("0", False), - ("false", False), - ("FALSE", False), - ("no ", False), - (0, False), - (False, False), -]) -def test_ok__valid_bool(arg: Any, retval: bool) -> None: - assert valid_bool(arg) == retval - - [email protected]("arg", ["test", "", None, -1, "x"]) -def test_fail__valid_bool(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_bool(arg)) - - -# ===== [email protected]("arg", ["1 ", "-1", 1, -1, 0, 100500]) -def test_ok__valid_number(arg: Any) -> None: - assert valid_number(arg) == int(str(arg).strip()) - - [email protected]("arg", ["test", "", None, "1x", 100500.0]) -def test_fail__valid_number(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_number(arg)) - - [email protected]("arg", [-5, 0, 5, "-5 ", "0 ", "5 "]) -def test_ok__valid_number__min_max(arg: Any) -> None: - assert valid_number(arg, -5, 5) == int(str(arg).strip()) - - [email protected]("arg", ["test", "", None, -6, 6, "-6 ", "6 "]) -def test_fail__valid_number__min_max(arg: Any) -> None: # pylint: disable=invalid-name - with pytest.raises(ValidatorError): - print(valid_number(arg, -5, 5)) - - -# ===== [email protected]("arg", [1, 5, "5 "]) -def test_ok__valid_int_f1(arg: Any) -> None: - value = valid_int_f1(arg) - assert type(value) == int # pylint: disable=unidiomatic-typecheck - assert value == int(str(arg).strip()) - - [email protected]("arg", ["test", "", None, -6, "-6 ", 0, "0 ", "5.0"]) -def test_fail__valid_int_f1(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_int_f1(arg)) - - -# ===== [email protected]("arg", [0.1, 1, 5, "5 ", "5.0 "]) -def test_ok__valid_float_f01(arg: Any) -> None: - value = valid_float_f01(arg) - assert type(value) == float # pylint: disable=unidiomatic-typecheck - assert value == float(str(arg).strip()) - - [email protected]("arg", ["test", "", None, 0.0, "0.0", -6, "-6", 0, "0"]) -def test_fail__valid_float_f01(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_float_f01(arg)) - - -# ===== [email protected]("arg, retval", [ - ("a, b, c", ["a", "b", "c"]), - ("a b c", ["a", "b", "c"]), - (["a", "b", "c"], ["a", "b", "c"]), - ("", []), - (" ", []), - (", ", []), - (", a, ", ["a"]), - ([], []), -]) -def test_ok__valid_string_list(arg: Any, retval: List) -> None: - assert valid_string_list(arg) == retval - - [email protected]("arg, retval", [ - ("1, 2, 3", [1, 2, 3]), - ("1 2 3", [1, 2, 3]), - ([1, 2, 3], [1, 2, 3]), - ("", []), - (" ", []), - (", ", []), - (", 1, ", [1]), - ([], []), -]) -def test_ok__valid_string_list__subval(arg: Any, retval: List) -> None: # pylint: disable=invalid-name - assert valid_string_list(arg, subval=int) == retval - - [email protected]("arg", [None, [None]]) -def test_fail__valid_string_list(arg: Any) -> None: # pylint: disable=invalid-name - with pytest.raises(ValidatorError): - print(valid_string_list(arg)) diff --git a/tests/validators/test_hw.py b/tests/validators/test_hw.py deleted file mode 100644 index 2c93d3eb..00000000 --- a/tests/validators/test_hw.py +++ /dev/null @@ -1,72 +0,0 @@ -# ========================================================================== # -# # -# KVMD - The main Pi-KVM daemon. # -# # -# Copyright (C) 2018 Maxim Devaev <[email protected]> # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <https://www.gnu.org/licenses/>. # -# # -# ========================================================================== # - - -from typing import Any - -import pytest - -from kvmd.validators import ValidatorError -from kvmd.validators.hw import valid_tty_speed -from kvmd.validators.hw import valid_gpio_pin -from kvmd.validators.hw import valid_gpio_pin_optional - - -# ===== [email protected]("arg", ["1200 ", 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200]) -def test_ok__valid_tty_speed(arg: Any) -> None: - value = valid_tty_speed(arg) - assert type(value) == int # pylint: disable=unidiomatic-typecheck - assert value == int(str(arg).strip()) - - [email protected]("arg", ["test", "", None, 0, 1200.1]) -def test_fail__valid_tty_speed(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_tty_speed(arg)) - - -# ===== [email protected]("arg", ["0 ", 0, 1, 13]) -def test_ok__valid_gpio_pin(arg: Any) -> None: - value = valid_gpio_pin(arg) - assert type(value) == int # pylint: disable=unidiomatic-typecheck - assert value == int(str(arg).strip()) - - [email protected]("arg", ["test", "", None, -1, -13, 1.1]) -def test_fail__valid_gpio_pin(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_gpio_pin(arg)) - - -# ===== [email protected]("arg", ["0 ", -1, 0, 1, 13]) -def test_ok__valid_gpio_pin_optional(arg: Any) -> None: - value = valid_gpio_pin_optional(arg) - assert type(value) == int # pylint: disable=unidiomatic-typecheck - assert value == int(str(arg).strip()) - - [email protected]("arg", ["test", "", None, -2, -13, 1.1]) -def test_fail__valid_gpio_pin_optional(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_gpio_pin_optional(arg)) diff --git a/tests/validators/test_kvm.py b/tests/validators/test_kvm.py deleted file mode 100644 index f1050b36..00000000 --- a/tests/validators/test_kvm.py +++ /dev/null @@ -1,169 +0,0 @@ -# ========================================================================== # -# # -# KVMD - The main Pi-KVM daemon. # -# # -# Copyright (C) 2018 Maxim Devaev <[email protected]> # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <https://www.gnu.org/licenses/>. # -# # -# ========================================================================== # - - -from typing import Any - -import pytest - -from kvmd.keymap import KEYMAP - -from kvmd.validators import ValidatorError -from kvmd.validators.kvm import valid_atx_button -from kvmd.validators.kvm import valid_kvm_target -from kvmd.validators.kvm import valid_log_seek -from kvmd.validators.kvm import valid_stream_quality -from kvmd.validators.kvm import valid_stream_fps -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 - - -# ===== [email protected]("arg", ["POWER ", "POWER_LONG ", "RESET "]) -def test_ok__valid_atx_button(arg: Any) -> None: - assert valid_atx_button(arg) == arg.strip().lower() - - [email protected]("arg", ["test", "", None]) -def test_fail__valid_atx_button(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_atx_button(arg)) - - -# ===== [email protected]("arg", ["KVM ", "SERVER "]) -def test_ok__valid_kvm_target(arg: Any) -> None: - assert valid_kvm_target(arg) == arg.strip().lower() - - [email protected]("arg", ["test", "", None]) -def test_fail__valid_kvm_target(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_kvm_target(arg)) - - -# ===== [email protected]("arg", ["0 ", 0, 1, 13]) -def test_ok__valid_log_seek(arg: Any) -> None: - value = valid_log_seek(arg) - assert type(value) == int # pylint: disable=unidiomatic-typecheck - assert value == int(str(arg).strip()) - - [email protected]("arg", ["test", "", None, -1, -13, 1.1]) -def test_fail__valid_log_seek(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_log_seek(arg)) - - -# ===== [email protected]("arg", ["1 ", 20, 100]) -def test_ok__valid_stream_quality(arg: Any) -> None: - value = valid_stream_quality(arg) - assert type(value) == int # pylint: disable=unidiomatic-typecheck - assert value == int(str(arg).strip()) - - [email protected]("arg", ["test", "", None, 0, 101, 1.1]) -def test_fail__valid_stream_quality(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_stream_quality(arg)) - - -# ===== [email protected]("arg", ["1 ", 30]) -def test_ok__valid_stream_fps(arg: Any) -> None: - value = valid_stream_fps(arg) - assert type(value) == int # pylint: disable=unidiomatic-typecheck - assert value == int(str(arg).strip()) - - [email protected]("arg", ["test", "", None, 31, 1.1]) -def test_fail__valid_stream_fps(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_stream_fps(arg)) - - -# ===== -def test_ok__valid_hid_key() -> None: - for key in KEYMAP: - print(valid_hid_key(key)) - print(valid_hid_key(key + " ")) - - [email protected]("arg", ["test", "", None, "keya"]) -def test_fail__valid_hid_key(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_hid_key(arg)) - - -# ===== [email protected]("arg", [-20000, "1 ", "-1", 1, -1, 0, "20000 "]) -def test_ok__valid_hid_mouse_move(arg: Any) -> None: - assert valid_hid_mouse_move(arg) == int(str(arg).strip()) - - -def test_ok__valid_hid_mouse_move__m50000() -> None: - assert valid_hid_mouse_move(-50000) == -32768 - - -def test_ok__valid_hid_mouse_move__p50000() -> None: - assert valid_hid_mouse_move(50000) == 32767 - - [email protected]("arg", ["test", "", None, 1.1]) -def test_fail__valid_hid_mouse_move(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_hid_mouse_move(arg)) - - -# ===== [email protected]("arg", ["LEFT ", "RIGHT "]) -def test_ok__valid_hid_mouse_button(arg: Any) -> None: - assert valid_hid_mouse_button(arg) == arg.strip().lower() - - [email protected]("arg", ["test", "", None]) -def test_fail__valid_hid_mouse_button(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_hid_mouse_button(arg)) - - -# ===== [email protected]("arg", [-100, "1 ", "-1", 1, -1, 0, "100 "]) -def test_ok__valid_hid_mouse_wheel(arg: Any) -> None: - assert valid_hid_mouse_wheel(arg) == int(str(arg).strip()) - - -def test_ok__valid_hid_mouse_wheel__m200() -> None: - assert valid_hid_mouse_wheel(-200) == -128 - - -def test_ok__valid_hid_mouse_wheel__p200() -> None: - assert valid_hid_mouse_wheel(200) == 127 - - [email protected]("arg", ["test", "", None, 1.1]) -def test_fail__valid_hid_mouse_wheel(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_hid_mouse_wheel(arg)) diff --git a/tests/validators/test_net.py b/tests/validators/test_net.py deleted file mode 100644 index eab67c9a..00000000 --- a/tests/validators/test_net.py +++ /dev/null @@ -1,122 +0,0 @@ -# ========================================================================== # -# # -# KVMD - The main Pi-KVM daemon. # -# # -# Copyright (C) 2018 Maxim Devaev <[email protected]> # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <https://www.gnu.org/licenses/>. # -# # -# ========================================================================== # - - -from typing import Any - -import pytest - -from kvmd.validators import ValidatorError -from kvmd.validators.net import valid_ip_or_host -from kvmd.validators.net import valid_ip -from kvmd.validators.net import valid_rfc_host -from kvmd.validators.net import valid_port - - -# ===== [email protected]("arg", [ - "yandex.ru ", - "foobar", - "foo-bar.ru", - "127.0.0.1", - "8.8.8.8", - "::", - "::1", - "2001:500:2f::f", -]) -def test_ok__valid_ip_or_host(arg: Any) -> None: - assert valid_ip_or_host(arg) == arg.strip() - - [email protected]("arg", [ - "foo_bar.ru", - "1.1.1.", - ":", - "", - None, -]) -def test_fail__valid_ip_or_host(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_ip_or_host(arg)) - - -# ===== [email protected]("arg", [ - "127.0.0.1 ", - "8.8.8.8", - "::", - "::1", - "2001:500:2f::f", -]) -def test_ok__valid_ip(arg: Any) -> None: - assert valid_ip(arg) == arg.strip() - - [email protected]("arg", [ - "ya.ru", - "1", - "1.1.1", - "1.1.1.", - ":", - "", - None, -]) -def test_fail__valid_ip(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_ip(arg)) - - -# ===== [email protected]("arg", [ - "yandex.ru ", - "foobar", - "foo-bar.ru", - "z0r.de", - "11.ru", - "127.0.0.1", -]) -def test_ok__valid_rfc_host(arg: Any) -> None: - assert valid_rfc_host(arg) == arg.strip() - - [email protected]("arg", [ - "foobar.ru.", - "foo_bar.ru", - "", - None, -]) -def test_fail__valid_rfc_host(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_rfc_host(arg)) - - -# ===== [email protected]("arg", ["0 ", 0, "22", 443, 65535]) -def test_ok__valid_port(arg: Any) -> None: - value = valid_port(arg) - assert type(value) == int # pylint: disable=unidiomatic-typecheck - assert value == int(str(arg).strip()) - - [email protected]("arg", ["test", "", None, 1.1]) -def test_fail__valid_port(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_port(arg)) diff --git a/tests/validators/test_os.py b/tests/validators/test_os.py deleted file mode 100644 index b280b4b3..00000000 --- a/tests/validators/test_os.py +++ /dev/null @@ -1,118 +0,0 @@ -# ========================================================================== # -# # -# KVMD - The main Pi-KVM daemon. # -# # -# Copyright (C) 2018 Maxim Devaev <[email protected]> # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <https://www.gnu.org/licenses/>. # -# # -# ========================================================================== # - - -import os - -from typing import List -from typing import Any - -import pytest - -from kvmd.validators import ValidatorError -from kvmd.validators.os import valid_abs_path -from kvmd.validators.os import valid_abs_path_exists -from kvmd.validators.os import valid_unix_mode -from kvmd.validators.os import valid_command - - -# ===== [email protected]("arg, retval", [ - ("/..", "/"), - ("/root/..", "/"), - ("/root", "/root"), - ("/f/o/o/b/a/r", "/f/o/o/b/a/r"), - ("~", os.path.abspath(".") + "/~"), - ("/foo~", "/foo~"), - ("/foo/~", "/foo/~"), - (".", os.path.abspath(".")), -]) -def test_ok__valid_abs_path(arg: Any, retval: str) -> None: - assert valid_abs_path(arg) == retval - - [email protected]("arg", ["", " ", None]) -def test_fail__valid_abs_path(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_abs_path(arg)) - - -# ===== [email protected]("arg, retval", [ - ("/..", "/"), - ("/root/..", "/"), - ("/root", "/root"), - (".", os.path.abspath(".")), -]) -def test_ok__valid_abs_path_exists(arg: Any, retval: str) -> None: - assert valid_abs_path_exists(arg) == retval - - [email protected]("arg", [ - "/f/o/o/b/a/r", - "~", - "/foo~", - "/foo/~", - "", - None, -]) -def test_fail__valid_abs_path_exists(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_abs_path_exists(arg)) - - -# ===== [email protected]("arg", [0, 5, "1000"]) -def test_ok__valid_unix_mode(arg: Any) -> None: - value = valid_unix_mode(arg) - assert type(value) == int # pylint: disable=unidiomatic-typecheck - assert value == int(str(value).strip()) - - [email protected]("arg", ["test", "", None, -6, "-6", "5.0"]) -def test_fail__valid_unix_mode(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_unix_mode(arg)) - - -# ===== [email protected]("arg, retval", [ - (["/bin/true"], ["/bin/true"]), - (["/bin/true", 1, 2, 3], ["/bin/true", "1", "2", "3"]), - ("/bin/true, 1, 2, 3,", ["/bin/true", "1", "2", "3"]), - ("/bin/true", ["/bin/true"]), -]) -def test_ok__valid_command(arg: Any, retval: List[str]) -> None: - assert valid_command(arg) == retval - - [email protected]("arg", [ - ["/bin/blahblahblah"], - ["/bin/blahblahblah", 1, 2, 3], - [" "], - [], - "/bin/blahblahblah, 1, 2, 3,", - "/bin/blahblahblah", - " ", -]) -def test_fail__valid_command(arg: Any) -> None: - with pytest.raises(ValidatorError): - print(valid_command(arg)) |