Merge ~mertkirpici/juju-lint:topic/coverage into juju-lint:master

Proposed by Mert Kirpici
Status: Merged
Approved by: Martin Kalcok
Approved revision: fca2a52d8ef38b12e662f7dadd131d9448d0b951
Merged at revision: ce5d33a2b39e4a133eb6abbabc5105c1c9e0ea55
Proposed branch: ~mertkirpici/juju-lint:topic/coverage
Merge into: juju-lint:master
Diff against target: 83 lines (+24/-3)
3 files modified
pyproject.toml (+15/-0)
tests/unit/test_config.py (+7/-2)
tox.ini (+2/-1)
Reviewer Review Type Date Requested Status
Sudeep Bhandari Approve
🤖 prod-jenkaas-bootstack (community) continuous-integration Approve
Ramesh Sattaru (community) Approve
Robert Gildein Approve
Review via email: mp+436243@code.launchpad.net

Commit message

Require full unit test coverage

Description of the change

This was missed during the snap template update, we expect %100 test coverage in this project.

This also revealed a sneaky bug in the process. When the jujulint.config.Config class got initialized it was using the sys.argv of the pytest process, causing a testing error and not being able to pass arguments to pytest.

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: Approve (continuous-integration)
Revision history for this message
Robert Gildein (rgildein) wrote :

LGTM

Maybe we can use our templates [1] in juju-lint, not in this MP.

---
[1]: https://git.launchpad.net/bootstack-charms-spec/tree/source/snap-pytest

review: Approve
Revision history for this message
Ramesh Sattaru (rameshcan) :
review: Approve
Revision history for this message
Mert Kirpici (mertkirpici) wrote (last edit ):

> LGTM
>
> Maybe we can use our templates [1] in juju-lint, not in this MP.
>
> ---
> [1]: https://git.launchpad.net/bootstack-charms-spec/tree/source/snap-pytest

Hi there Robert, thanks for the review! This snap recently seems to have received the template update but the coverage relation sections in tox and pyproject.toml were missing. I assumed they were also missing in the bootstack templates. Turns out they're not. Maybe they were skipped due to the sys.argv bug I tried to explain in the description. Passing arguments to pytest in tox.ini was broken.

I am thinking of applying both your suggestions and align pyproject.toml and tox.ini posargs in this MP, I think it is a better solution rather than diverging more. What are your thoughts?

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

> Hi there Robert, thanks for the review! This snap recently seems to have
> received the template update but the coverage relation sections in tox and
> pyproject.toml were missing. I assumed they were also missing in the bootstack
> templates. Turns out they're not. Maybe they were skipped due to the sys.argv
> bug I tried to explain in the description. Passing arguments to pytest in
> tox.ini was broken.

Maybe it was related with tox 4.* issue? Not sure here.

> I am thinking of applying both your suggestions and align pyproject.toml and
> tox.ini posargs in this MP, I think it is a better solution rather than
> diverging more. What are your thoughts?

It's up to you, I'm trying to suggest templates everywhere, because it's easier
to work on multiple project with similar dev behavior and also using them in various
projects helps to improve them. I think that using separate MP is better, because
you can add/update more templates at once (recently we add .gitignore).

Also feel free to update our templates if it's needed. Recently I removed
`addopts` [1] from `juju-spell`, because it was more annoying than helpful.

---
[1]: https://git.launchpad.net/bootstack-charms-spec/tree/source/snap-pytest/pyproject.toml#n38

them also.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sudeep Bhandari (sudeephb) :
review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision ce5d33a2b39e4a133eb6abbabc5105c1c9e0ea55

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/pyproject.toml b/pyproject.toml
index c58e8e6..789c704 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -33,3 +33,18 @@ skip_glob = '''
33 | report33 | report
34)/34)/
35'''35'''
36
37[tool.coverage.run]
38relative_files = true
39source = ["jujulint"]
40omit = ["tests/**", "docs/**", "lib/**", "snap/**", "build/**", "setup.py"]
41
42[tool.coverage.report]
43fail_under = 100
44show_missing = true
45
46[tool.coverage.html]
47directory = "report"
48
49[tool.coverage.xml]
50output = "report/coverage.xml"
diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py
index 1d9060d..71c2e40 100644
--- a/tests/unit/test_config.py
+++ b/tests/unit/test_config.py
@@ -3,12 +3,14 @@
33
4import os4import os
5import sys5import sys
6from unittest.mock import patch
67
7import yaml8import yaml
89
9from jujulint.config import Config10from jujulint.config import Config
1011
11config_file = f"{Config().config_dir()}/config.yaml"12with patch.object(sys, "argv", ["juju-lint"]):
13 config_file = f"{Config().config_dir()}/config.yaml"
12builtin_open = open14builtin_open = open
13builtin_isfile = os.path.isfile15builtin_isfile = os.path.isfile
1416
@@ -52,6 +54,7 @@ def patch_user_config(mocker):
52 mocker.patch("builtins.open", my_mock_open)54 mocker.patch("builtins.open", my_mock_open)
5355
5456
57@patch.object(sys, "argv", ["juju-lint"])
55def test_config_file(mocker):58def test_config_file(mocker):
56 """Tests if the config entries set in the .config/juju-lint/config.yaml are correctly applied.59 """Tests if the config entries set in the .config/juju-lint/config.yaml are correctly applied.
5760
@@ -65,6 +68,7 @@ def test_config_file(mocker):
65 assert config[key].get() == expected_config[key]68 assert config[key].get() == expected_config[key]
6669
6770
71@patch.object(sys, "argv", ["juju-lint"])
68def test_default_config(mocker):72def test_default_config(mocker):
69 """Tests if the default values are correctly read from config_default.yaml."""73 """Tests if the default values are correctly read from config_default.yaml."""
70 default_config = {74 default_config = {
@@ -96,7 +100,8 @@ def test_parser_options(mocker):
96 "output": {"folder": "cli/folder"},100 "output": {"folder": "cli/folder"},
97 "format": "json",101 "format": "json",
98 }102 }
99 test_args = sys.argv + [103 test_args = [
104 "juju-lint",
100 "-F",105 "-F",
101 cli_config["format"],106 cli_config["format"],
102 "-l",107 "-l",
diff --git a/tox.ini b/tox.ini
index 8aefb78..f6d4326 100644
--- a/tox.ini
+++ b/tox.ini
@@ -48,7 +48,8 @@ commands =
48deps = {[testenv:lint]deps}48deps = {[testenv:lint]deps}
4949
50[testenv:unit]50[testenv:unit]
51commands = pytest {toxinidir}/tests/unit51commands = pytest {toxinidir}/tests/unit \
52 {posargs:-v --cov --cov-report=term-missing --cov-report=html --cov-report=xml}
52deps =53deps =
53 -r {toxinidir}/requirements.txt54 -r {toxinidir}/requirements.txt
54 -r {toxinidir}/tests/unit/requirements.txt55 -r {toxinidir}/tests/unit/requirements.txt

Subscribers

People subscribed via source and target branches