Skip to content

Commit 9eef933

Browse files
committed
Significant improvements to the checkers module
- Added `OPERATORS` constant dictionary to define comparison operations. - Introduced `is_valid_value` and `assert_is_valid_value` functions for value validation based on operators. - Updated documentation in `checkers.md` to include new functions and constants. - Enhanced test coverage in `test_checkers.py` for the new validation functions. - Improved docstrings across all functions
1 parent 8fc37d6 commit 9eef933

3 files changed

Lines changed: 377 additions & 127 deletions

File tree

docs/code/checkers.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
-
66

77

8+
## Constants
9+
10+
::: toolbox_python.checkers
11+
options:
12+
show_root_heading: false
13+
members:
14+
- OPERATORS
15+
16+
817
## `is_*()` functions
918

1019
::: toolbox_python.checkers
@@ -17,6 +26,7 @@
1726
- is_value_in_iterable
1827
- is_all_values_in_iterable
1928
- is_any_values_in_iterable
29+
- is_valid_value
2030

2131

2232
## `is_*()` function aliases
@@ -31,6 +41,7 @@
3141
- is_in
3242
- is_any_in
3343
- is_all_in
44+
- is_valid
3445

3546

3647
## `assert_*()` functions
@@ -45,6 +56,7 @@
4556
- assert_value_in_iterable
4657
- assert_any_values_in_iterable
4758
- assert_all_values_in_iterable
59+
- assert_is_valid_value
4860

4961

5062
## `assert_*()` function aliases
@@ -54,11 +66,15 @@
5466
show_root_heading: false
5567
members:
5668
- assert_type
69+
- assert_is_type
5770
- assert_all_type
71+
- assert_all_is_type
5872
- assert_any_type
73+
- assert_any_is_type
5974
- assert_in
6075
- assert_any_in
6176
- assert_all_in
77+
- assert_is_valid
6278

6379

6480
## `*_contains()` functions

src/tests/test_checkers.py

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
from parameterized import parameterized
2020

2121
# ## Local First Party Imports ----
22-
from tests.setup import name_func_nested_list, name_func_predefined_name
22+
from tests.setup import (
23+
name_func_flat_list,
24+
name_func_nested_list,
25+
name_func_predefined_name,
26+
)
2327
from toolbox_python.checkers import (
2428
all_elements_contains,
2529
any_element_contains,
@@ -32,6 +36,7 @@
3236
assert_any_values_in_iterable,
3337
assert_any_values_of_type,
3438
assert_in,
39+
assert_is_valid,
3540
assert_type,
3641
assert_value_in_iterable,
3742
assert_value_of_type,
@@ -46,6 +51,7 @@
4651
is_any_values_of_type,
4752
is_in,
4853
is_type,
54+
is_valid,
4955
is_value_in_iterable,
5056
is_value_of_type,
5157
)
@@ -75,7 +81,12 @@
7581
# ---------------------------------------------------------------------------- #
7682

7783

78-
class TestSuite(TestCase):
84+
## --------------------------------------------------------------------------- #
85+
## Types ####
86+
## --------------------------------------------------------------------------- #
87+
88+
89+
class TestTypes(TestCase):
7990

8091
def setUp(self) -> None:
8192
pass
@@ -230,6 +241,14 @@ def test_is_any_values_of_type(
230241
assert_any_values_of_type(_vals, _typ)
231242
assert_any_type(_vals, _typ)
232243

244+
245+
## --------------------------------------------------------------------------- #
246+
## Iterables ####
247+
## --------------------------------------------------------------------------- #
248+
249+
250+
class TestIterables(TestCase):
251+
233252
@parameterized.expand(
234253
(
235254
("list", ["a", "b", "c"]),
@@ -371,3 +390,68 @@ def test_get_elements_containing(
371390
_out = tuple(sorted(_out))
372391
_exp = tuple(sorted(_exp))
373392
assert _out == _exp
393+
394+
395+
## --------------------------------------------------------------------------- #
396+
## Values ####
397+
## --------------------------------------------------------------------------- #
398+
399+
400+
TRUES = (
401+
(5, "<", 10),
402+
(5, "<=", 10),
403+
(5, "<=", 5),
404+
(10, ">", 5),
405+
(10, ">=", 5),
406+
(5, ">=", 5),
407+
(5, "==", 5),
408+
(5, "!=", 10),
409+
(3, "in", [1, 2, 3, 4]),
410+
(5, "not in", (1, 2, 3, 4)),
411+
)
412+
FALSES = (
413+
(10, "<", 5),
414+
(10, "<=", 5),
415+
(5, ">", 10),
416+
(5, ">=", 10),
417+
(5, "==", 10),
418+
(5, "!=", 5),
419+
(5, "in", [1, 2, 3, 4]),
420+
(3, "not in", (1, 2, 3, 4)),
421+
)
422+
423+
424+
class TestValues(TestCase):
425+
426+
@parameterized.expand(
427+
input=TRUES,
428+
name_func=name_func_flat_list,
429+
)
430+
def test_is_valid(self, _val: Any, _op: str, _targ: Any) -> None:
431+
assert is_valid(_val, _op, _targ) == True
432+
433+
@parameterized.expand(
434+
input=FALSES,
435+
name_func=name_func_flat_list,
436+
)
437+
def test_not_is_valid(self, _val: Any, _op: str, _targ: Any) -> None:
438+
assert is_valid(_val, _op, _targ) == False
439+
440+
@parameterized.expand(
441+
input=TRUES,
442+
name_func=name_func_flat_list,
443+
)
444+
def test_assert_is_valid(self, _val: Any, _op: str, _targ: Any) -> None:
445+
assert assert_is_valid(_val, _op, _targ) is None
446+
447+
@parameterized.expand(
448+
input=FALSES,
449+
name_func=name_func_flat_list,
450+
)
451+
def test_assert_not_is_valid(self, _val: Any, _op: str, _targ: Any) -> None:
452+
with pytest.raises(ValueError):
453+
assert_is_valid(_val, _op, _targ)
454+
455+
def test_assert_is_valid_unknown_operator(self) -> None:
456+
with pytest.raises(ValueError):
457+
assert_is_valid(5, "unknown", 10)

0 commit comments

Comments
 (0)