Merge ~jfguedez/juju-lint:fix-unit-tests into juju-lint:master

Proposed by Jose Guedez
Status: Merged
Approved by: James Troup
Approved revision: 4594e4175ff4aa5396ffa6bac49ce3295e5f828b
Merged at revision: 25a0f732a2268d9b950f7702f415f9f7ed3a78e4
Proposed branch: ~jfguedez/juju-lint:fix-unit-tests
Merge into: juju-lint:master
Diff against target: 262 lines (+70/-23)
6 files modified
Makefile (+1/-1)
jujulint/cli.py (+9/-1)
jujulint/config.py (+1/-1)
jujulint/lint.py (+54/-16)
tests/conftest.py (+3/-2)
tests/test_jujulint.py (+2/-2)
Reviewer Review Type Date Requested Status
Linda Guo (community) Approve
Juju Lint maintainers Pending
Review via email: mp+402958@code.launchpad.net

Commit message

Fix current unit tests and formatting

To post a comment you must log in.
Revision history for this message
Jose Guedez (jfguedez) wrote :

Fixes the current broken unit tests:

collected 4 items

tests/test_cli.py::test_pytest PASSED [ 25%]
tests/test_cli.py::test_cli_fixture PASSED [ 50%]
tests/test_jujulint.py::test_flatten_list PASSED [ 75%]
tests/test_jujulint.py::test_map_charms PASSED [100%]

-------------------------------- generated xml file: /home/jguedez/canonical/repos/bootstack/juju-lint/tests/report/junit.xml --------------------------------
--------------------------- generated html file: file:///home/jguedez/canonical/repos/bootstack/juju-lint/tests/report/index.html ----------------------------

----------- coverage: platform linux, python 3.8.5-final-0 -----------
Name Stmts Miss Cover
-------------------------------------------
jujulint/__init__.py 0 0 100%
jujulint/cli.py 79 54 32%
jujulint/cloud.py 170 150 12%
jujulint/config.py 17 0 100%
jujulint/k8s.py 13 13 0%
jujulint/lint.py 388 331 15%
jujulint/logging.py 49 26 47%
jujulint/openstack.py 14 5 64%
jujulint/util.py 20 3 85%
-------------------------------------------
TOTAL 750 582 22%
Coverage annotated source written to dir tests/report/coverage-annotated
Coverage HTML written to dir tests/report/coverage-html

===================================================================== 4 passed in 0.65s ======================================================================
__________________________________________________________________________ summary ___________________________________________________________________________
  unit: commands succeeded
  congratulations :)

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
Linda Guo (lihuiguo) wrote :

lgtm

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

