Merge ~jfguedez/juju-lint:fix-unit-tests into juju-lint:master
- Git
- lp:~jfguedez/juju-lint
- fix-unit-tests
- Merge into 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) |
Related bugs: |
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
Description of the change
To post a comment you must log in.
Revision history for this message
Jose Guedez (jfguedez) wrote : | # |
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
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
Change successfully merged at revision 25a0f732a2268d9
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/Makefile b/Makefile | |||
2 | index 03f0a84..917e96b 100644 | |||
3 | --- a/Makefile | |||
4 | +++ b/Makefile | |||
5 | @@ -9,4 +9,4 @@ deb-src: | |||
6 | 9 | debuild -S -sa -I.git -I.tox | 9 | debuild -S -sa -I.git -I.tox |
7 | 10 | 10 | ||
8 | 11 | test: | 11 | test: |
10 | 12 | tox -e py3-test | 12 | tox -e unit |
11 | diff --git a/jujulint/cli.py b/jujulint/cli.py | |||
12 | index 68e7bb2..8892420 100755 | |||
13 | --- a/jujulint/cli.py | |||
14 | +++ b/jujulint/cli.py | |||
15 | @@ -36,7 +36,15 @@ class Cli: | |||
16 | 36 | """Create new CLI and configure runtime environment.""" | 36 | """Create new CLI and configure runtime environment.""" |
17 | 37 | self.config = Config() | 37 | self.config = Config() |
18 | 38 | self.logger = Logger(self.config["logging"]["loglevel"].get()) | 38 | self.logger = Logger(self.config["logging"]["loglevel"].get()) |
20 | 39 | self.version = pkg_resources.require("jujulint")[0].version | 39 | |
21 | 40 | # get the version of the current package if available | ||
22 | 41 | # this will fail if not running from an installed package | ||
23 | 42 | # e.g. during unit tests | ||
24 | 43 | try: | ||
25 | 44 | self.version = pkg_resources.require("jujulint")[0].version | ||
26 | 45 | except pkg_resources.DistributionNotFound: | ||
27 | 46 | self.version = "unknown" | ||
28 | 47 | |||
29 | 40 | rules_file = self.config["rules"]["file"].get() | 48 | rules_file = self.config["rules"]["file"].get() |
30 | 41 | # handle absolute path provided | 49 | # handle absolute path provided |
31 | 42 | if os.path.isfile(rules_file): | 50 | if os.path.isfile(rules_file): |
32 | diff --git a/jujulint/config.py b/jujulint/config.py | |||
33 | index fb5497a..05b7883 100644 | |||
34 | --- a/jujulint/config.py | |||
35 | +++ b/jujulint/config.py | |||
36 | @@ -67,7 +67,7 @@ class Config(Configuration): | |||
37 | 67 | self.parser.add_argument( | 67 | self.parser.add_argument( |
38 | 68 | "manual-file", | 68 | "manual-file", |
39 | 69 | metavar="manual-file", | 69 | metavar="manual-file", |
41 | 70 | nargs='?', | 70 | nargs="?", |
42 | 71 | type=str, | 71 | type=str, |
43 | 72 | default=None, | 72 | default=None, |
44 | 73 | help=( | 73 | help=( |
45 | diff --git a/jujulint/lint.py b/jujulint/lint.py | |||
46 | index 70f5ae6..ce49398 100755 | |||
47 | --- a/jujulint/lint.py | |||
48 | +++ b/jujulint/lint.py | |||
49 | @@ -95,7 +95,9 @@ class Linter: | |||
50 | 95 | ) | 95 | ) |
51 | 96 | ) | 96 | ) |
52 | 97 | self.lint_rules["subordinates"][name] = dict(where=where) | 97 | self.lint_rules["subordinates"][name] = dict(where=where) |
54 | 98 | self.lint_rules["known charms"] = flatten_list(self.lint_rules["known charms"]) | 98 | self.lint_rules["known charms"] = flatten_list( |
55 | 99 | self.lint_rules["known charms"] | ||
56 | 100 | ) | ||
57 | 99 | self.logger.debug( | 101 | self.logger.debug( |
58 | 100 | "[{}] [{}/{}] Lint Rules: {}".format( | 102 | "[{}] [{}/{}] Lint Rules: {}".format( |
59 | 101 | self.cloud_name, | 103 | self.cloud_name, |
60 | @@ -236,13 +238,21 @@ class Linter: | |||
61 | 236 | if check_value is False: | 238 | if check_value is False: |
62 | 237 | self.logger.debug( | 239 | self.logger.debug( |
63 | 238 | "[{}] [{}/{}] (PASS) Application {} is correctly using default config for {}.".format( | 240 | "[{}] [{}/{}] (PASS) Application {} is correctly using default config for {}.".format( |
65 | 239 | self.cloud_name, self.controller_name, self.model_name, name, rule, | 241 | self.cloud_name, |
66 | 242 | self.controller_name, | ||
67 | 243 | self.model_name, | ||
68 | 244 | name, | ||
69 | 245 | rule, | ||
70 | 240 | ) | 246 | ) |
71 | 241 | ) | 247 | ) |
72 | 242 | return True | 248 | return True |
73 | 243 | self.logger.error( | 249 | self.logger.error( |
74 | 244 | "[{}] [{}/{}] (FAIL) Application {} has no manual config for {}.".format( | 250 | "[{}] [{}/{}] (FAIL) Application {} has no manual config for {}.".format( |
76 | 245 | self.cloud_name, self.controller_name, self.model_name, name, rule, | 251 | self.cloud_name, |
77 | 252 | self.controller_name, | ||
78 | 253 | self.model_name, | ||
79 | 254 | name, | ||
80 | 255 | rule, | ||
81 | 246 | ) | 256 | ) |
82 | 247 | ) | 257 | ) |
83 | 248 | return False | 258 | return False |
84 | @@ -440,13 +450,17 @@ class Linter: | |||
85 | 440 | continue | 450 | continue |
86 | 441 | self.logger.debug( | 451 | self.logger.debug( |
87 | 442 | "[{}] [{}/{}] ... and we are a host, will fallthrough".format( | 452 | "[{}] [{}/{}] ... and we are a host, will fallthrough".format( |
89 | 443 | self.cloud_name, self.controller_name, self.model_name, | 453 | self.cloud_name, |
90 | 454 | self.controller_name, | ||
91 | 455 | self.model_name, | ||
92 | 444 | ) | 456 | ) |
93 | 445 | ) | 457 | ) |
94 | 446 | elif where == "all or nothing" and required_sub not in all_or_nothing: | 458 | elif where == "all or nothing" and required_sub not in all_or_nothing: |
95 | 447 | self.logger.debug( | 459 | self.logger.debug( |
96 | 448 | "[{}] [{}/{}] requirement is 'all or nothing' and was 'nothing'.".format( | 460 | "[{}] [{}/{}] requirement is 'all or nothing' and was 'nothing'.".format( |
98 | 449 | self.cloud_name, self.controller_name, self.model_name, | 461 | self.cloud_name, |
99 | 462 | self.controller_name, | ||
100 | 463 | self.model_name, | ||
101 | 450 | ) | 464 | ) |
102 | 451 | ) | 465 | ) |
103 | 452 | continue | 466 | continue |
104 | @@ -455,7 +469,9 @@ class Linter: | |||
105 | 455 | elif where == "container aware": | 469 | elif where == "container aware": |
106 | 456 | self.logger.debug( | 470 | self.logger.debug( |
107 | 457 | "[{}] [{}/{}] requirement is 'container aware'.".format( | 471 | "[{}] [{}/{}] requirement is 'container aware'.".format( |
109 | 458 | self.cloud_name, self.controller_name, self.model_name, | 472 | self.cloud_name, |
110 | 473 | self.controller_name, | ||
111 | 474 | self.model_name, | ||
112 | 459 | ) | 475 | ) |
113 | 460 | ) | 476 | ) |
114 | 461 | if is_container(machine): | 477 | if is_container(machine): |
115 | @@ -476,7 +492,9 @@ class Linter: | |||
116 | 476 | ) | 492 | ) |
117 | 477 | exceptions = [] | 493 | exceptions = [] |
118 | 478 | if "exceptions" in self.lint_rules["subordinates"][required_sub]: | 494 | if "exceptions" in self.lint_rules["subordinates"][required_sub]: |
120 | 479 | exceptions = self.lint_rules["subordinates"][required_sub]["exceptions"] | 495 | exceptions = self.lint_rules["subordinates"][required_sub][ |
121 | 496 | "exceptions" | ||
122 | 497 | ] | ||
123 | 480 | self.logger.debug( | 498 | self.logger.debug( |
124 | 481 | "[{}] [{}/{}] -> exceptions == {}".format( | 499 | "[{}] [{}/{}] -> exceptions == {}".format( |
125 | 482 | self.cloud_name, | 500 | self.cloud_name, |
126 | @@ -529,14 +547,18 @@ class Linter: | |||
127 | 529 | if not found: | 547 | if not found: |
128 | 530 | self.logger.debug( | 548 | self.logger.debug( |
129 | 531 | "[{}] [{}/{}] -> NOT FOUND".format( | 549 | "[{}] [{}/{}] -> NOT FOUND".format( |
131 | 532 | self.cloud_name, self.controller_name, self.model_name, | 550 | self.cloud_name, |
132 | 551 | self.controller_name, | ||
133 | 552 | self.model_name, | ||
134 | 533 | ) | 553 | ) |
135 | 534 | ) | 554 | ) |
136 | 535 | for app in self.model.apps_on_machines[machine]: | 555 | for app in self.model.apps_on_machines[machine]: |
137 | 536 | self.model.missing_subs[required_sub].add(app) | 556 | self.model.missing_subs[required_sub].add(app) |
138 | 537 | self.logger.debug( | 557 | self.logger.debug( |
139 | 538 | "[{}] [{}/{}] -> continue-ing back out...".format( | 558 | "[{}] [{}/{}] -> continue-ing back out...".format( |
141 | 539 | self.cloud_name, self.controller_name, self.model_name, | 559 | self.cloud_name, |
142 | 560 | self.controller_name, | ||
143 | 561 | self.model_name, | ||
144 | 540 | ) | 562 | ) |
145 | 541 | ) | 563 | ) |
146 | 542 | continue | 564 | continue |
147 | @@ -552,7 +574,9 @@ class Linter: | |||
148 | 552 | ) | 574 | ) |
149 | 553 | self.logger.debug( | 575 | self.logger.debug( |
150 | 554 | "[{}] [{}/{}] requirement is 'all' OR we fell through.".format( | 576 | "[{}] [{}/{}] requirement is 'all' OR we fell through.".format( |
152 | 555 | self.cloud_name, self.controller_name, self.model_name, | 577 | self.cloud_name, |
153 | 578 | self.controller_name, | ||
154 | 579 | self.model_name, | ||
155 | 556 | ) | 580 | ) |
156 | 557 | ) | 581 | ) |
157 | 558 | if required_sub not in present_subs: | 582 | if required_sub not in present_subs: |
158 | @@ -567,7 +591,9 @@ class Linter: | |||
159 | 567 | continue | 591 | continue |
160 | 568 | self.logger.debug( | 592 | self.logger.debug( |
161 | 569 | "[{}] [{}/{}] not found.".format( | 593 | "[{}] [{}/{}] not found.".format( |
163 | 570 | self.cloud_name, self.controller_name, self.model_name, | 594 | self.cloud_name, |
164 | 595 | self.controller_name, | ||
165 | 596 | self.model_name, | ||
166 | 571 | ) | 597 | ) |
167 | 572 | ) | 598 | ) |
168 | 573 | for app in self.model.apps_on_machines[machine]: | 599 | for app in self.model.apps_on_machines[machine]: |
169 | @@ -612,7 +638,10 @@ class Linter: | |||
170 | 612 | if charm not in self.model.charms: | 638 | if charm not in self.model.charms: |
171 | 613 | self.logger.error( | 639 | self.logger.error( |
172 | 614 | "[{}] Ops charm '{}' in OpenStack model {} on controller {} not found".format( | 640 | "[{}] Ops charm '{}' in OpenStack model {} on controller {} not found".format( |
174 | 615 | self.cloud_name, charm, self.model_name, self.controller_name | 641 | self.cloud_name, |
175 | 642 | charm, | ||
176 | 643 | self.model_name, | ||
177 | 644 | self.controller_name, | ||
178 | 616 | ) | 645 | ) |
179 | 617 | ) | 646 | ) |
180 | 618 | elif self.cloud_type == "kubernetes": | 647 | elif self.cloud_type == "kubernetes": |
181 | @@ -656,7 +685,9 @@ class Linter: | |||
182 | 656 | if self.model.duelling_subs: | 685 | if self.model.duelling_subs: |
183 | 657 | self.logger.error( | 686 | self.logger.error( |
184 | 658 | "[{}] [{}/{}] following subordinates where found on machines more than once:".format( | 687 | "[{}] [{}/{}] following subordinates where found on machines more than once:".format( |
186 | 659 | self.cloud_name, self.controller_name, self.model_name, | 688 | self.cloud_name, |
187 | 689 | self.controller_name, | ||
188 | 690 | self.model_name, | ||
189 | 660 | ) | 691 | ) |
190 | 661 | ) | 692 | ) |
191 | 662 | for sub in self.model.duelling_subs: | 693 | for sub in self.model.duelling_subs: |
192 | @@ -782,7 +813,10 @@ class Linter: | |||
193 | 782 | else: | 813 | else: |
194 | 783 | self.logger.warn( | 814 | self.logger.warn( |
195 | 784 | "[{}] [{}/{}] Could not determine appropriate status key for {}.".format( | 815 | "[{}] [{}/{}] Could not determine appropriate status key for {}.".format( |
197 | 785 | self.cloud_name, self.controller_name, self.model_name, name, | 816 | self.cloud_name, |
198 | 817 | self.controller_name, | ||
199 | 818 | self.model_name, | ||
200 | 819 | name, | ||
201 | 786 | ) | 820 | ) |
202 | 787 | ) | 821 | ) |
203 | 788 | 822 | ||
204 | @@ -913,7 +947,9 @@ class Linter: | |||
205 | 913 | "[{}] [{}/{}] Relations data found; assuming a bundle and " | 947 | "[{}] [{}/{}] Relations data found; assuming a bundle and " |
206 | 914 | "skipping AZ and status checks." | 948 | "skipping AZ and status checks." |
207 | 915 | ).format( | 949 | ).format( |
209 | 916 | self.cloud_name, self.model_name, self.controller_name, | 950 | self.cloud_name, |
210 | 951 | self.model_name, | ||
211 | 952 | self.controller_name, | ||
212 | 917 | ) | 953 | ) |
213 | 918 | ) | 954 | ) |
214 | 919 | 955 | ||
215 | @@ -921,6 +957,8 @@ class Linter: | |||
216 | 921 | else: | 957 | else: |
217 | 922 | self.logger.warn( | 958 | self.logger.warn( |
218 | 923 | "[{}] [{}/{}] Model contains no applications, skipping.".format( | 959 | "[{}] [{}/{}] Model contains no applications, skipping.".format( |
220 | 924 | self.cloud_name, self.controller_name, self.model_name, | 960 | self.cloud_name, |
221 | 961 | self.controller_name, | ||
222 | 962 | self.model_name, | ||
223 | 925 | ) | 963 | ) |
224 | 926 | ) | 964 | ) |
225 | diff --git a/tests/conftest.py b/tests/conftest.py | |||
226 | index c95eb69..ef72390 100644 | |||
227 | --- a/tests/conftest.py | |||
228 | +++ b/tests/conftest.py | |||
229 | @@ -27,10 +27,11 @@ def mocked_pkg_resources(monkeypatch): | |||
230 | 27 | 27 | ||
231 | 28 | 28 | ||
232 | 29 | @pytest.fixture | 29 | @pytest.fixture |
234 | 30 | def cli(): | 30 | def cli(monkeypatch): |
235 | 31 | """Provide a test instance of the CLI class.""" | 31 | """Provide a test instance of the CLI class.""" |
237 | 32 | from jujulint.cli import Cli | 32 | monkeypatch.setattr(sys, "argv", ["juju-lint", "-c", "contrib/canonical-rules.yaml"]) |
238 | 33 | 33 | ||
239 | 34 | from jujulint.cli import Cli | ||
240 | 34 | cli = Cli() | 35 | cli = Cli() |
241 | 35 | 36 | ||
242 | 36 | return cli | 37 | return cli |
243 | diff --git a/tests/test_jujulint.py b/tests/test_jujulint.py | |||
244 | index 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 | 16 | assert flattened_list == utils.flatten_list(unflattened_list) | 16 | assert flattened_list == utils.flatten_list(unflattened_list) |
249 | 17 | 17 | ||
250 | 18 | 18 | ||
252 | 19 | def test_map_charms(lint): | 19 | def test_map_charms(lint, utils): |
253 | 20 | """Test the charm name validation code.""" | 20 | """Test the charm name validation code.""" |
254 | 21 | applications = { | 21 | applications = { |
255 | 22 | "test-app-1": {"charm": "cs:~USER/SERIES/TEST-CHARM12-123"}, | 22 | "test-app-1": {"charm": "cs:~USER/SERIES/TEST-CHARM12-123"}, |
256 | @@ -32,5 +32,5 @@ def test_map_charms(lint): | |||
257 | 32 | applications = { | 32 | applications = { |
258 | 33 | "test-app1": {"charm": "cs:invalid-charm$"}, | 33 | "test-app1": {"charm": "cs:invalid-charm$"}, |
259 | 34 | } | 34 | } |
261 | 35 | with pytest.raises(jujulint.lint.InvalidCharmNameError): | 35 | with pytest.raises(utils.InvalidCharmNameError): |
262 | 36 | lint.map_charms(applications) | 36 | lint.map_charms(applications) |
Fixes the current broken unit tests:
collected 4 items
tests/test_ cli.py: :test_pytest PASSED [ 25%] cli.py: :test_cli_ fixture PASSED [ 50%] jujulint. py::test_ flatten_ list PASSED [ 75%] jujulint. py::test_ map_charms PASSED [100%]
tests/test_
tests/test_
tests/test_
------- ------- ------- ------- ---- 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 ----------- ------- ------- ------- ------- ------- - __init_ _.py 0 0 100% openstack. py 14 5 64% ------- ------- ------- ------- ------- - coverage- annotated coverage- html
Name Stmts Miss Cover
-------
jujulint/
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/
jujulint/util.py 20 3 85%
-------
TOTAL 750 582 22%
Coverage annotated source written to dir tests/report/
Coverage HTML written to dir tests/report/
======= ======= ======= ======= ======= ======= ======= ======= ======= ====== 4 passed in 0.65s ======= ======= ======= ======= ======= ======= ======= ======= ======= ======= _______ _______ _______ _______ _______ _______ _______ _______ _______ ____ summary _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _____
_______
unit: commands succeeded
congratulations :)