Merge ~jfguedez/juju-lint:neq-fix-and-lint-error into juju-lint:master

Proposed by Jose Guedez
Status: Merged
Approved by: James Troup
Approved revision: aaeb71b9c00a30053a142eecb6bf9a247f0a8e69
Merged at revision: e4a01123bd2ca031412216d6cbee2320f47e94bd
Proposed branch: ~jfguedez/juju-lint:neq-fix-and-lint-error
Merge into: juju-lint:master
Diff against target: 65 lines (+16/-8)
3 files modified
jujulint/lint.py (+1/-3)
jujulint/util.py (+1/-0)
tests/test_jujulint.py (+14/-5)
Reviewer Review Type Date Requested Status
Edin S (community) Approve
Juju Lint maintainers Pending
Review via email: mp+408595@code.launchpad.net

Commit message

Fix issue with 'neq' logic (empty string), and some lint errors

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
Edin S (exsdev) :
review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision e4a01123bd2ca031412216d6cbee2320f47e94bd

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 5328723..4648d45 100755
3--- a/jujulint/lint.py
4+++ b/jujulint/lint.py
5@@ -276,9 +276,7 @@ class Linter:
6 operator = ConfigOperator(
7 name="neq",
8 repr="!=",
9- check=lambda check_value, actual_value: not helper_operator_eq_check(
10- check_value, actual_value
11- ),
12+ check=lambda check_value, actual_value: check_value != actual_value,
13 error_template="Application {} has incorrect setting for '{}': Should not be {}",
14 )
15
16diff --git a/jujulint/util.py b/jujulint/util.py
17index bdd7008..b8c1359 100644
18--- a/jujulint/util.py
19+++ b/jujulint/util.py
20@@ -47,6 +47,7 @@ def is_container(machine):
21
22
23 def extract_charm_name(charm):
24+ """Extract the charm name using regex."""
25 match = re.match(
26 r"^(?:\w+:)?(?:~[\w\.-]+/)?(?:\w+/)?([a-zA-Z0-9-]+?)(?:-\d+)?$", charm
27 )
28diff --git a/tests/test_jujulint.py b/tests/test_jujulint.py
29index cd41c58..96499d2 100644
30--- a/tests/test_jujulint.py
31+++ b/tests/test_jujulint.py
32@@ -301,10 +301,19 @@ class TestLinter:
33 assert errors[0]["expected_value"] is False
34 assert errors[0]["actual_value"] is True
35
36- def test_config_neq(self, linter, juju_status):
37+ def test_config_neq_valid(self, linter, juju_status):
38 """Test the config condition 'neq'."""
39- linter.lint_rules["config"] = {"ubuntu": {"fake-opt": {"neq": False}}}
40- juju_status["applications"]["ubuntu"]["options"] = {"fake-opt": False}
41+ linter.lint_rules["config"] = {"ubuntu": {"fake-opt": {"neq": "foo"}}}
42+ juju_status["applications"]["ubuntu"]["options"] = {"fake-opt": "bar"}
43+ linter.do_lint(juju_status)
44+
45+ errors = linter.output_collector["errors"]
46+ assert len(errors) == 0
47+
48+ def test_config_neq_invalid(self, linter, juju_status):
49+ """Test the config condition 'neq', valid."""
50+ linter.lint_rules["config"] = {"ubuntu": {"fake-opt": {"neq": ""}}}
51+ juju_status["applications"]["ubuntu"]["options"] = {"fake-opt": ""}
52 linter.do_lint(juju_status)
53
54 errors = linter.output_collector["errors"]
55@@ -312,8 +321,8 @@ class TestLinter:
56 assert errors[0]["id"] == "config-neq-check"
57 assert errors[0]["application"] == "ubuntu"
58 assert errors[0]["rule"] == "fake-opt"
59- assert errors[0]["expected_value"] is False
60- assert errors[0]["actual_value"] is False
61+ assert errors[0]["expected_value"] == ""
62+ assert errors[0]["actual_value"] == ""
63
64 def test_config_gte(self, linter, juju_status):
65 """Test the config condition 'gte'."""

Subscribers

People subscribed via source and target branches