Change successfully merged at revision 25a0f732a2268d9b950f7702f415f9f7ed3a78e4

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/Makefile b/Makefile
2index 03f0a84..917e96b 100644
3--- a/Makefile
4+++ b/Makefile
5@@ -9,4 +9,4 @@ deb-src:
6 debuild -S -sa -I.git -I.tox
7
8 test:
9- tox -e py3-test
10+ tox -e unit
11diff --git a/jujulint/cli.py b/jujulint/cli.py
12index 68e7bb2..8892420 100755
13--- a/jujulint/cli.py
14+++ b/jujulint/cli.py
15@@ -36,7 +36,15 @@ class Cli:
16 """Create new CLI and configure runtime environment."""
17 self.config = Config()
18 self.logger = Logger(self.config["logging"]["loglevel"].get())
19- self.version = pkg_resources.require("jujulint")[0].version
20+
21+ # get the version of the current package if available
22+ # this will fail if not running from an installed package
23+ # e.g. during unit tests
24+ try:
25+ self.version = pkg_resources.require("jujulint")[0].version
26+ except pkg_resources.DistributionNotFound:
27+ self.version = "unknown"
28+
29 rules_file = self.config["rules"]["file"].get()
30 # handle absolute path provided
31 if os.path.isfile(rules_file):
32diff --git a/jujulint/config.py b/jujulint/config.py
33index fb5497a..05b7883 100644
34--- a/jujulint/config.py
35+++ b/jujulint/config.py
36@@ -67,7 +67,7 @@ class Config(Configuration):
37 self.parser.add_argument(
38 "manual-file",
39 metavar="manual-file",
40- nargs='?',
41+ nargs="?",
42 type=str,
43 default=None,
44 help=(
45diff --git a/jujulint/lint.py b/jujulint/lint.py
46index 70f5ae6..ce49398 100755
47--- a/jujulint/lint.py
48+++ b/jujulint/lint.py
49@@ -95,7 +95,9 @@ class Linter:
50 )
51 )
52 self.lint_rules["subordinates"][name] = dict(where=where)
53- self.lint_rules["known charms"] = flatten_list(self.lint_rules["known charms"])
54+ self.lint_rules["known charms"] = flatten_list(
55+ self.lint_rules["known charms"]
56+ )
57 self.logger.debug(
58 "[{}] [{}/{}] Lint Rules: {}".format(
59 self.cloud_name,
60@@ -236,13 +238,21 @@ class Linter:
61 if check_value is False:
62 self.logger.debug(
63 "[{}] [{}/{}] (PASS) Application {} is correctly using default config for {}.".format(
64- self.cloud_name, self.controller_name, self.model_name, name, rule,
65+ self.cloud_name,
66+ self.controller_name,
67+ self.model_name,
68+ name,
69+ rule,
70 )
71 )
72 return True
73 self.logger.error(
74 "[{}] [{}/{}] (FAIL) Application {} has no manual config for {}.".format(
75- self.cloud_name, self.controller_name, self.model_name, name, rule,
76+ self.cloud_name,
77+ self.controller_name,
78+ self.model_name,
79+ name,
80+ rule,
81 )
82 )
83 return False
84@@ -440,13 +450,17 @@ class Linter:
85 continue
86 self.logger.debug(
87 "[{}] [{}/{}] ... and we are a host, will fallthrough".format(
88- self.cloud_name, self.controller_name, self.model_name,
89+ self.cloud_name,
90+ self.controller_name,
91+ self.model_name,
92 )
93 )
94 elif where == "all or nothing" and required_sub not in all_or_nothing:
95 self.logger.debug(
96 "[{}] [{}/{}] requirement is 'all or nothing' and was 'nothing'.".format(
97- self.cloud_name, self.controller_name, self.model_name,
98+ self.cloud_name,
99+ self.controller_name,
100+ self.model_name,
101 )
102 )
103 continue
104@@ -455,7 +469,9 @@ class Linter:
105 elif where == "container aware":
106 self.logger.debug(
107 "[{}] [{}/{}] requirement is 'container aware'.".format(
108- self.cloud_name, self.controller_name, self.model_name,
109+ self.cloud_name,
110+ self.controller_name,
111+ self.model_name,
112 )
113 )
114 if is_container(machine):
115@@ -476,7 +492,9 @@ class Linter:
116 )
117 exceptions = []
118 if "exceptions" in self.lint_rules["subordinates"][required_sub]:
119- exceptions = self.lint_rules["subordinates"][required_sub]["exceptions"]
120+ exceptions = self.lint_rules["subordinates"][required_sub][
121+ "exceptions"
122+ ]
123 self.logger.debug(
124 "[{}] [{}/{}] -> exceptions == {}".format(
125 self.cloud_name,
126@@ -529,14 +547,18 @@ class Linter:
127 if not found:
128 self.logger.debug(
129 "[{}] [{}/{}] -> NOT FOUND".format(
130- self.cloud_name, self.controller_name, self.model_name,
131+ self.cloud_name,
132+ self.controller_name,
133+ self.model_name,
134 )
135 )
136 for app in self.model.apps_on_machines[machine]:
137 self.model.missing_subs[required_sub].add(app)
138 self.logger.debug(
139 "[{}] [{}/{}] -> continue-ing back out...".format(
140- self.cloud_name, self.controller_name, self.model_name,
141+ self.cloud_name,
142+ self.controller_name,
143+ self.model_name,
144 )
145 )
146 continue
147@@ -552,7 +574,9 @@ class Linter:
148 )
149 self.logger.debug(
150 "[{}] [{}/{}] requirement is 'all' OR we fell through.".format(
151- self.cloud_name, self.controller_name, self.model_name,
152+ self.cloud_name,
153+ self.controller_name,
154+ self.model_name,
155 )
156 )
157 if required_sub not in present_subs:
158@@ -567,7 +591,9 @@ class Linter:
159 continue
160 self.logger.debug(
161 "[{}] [{}/{}] not found.".format(
162- self.cloud_name, self.controller_name, self.model_name,
163+ self.cloud_name,
164+ self.controller_name,
165+ self.model_name,
166 )
167 )
168 for app in self.model.apps_on_machines[machine]:
169@@ -612,7 +638,10 @@ class Linter:
170 if charm not in self.model.charms:
171 self.logger.error(
172 "[{}] Ops charm '{}' in OpenStack model {} on controller {} not found".format(
173- self.cloud_name, charm, self.model_name, self.controller_name
174+ self.cloud_name,
175+ charm,
176+ self.model_name,
177+ self.controller_name,
178 )
179 )
180 elif self.cloud_type == "kubernetes":
181@@ -656,7 +685,9 @@ class Linter:
182 if self.model.duelling_subs:
183 self.logger.error(
184 "[{}] [{}/{}] following subordinates where found on machines more than once:".format(
185- self.cloud_name, self.controller_name, self.model_name,
186+ self.cloud_name,
187+ self.controller_name,
188+ self.model_name,
189 )
190 )
191 for sub in self.model.duelling_subs:
192@@ -782,7 +813,10 @@ class Linter:
193 else:
194 self.logger.warn(
195 "[{}] [{}/{}] Could not determine appropriate status key for {}.".format(
196- self.cloud_name, self.controller_name, self.model_name, name,
197+ self.cloud_name,
198+ self.controller_name,
199+ self.model_name,
200+ name,
201 )
202 )
203
204@@ -913,7 +947,9 @@ class Linter:
205 "[{}] [{}/{}] Relations data found; assuming a bundle and "
206 "skipping AZ and status checks."
207 ).format(
208- self.cloud_name, self.model_name, self.controller_name,
209+ self.cloud_name,
210+ self.model_name,
211+ self.controller_name,
212 )
213 )
214
215@@ -921,6 +957,8 @@ class Linter:
216 else:
217 self.logger.warn(
218 "[{}] [{}/{}] Model contains no applications, skipping.".format(
219- self.cloud_name, self.controller_name, self.model_name,
220+ self.cloud_name,
221+ self.controller_name,
222+ self.model_name,
223 )
224 )
225diff --git a/tests/conftest.py b/tests/conftest.py
226index c95eb69..ef72390 100644
227--- a/tests/conftest.py
228+++ b/tests/conftest.py
229@@ -27,10 +27,11 @@ def mocked_pkg_resources(monkeypatch):
230
231
232 @pytest.fixture
233-def cli():
234+def cli(monkeypatch):
235 """Provide a test instance of the CLI class."""
236- from jujulint.cli import Cli
237+ monkeypatch.setattr(sys, "argv", ["juju-lint", "-c", "contrib/canonical-rules.yaml"])
238
239+ from jujulint.cli import Cli
240 cli = Cli()
241
242 return cli
243diff --git a/tests/test_jujulint.py b/tests/test_jujulint.py
244index ba2dbf7..4c27cc1 100644
245--- a/tests/test_jujulint.py
246+++ b/tests/test_jujulint.py
247@@ -16,7 +16,7 @@ def test_flatten_list(utils):
248 assert flattened_list == utils.flatten_list(unflattened_list)
249
250
251-def test_map_charms(lint):
252+def test_map_charms(lint, utils):
253 """Test the charm name validation code."""
254 applications = {
255 "test-app-1": {"charm": "cs:~USER/SERIES/TEST-CHARM12-123"},
256@@ -32,5 +32,5 @@ def test_map_charms(lint):
257 applications = {
258 "test-app1": {"charm": "cs:invalid-charm$"},
259 }
260- with pytest.raises(jujulint.lint.InvalidCharmNameError):
261+ with pytest.raises(utils.InvalidCharmNameError):
262 lint.map_charms(applications)

Subscribers

People subscribed via source and target branches