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
diff --git a/Makefile b/Makefile
index 03f0a84..917e96b 100644
--- a/Makefile
+++ b/Makefile
@@ -9,4 +9,4 @@ deb-src:
9 debuild -S -sa -I.git -I.tox9 debuild -S -sa -I.git -I.tox
1010
11test:11test:
12 tox -e py3-test12 tox -e unit
diff --git a/jujulint/cli.py b/jujulint/cli.py
index 68e7bb2..8892420 100755
--- a/jujulint/cli.py
+++ b/jujulint/cli.py
@@ -36,7 +36,15 @@ class Cli:
36 """Create new CLI and configure runtime environment."""36 """Create new CLI and configure runtime environment."""
37 self.config = Config()37 self.config = Config()
38 self.logger = Logger(self.config["logging"]["loglevel"].get())38 self.logger = Logger(self.config["logging"]["loglevel"].get())
39 self.version = pkg_resources.require("jujulint")[0].version39
40 # get the version of the current package if available
41 # this will fail if not running from an installed package
42 # e.g. during unit tests
43 try:
44 self.version = pkg_resources.require("jujulint")[0].version
45 except pkg_resources.DistributionNotFound:
46 self.version = "unknown"
47
40 rules_file = self.config["rules"]["file"].get()48 rules_file = self.config["rules"]["file"].get()
41 # handle absolute path provided49 # handle absolute path provided
42 if os.path.isfile(rules_file):50 if os.path.isfile(rules_file):
diff --git a/jujulint/config.py b/jujulint/config.py
index fb5497a..05b7883 100644
--- a/jujulint/config.py
+++ b/jujulint/config.py
@@ -67,7 +67,7 @@ class Config(Configuration):
67 self.parser.add_argument(67 self.parser.add_argument(
68 "manual-file",68 "manual-file",
69 metavar="manual-file",69 metavar="manual-file",
70 nargs='?',70 nargs="?",
71 type=str,71 type=str,
72 default=None,72 default=None,
73 help=(73 help=(
diff --git a/jujulint/lint.py b/jujulint/lint.py
index 70f5ae6..ce49398 100755
--- a/jujulint/lint.py
+++ b/jujulint/lint.py
@@ -95,7 +95,9 @@ class Linter:
95 )95 )
96 )96 )
97 self.lint_rules["subordinates"][name] = dict(where=where)97 self.lint_rules["subordinates"][name] = dict(where=where)
98 self.lint_rules["known charms"] = flatten_list(self.lint_rules["known charms"])98 self.lint_rules["known charms"] = flatten_list(
99 self.lint_rules["known charms"]
100 )
99 self.logger.debug(101 self.logger.debug(
100 "[{}] [{}/{}] Lint Rules: {}".format(102 "[{}] [{}/{}] Lint Rules: {}".format(
101 self.cloud_name,103 self.cloud_name,
@@ -236,13 +238,21 @@ class Linter:
236 if check_value is False:238 if check_value is False:
237 self.logger.debug(239 self.logger.debug(
238 "[{}] [{}/{}] (PASS) Application {} is correctly using default config for {}.".format(240 "[{}] [{}/{}] (PASS) Application {} is correctly using default config for {}.".format(
239 self.cloud_name, self.controller_name, self.model_name, name, rule,241 self.cloud_name,
242 self.controller_name,
243 self.model_name,
244 name,
245 rule,
240 )246 )
241 )247 )
242 return True248 return True
243 self.logger.error(249 self.logger.error(
244 "[{}] [{}/{}] (FAIL) Application {} has no manual config for {}.".format(250 "[{}] [{}/{}] (FAIL) Application {} has no manual config for {}.".format(
245 self.cloud_name, self.controller_name, self.model_name, name, rule,251 self.cloud_name,
252 self.controller_name,
253 self.model_name,
254 name,
255 rule,
246 )256 )
247 )257 )
248 return False258 return False
@@ -440,13 +450,17 @@ class Linter:
440 continue450 continue
441 self.logger.debug(451 self.logger.debug(
442 "[{}] [{}/{}] ... and we are a host, will fallthrough".format(452 "[{}] [{}/{}] ... and we are a host, will fallthrough".format(
443 self.cloud_name, self.controller_name, self.model_name,453 self.cloud_name,
454 self.controller_name,
455 self.model_name,
444 )456 )
445 )457 )
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:
447 self.logger.debug(459 self.logger.debug(
448 "[{}] [{}/{}] requirement is 'all or nothing' and was 'nothing'.".format(460 "[{}] [{}/{}] requirement is 'all or nothing' and was 'nothing'.".format(
449 self.cloud_name, self.controller_name, self.model_name,461 self.cloud_name,
462 self.controller_name,
463 self.model_name,
450 )464 )
451 )465 )
452 continue466 continue
@@ -455,7 +469,9 @@ class Linter:
455 elif where == "container aware":469 elif where == "container aware":
456 self.logger.debug(470 self.logger.debug(
457 "[{}] [{}/{}] requirement is 'container aware'.".format(471 "[{}] [{}/{}] requirement is 'container aware'.".format(
458 self.cloud_name, self.controller_name, self.model_name,472 self.cloud_name,
473 self.controller_name,
474 self.model_name,
459 )475 )
460 )476 )
461 if is_container(machine):477 if is_container(machine):
@@ -476,7 +492,9 @@ class Linter:
476 )492 )
477 exceptions = []493 exceptions = []
478 if "exceptions" in self.lint_rules["subordinates"][required_sub]:494 if "exceptions" in self.lint_rules["subordinates"][required_sub]:
479 exceptions = self.lint_rules["subordinates"][required_sub]["exceptions"]495 exceptions = self.lint_rules["subordinates"][required_sub][
496 "exceptions"
497 ]
480 self.logger.debug(498 self.logger.debug(
481 "[{}] [{}/{}] -> exceptions == {}".format(499 "[{}] [{}/{}] -> exceptions == {}".format(
482 self.cloud_name,500 self.cloud_name,
@@ -529,14 +547,18 @@ class Linter:
529 if not found:547 if not found:
530 self.logger.debug(548 self.logger.debug(
531 "[{}] [{}/{}] -> NOT FOUND".format(549 "[{}] [{}/{}] -> NOT FOUND".format(
532 self.cloud_name, self.controller_name, self.model_name,550 self.cloud_name,
551 self.controller_name,
552 self.model_name,
533 )553 )
534 )554 )
535 for app in self.model.apps_on_machines[machine]:555 for app in self.model.apps_on_machines[machine]:
536 self.model.missing_subs[required_sub].add(app)556 self.model.missing_subs[required_sub].add(app)
537 self.logger.debug(557 self.logger.debug(
538 "[{}] [{}/{}] -> continue-ing back out...".format(558 "[{}] [{}/{}] -> continue-ing back out...".format(
539 self.cloud_name, self.controller_name, self.model_name,559 self.cloud_name,
560 self.controller_name,
561 self.model_name,
540 )562 )
541 )563 )
542 continue564 continue
@@ -552,7 +574,9 @@ class Linter:
552 )574 )
553 self.logger.debug(575 self.logger.debug(
554 "[{}] [{}/{}] requirement is 'all' OR we fell through.".format(576 "[{}] [{}/{}] requirement is 'all' OR we fell through.".format(
555 self.cloud_name, self.controller_name, self.model_name,577 self.cloud_name,
578 self.controller_name,
579 self.model_name,
556 )580 )
557 )581 )
558 if required_sub not in present_subs:582 if required_sub not in present_subs:
@@ -567,7 +591,9 @@ class Linter:
567 continue591 continue
568 self.logger.debug(592 self.logger.debug(
569 "[{}] [{}/{}] not found.".format(593 "[{}] [{}/{}] not found.".format(
570 self.cloud_name, self.controller_name, self.model_name,594 self.cloud_name,
595 self.controller_name,
596 self.model_name,
571 )597 )
572 )598 )
573 for app in self.model.apps_on_machines[machine]:599 for app in self.model.apps_on_machines[machine]:
@@ -612,7 +638,10 @@ class Linter:
612 if charm not in self.model.charms:638 if charm not in self.model.charms:
613 self.logger.error(639 self.logger.error(
614 "[{}] Ops charm '{}' in OpenStack model {} on controller {} not found".format(640 "[{}] Ops charm '{}' in OpenStack model {} on controller {} not found".format(
615 self.cloud_name, charm, self.model_name, self.controller_name641 self.cloud_name,
642 charm,
643 self.model_name,
644 self.controller_name,
616 )645 )
617 )646 )
618 elif self.cloud_type == "kubernetes":647 elif self.cloud_type == "kubernetes":
@@ -656,7 +685,9 @@ class Linter:
656 if self.model.duelling_subs:685 if self.model.duelling_subs:
657 self.logger.error(686 self.logger.error(
658 "[{}] [{}/{}] following subordinates where found on machines more than once:".format(687 "[{}] [{}/{}] following subordinates where found on machines more than once:".format(
659 self.cloud_name, self.controller_name, self.model_name,688 self.cloud_name,
689 self.controller_name,
690 self.model_name,
660 )691 )
661 )692 )
662 for sub in self.model.duelling_subs:693 for sub in self.model.duelling_subs:
@@ -782,7 +813,10 @@ class Linter:
782 else:813 else:
783 self.logger.warn(814 self.logger.warn(
784 "[{}] [{}/{}] Could not determine appropriate status key for {}.".format(815 "[{}] [{}/{}] Could not determine appropriate status key for {}.".format(
785 self.cloud_name, self.controller_name, self.model_name, name,816 self.cloud_name,
817 self.controller_name,
818 self.model_name,
819 name,
786 )820 )
787 )821 )
788822
@@ -913,7 +947,9 @@ class Linter:
913 "[{}] [{}/{}] Relations data found; assuming a bundle and "947 "[{}] [{}/{}] Relations data found; assuming a bundle and "
914 "skipping AZ and status checks."948 "skipping AZ and status checks."
915 ).format(949 ).format(
916 self.cloud_name, self.model_name, self.controller_name,950 self.cloud_name,
951 self.model_name,
952 self.controller_name,
917 )953 )
918 )954 )
919955
@@ -921,6 +957,8 @@ class Linter:
921 else:957 else:
922 self.logger.warn(958 self.logger.warn(
923 "[{}] [{}/{}] Model contains no applications, skipping.".format(959 "[{}] [{}/{}] Model contains no applications, skipping.".format(
924 self.cloud_name, self.controller_name, self.model_name,960 self.cloud_name,
961 self.controller_name,
962 self.model_name,
925 )963 )
926 )964 )
diff --git a/tests/conftest.py b/tests/conftest.py
index c95eb69..ef72390 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -27,10 +27,11 @@ def mocked_pkg_resources(monkeypatch):
2727
2828
29@pytest.fixture29@pytest.fixture
30def cli():30def cli(monkeypatch):
31 """Provide a test instance of the CLI class."""31 """Provide a test instance of the CLI class."""
32 from jujulint.cli import Cli32 monkeypatch.setattr(sys, "argv", ["juju-lint", "-c", "contrib/canonical-rules.yaml"])
3333
34 from jujulint.cli import Cli
34 cli = Cli()35 cli = Cli()
3536
36 return cli37 return cli
diff --git a/tests/test_jujulint.py b/tests/test_jujulint.py
index ba2dbf7..4c27cc1 100644
--- a/tests/test_jujulint.py
+++ b/tests/test_jujulint.py
@@ -16,7 +16,7 @@ def test_flatten_list(utils):
16 assert flattened_list == utils.flatten_list(unflattened_list)16 assert flattened_list == utils.flatten_list(unflattened_list)
1717
1818
19def test_map_charms(lint):19def test_map_charms(lint, utils):
20 """Test the charm name validation code."""20 """Test the charm name validation code."""
21 applications = {21 applications = {
22 "test-app-1": {"charm": "cs:~USER/SERIES/TEST-CHARM12-123"},22 "test-app-1": {"charm": "cs:~USER/SERIES/TEST-CHARM12-123"},
@@ -32,5 +32,5 @@ def test_map_charms(lint):
32 applications = {32 applications = {
33 "test-app1": {"charm": "cs:invalid-charm$"},33 "test-app1": {"charm": "cs:invalid-charm$"},
34 }34 }
35 with pytest.raises(jujulint.lint.InvalidCharmNameError):35 with pytest.raises(utils.InvalidCharmNameError):
36 lint.map_charms(applications)36 lint.map_charms(applications)

Subscribers

People subscribed via source and target branches