Skip to content

Commit afa094d

Browse files
lvrfrc87chadellitdependsnetworkspszulczewskiscetron
authored
Implement ge and le operator type (#89)
* Release 0.0.2 (#88) * Update readme to start with use cases (#84) * Update readme to start with use cases * Apply suggestions from code review Co-authored-by: Patryk Szulczewski <[email protected]> Co-authored-by: Stephen Corry <[email protected]> * Update README.md Co-authored-by: Patryk Szulczewski <[email protected]> Co-authored-by: Stephen Corry <[email protected]> * Doc update (#87) * Fix operator checks to follow other check_type logic. (#85) * Fix operator checks to follow other check_type logic. * Add new release 0.0.2 Co-authored-by: Patryk Szulczewski <[email protected]> Co-authored-by: Christian Adell <[email protected]> Co-authored-by: Ken Celenza <[email protected]> Co-authored-by: Patryk Szulczewski <[email protected]> Co-authored-by: Stephen Corry <[email protected]> Co-authored-by: Patryk Szulczewski <[email protected]> * add operator ge and le * fix validate tests Co-authored-by: Christian Adell <[email protected]> Co-authored-by: Ken Celenza <[email protected]> Co-authored-by: Patryk Szulczewski <[email protected]> Co-authored-by: Stephen Corry <[email protected]> Co-authored-by: Patryk Szulczewski <[email protected]>
1 parent 7d47d7c commit afa094d

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

docs/usage.md

+5
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,12 @@ The `operator` check is a collection of more specific checks divided into catego
478478
2. `is-lt`: Check if the value of a specified element is lesser than a given numeric value.
479479
- `is-lt: 55`: checks if value is lower than 55 or not.
480480

481+
3. `is-ge`: Check if the value of a specified element is greater than or equal to a given numeric value.
482+
- `is-ge: 2`: checks if value should be greater or equal than 2.
481483

484+
4. `is-le`: Check if the value of a specified element is lesser than or equal a given numeric value.
485+
- `is-le: 55`: checks if value is lower or equal than 55 or not.
486+
482487
Examples:
483488

484489
```python

jdiff/check_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def _validate(params) -> None: # type: ignore[override]
176176
"""Validate operator parameters."""
177177
in_operators = ("is-in", "not-in", "in-range", "not-in-range")
178178
bool_operators = ("all-same",)
179-
number_operators = ("is-gt", "is-lt")
179+
number_operators = ("is-gt", "is-lt", "is-ge", "is-le")
180180
string_operators = ("contains", "not-contains")
181181
valid_options = (
182182
in_operators,

jdiff/operator.py

+10
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def call_evaluation_logic():
5151

5252
ops = {
5353
">": operator.gt,
54+
">=": operator.ge,
5455
"<": operator.lt,
56+
"<=": operator.le,
5557
"is_in": operator.contains,
5658
"not_in": operator.contains,
5759
"contains": operator.contains,
@@ -99,10 +101,18 @@ def is_gt(self) -> Tuple[List, bool]:
99101
"""Is greather than operator caller."""
100102
return self._loop_through_wrapper(">")
101103

104+
def is_ge(self) -> Tuple[List, bool]:
105+
"""Is greather or equal than operator caller."""
106+
return self._loop_through_wrapper(">=")
107+
102108
def is_lt(self) -> Tuple[List, bool]:
103109
"""Is lower than operator caller."""
104110
return self._loop_through_wrapper("<")
105111

112+
def is_le(self) -> Tuple[List, bool]:
113+
"""Is lower or equal than operator caller."""
114+
return self._loop_through_wrapper("<=")
115+
106116
def is_in(self) -> Tuple[List, bool]:
107117
"""Is in operator caller."""
108118
return self._loop_through_wrapper("is_in")

tests/test_operators.py

+32
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,41 @@
7575
"result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]",
7676
([], True),
7777
)
78+
operator_is_ge_equal = (
79+
"pre.json",
80+
"operator",
81+
{"params": {"mode": "is-ge", "operator_data": 50}},
82+
"result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]",
83+
([], True),
84+
)
85+
operator_is_ge_greater = (
86+
"pre.json",
87+
"operator",
88+
{"params": {"mode": "is-ge", "operator_data": 20}},
89+
"result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]",
90+
([], True),
91+
)
7892
operator_is_lt = (
7993
"pre.json",
8094
"operator",
8195
{"params": {"mode": "is-lt", "operator_data": 60}},
8296
"result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]",
8397
([], True),
8498
)
99+
operator_is_le_equal = (
100+
"pre.json",
101+
"operator",
102+
{"params": {"mode": "is-le", "operator_data": 50}},
103+
"result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]",
104+
([], True),
105+
)
106+
operator_is_le_lower = (
107+
"pre.json",
108+
"operator",
109+
{"params": {"mode": "is-le", "operator_data": 60}},
110+
"result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]",
111+
([], True),
112+
)
85113
operator_is_in = (
86114
"pre.json",
87115
"operator",
@@ -132,7 +160,11 @@
132160
operator_contains,
133161
operator_not_contains,
134162
operator_is_gt,
163+
operator_is_ge_equal,
164+
operator_is_ge_greater,
135165
operator_is_lt,
166+
operator_is_le_equal,
167+
operator_is_le_lower,
136168
operator_is_in,
137169
operator_not_in,
138170
operator_in_range,

tests/test_validates.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
operator_params_wrong_operator = (
6666
"operator",
6767
{"params": {"mode": "random", "operator_data": [20, 40, 60]}},
68-
"'params' value must be one of the following: ['is-in', 'not-in', 'in-range', 'not-in-range', 'all-same', 'is-gt', 'is-lt', 'contains', 'not-contains']. You have: random",
68+
"'params' value must be one of the following: ['is-in', 'not-in', 'in-range', 'not-in-range', 'all-same', 'is-gt', 'is-lt', 'is-ge', 'is-le', 'contains', 'not-contains']. You have: random",
6969
)
7070
operator_params_in = (
7171
"operator",
@@ -85,7 +85,7 @@
8585
operator_params_number = (
8686
"operator",
8787
{"params": {"mode": "is-gt", "operator_data": "1"}},
88-
"check options ('is-gt', 'is-lt') must have value of type float or int. You have: 1 of type <class 'str'>",
88+
"check options ('is-gt', 'is-lt', 'is-ge', 'is-le') must have value of type float or int. You have: 1 of type <class 'str'>",
8989
)
9090
operator_params_contains = (
9191
"operator",

0 commit comments

Comments
 (0)