Merge ~mertkirpici/juju-lint:lp/1993735 into juju-lint:master

Proposed by Mert Kirpici
Status: Merged
Approved by: Robert Gildein
Approved revision: ff6c048579ecf261cc2cdb6b3bafecf644af4b71
Merged at revision: 1108dacb9fe66ef726d4764bcd2a3703ef6bfa14
Proposed branch: ~mertkirpici/juju-lint:lp/1993735
Merge into: juju-lint:master
Diff against target: 70 lines (+22/-10)
2 files modified
jujulint/lint.py (+15/-0)
tests/unit/test_jujulint.py (+7/-10)
Reviewer Review Type Date Requested Status
🤖 prod-jenkaas-bootstack continuous-integration Approve
Robert Gildein Approve
Gabriel Cocenza Approve
BootStack Reviewers Pending
Review via email: mp+432462@code.launchpad.net

Commit message

Close LP #1993735

Description of the change

The callback function `helper_operator_eq_check` for the eq operator, has an overloaded behavior. It first tries regex matching and if that is not successful, it tests for regular string equality checking.

This caused some issues when testing against an empty string. A check value of empty string used to match any kind of input, which is quite counter-intuitive.

With this change we are adding an exception for the empty string case to force string equality check in that case. Also adding a deprecation notice for the overloaded regex checking behavior to inform the users that it will be removed in the future.

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Robert Gildein (rgildein) wrote :

One suggestion and I think that we need to rewrite
`test_helper_operator_check` test function.

review: Needs Fixing
Revision history for this message
Mert Kirpici (mertkirpici) wrote :

Hi Robert thanks for the review and suggestions. I applied both of them in the update.

Revision history for this message
Gabriel Cocenza (gabrielcocenza) wrote :

LGTM

review: Approve
Revision history for this message
Robert Gildein (rgildein) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 1108dacb9fe66ef726d4764bcd2a3703ef6bfa14

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/jujulint/lint.py b/jujulint/lint.py
2index f73b7ea..4219b2f 100755
3--- a/jujulint/lint.py
4+++ b/jujulint/lint.py
5@@ -60,6 +60,16 @@ ConfigOperator = collections.namedtuple(
6
7 def helper_operator_eq_check(check_value, actual_value):
8 """Perform the actual equality check for the eq/neq rules."""
9+ # An empty string regex matches any string. Therefore
10+ # we are handling the empty string as a special case for now
11+ # as a workaround.
12+ # The overloaded regex matching behavior will be removed in a
13+ # future version.
14+ #
15+ # See LP #1993735
16+ if check_value == "":
17+ return check_value == actual_value
18+
19 match = False
20 try:
21 match = re.match(re.compile(str(check_value)), str(actual_value))
22@@ -126,6 +136,11 @@ class Linter:
23
24 # collect errors only for non-text output (e.g. json)
25 self.collect_errors = True if self.output_format != "text" else False
26+ self.logger.warn(
27+ "Regex autodetection feature of the eq operator is deprecated. "
28+ "It will only check for equality in the future. "
29+ "Please use the search operator for regex checks."
30+ )
31
32 def read_rules(self):
33 """Read and parse rules from YAML, optionally processing provided overrides."""
34diff --git a/tests/unit/test_jujulint.py b/tests/unit/test_jujulint.py
35index c87722d..9f95f43 100644
36--- a/tests/unit/test_jujulint.py
37+++ b/tests/unit/test_jujulint.py
38@@ -1540,25 +1540,22 @@ applications:
39 logger_mock.warn.assert_called_once_with(expected_msg)
40
41 @pytest.mark.parametrize(
42- "regex_error, check_value, actual_value",
43+ "expected_result, check_value, actual_value",
44 [
45 (True, "same", "same"),
46- (True, "same", "different"),
47- (False, "same", "same"),
48 (False, "same", "different"),
49+ (False, "same", "Same"),
50+ (True, "[sS]ame", "Same"),
51+ (True, "[same", "[same"),
52+ (False, "", "foo"),
53+ (True, "", ""),
54 ],
55 )
56 def test_helper_operator_check(
57- self, regex_error, check_value, actual_value, mocker
58+ self, expected_result, check_value, actual_value, mocker
59 ):
60 """Test comparing values using "helper_operator_check()" function."""
61- if regex_error:
62- mocker.patch.object(lint.re, "match", side_effect=lint.re.error(""))
63-
64- expected_result = check_value == actual_value
65-
66 result = lint.helper_operator_eq_check(check_value, actual_value)
67-
68 assert bool(result) == expected_result
69
70 @pytest.mark.parametrize(

Subscribers

People subscribed via source and target branches