Skip to content

Commit 426d2b7

Browse files
committed
Revert "compare implemetation and invalid testcase fixed"
This reverts commit 8577f7c.
1 parent 32bed45 commit 426d2b7

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

optimizely/helpers/condition.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ def compare_user_version_with_target_version(self, index):
152152

153153
target_version_parts = self.split_semantic_version(target_version)
154154
user_version_parts = self.split_semantic_version(user_version)
155-
if not user_version_parts:
156-
return None
157-
158155
user_version_parts_len = len(user_version_parts)
159156

160157
for (idx, _) in enumerate(target_version_parts):
@@ -406,8 +403,7 @@ def semver_equal_evaluator(self, index):
406403
None:
407404
- if the user version value is not string type or is null.
408405
"""
409-
return self.compare_user_version_with_target_version(
410-
index) == 0 if self.compare_user_version_with_target_version(index) else None
406+
return self.compare_user_version_with_target_version(index) == 0
411407

412408
def semver_greater_than_evaluator(self, index):
413409
""" Evaluate the given semantic version greater than match target version for the user version.
@@ -422,8 +418,7 @@ def semver_greater_than_evaluator(self, index):
422418
None:
423419
- if the user version value is not string type or is null.
424420
"""
425-
return self.compare_user_version_with_target_version(
426-
index) > 0 if self.compare_user_version_with_target_version(index) else None
421+
return self.compare_user_version_with_target_version(index) > 0
427422

428423
def semver_less_than_evaluator(self, index):
429424
""" Evaluate the given semantic version less than match target version for the user version.
@@ -438,8 +433,7 @@ def semver_less_than_evaluator(self, index):
438433
None:
439434
- if the user version value is not string type or is null.
440435
"""
441-
return self.compare_user_version_with_target_version(
442-
index) < 0 if self.compare_user_version_with_target_version(index) else None
436+
return self.compare_user_version_with_target_version(index) < 0
443437

444438
def semver_less_than_or_equal_evaluator(self, index):
445439
""" Evaluate the given semantic version less than or equal to match target version for the user version.
@@ -454,8 +448,7 @@ def semver_less_than_or_equal_evaluator(self, index):
454448
None:
455449
- if the user version value is not string type or is null.
456450
"""
457-
return self.compare_user_version_with_target_version(
458-
index) <= 0 if self.compare_user_version_with_target_version(index) else None
451+
return self.compare_user_version_with_target_version(index) <= 0
459452

460453
def semver_greater_than_or_equal_evaluator(self, index):
461454
""" Evaluate the given semantic version greater than or equal to match target version for the user version.
@@ -470,8 +463,7 @@ def semver_greater_than_or_equal_evaluator(self, index):
470463
None:
471464
- if the user version value is not string type or is null.
472465
"""
473-
return self.compare_user_version_with_target_version(
474-
index) >= 0 if self.compare_user_version_with_target_version(index) else None
466+
return self.compare_user_version_with_target_version(index) >= 0
475467

476468
EVALUATORS_BY_MATCH_TYPE = {
477469
ConditionMatchTypes.EXACT: exact_evaluator,

tests/helpers_tests/test_condition.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,13 +2019,11 @@ def test_substring__condition_value_invalid(self):
20192019
).format(json.dumps(expected_condition_log))
20202020
)
20212021

2022-
def test_invalid_semver__returns_None__when_semver_is_invalid(self):
2023-
invalid_test_cases = ["-", ".", "..", "+", "+test", " ", "2 .0. 0",
2024-
"2.", ".0.0", "1.2.2.2", "2.x", ",",
2025-
"+build-prerelese"]
2026-
2027-
for invalid_test_case in invalid_test_cases:
2028-
evaluator = condition_helper.CustomAttributeConditionEvaluator(
2029-
semver_less_than_or_equal_2_0_1_condition_list, {'Android': invalid_test_case}, self.mock_client_logger)
2022+
@pytest.mark.parametrize("test_input,expected", [(i, None) for i in ["-", ".", "..", "+", "+test", " ", "2 .0. 0",
2023+
"2.", ".0.0", "1.2.2.2", "2.x", ",",
2024+
"+build-prerelese"]])
2025+
def test_invalid_semver__returns_null__when_semver_is_invalid(self, test_input, expected):
2026+
evaluator = condition_helper.CustomAttributeConditionEvaluator(
2027+
semver_less_than_or_equal_2_0_1_condition_list, {'Android': test_input}, self.mock_client_logger)
20302028

2031-
self.assertIsNone(evaluator.evaluate(0))
2029+
assert eval(evaluator.evaluate(0)) == expected

0 commit comments

Comments
 (0)