Skip to content

Commit 2e7807b

Browse files
authored
envoy.base.checker: Implement no-error-on-warn (#150)
Signed-off-by: Ryan Northey <ryan@synca.io>
1 parent e6e2f7a commit 2e7807b

4 files changed

Lines changed: 31 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pypi: https://pypi.org/project/envoy.abstract.command
9696

9797
#### [envoy.base.checker](envoy.base.checker)
9898

99-
version: 0.0.3.dev0
99+
version: 0.0.3
100100

101101
pypi: https://pypi.org/project/envoy.base.checker
102102

envoy.base.checker/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.3-dev
1+
0.0.3

envoy.base.checker/envoy/base/checker/checker.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def error_count(self) -> int:
4242
def exiting(self):
4343
return "exiting" in self.errors
4444

45+
@property
46+
def fail_on_warn(self) -> bool:
47+
"""Return failure when warnings are generated."""
48+
return self.args.warning == "error"
49+
4550
@property
4651
def failed(self) -> dict:
4752
"""Dictionary of errors per check."""
@@ -56,8 +61,9 @@ def fix(self) -> bool:
5661
@property
5762
def has_failed(self) -> bool:
5863
"""Shows whether there are any failures."""
59-
# add logic for warn/error
60-
return bool(self.failed or self.warned)
64+
return bool(
65+
self.failed
66+
or (self.warned and self.fail_on_warn))
6167

6268
@cached_property
6369
def path(self) -> pathlib.Path:

envoy.base.checker/tests/test_checker.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ def test_checker_error_count():
7777
assert "error_count" not in checker.__dict__
7878

7979

80+
@pytest.mark.parametrize("warning", [True, False, "cabbage", "error"])
81+
def test_checker_fail_on_warn(patches, warning):
82+
checker = Checker("path1", "path2", "path3")
83+
patched = patches(
84+
("Checker.args", dict(new_callable=PropertyMock)),
85+
prefix="envoy.base.checker.checker")
86+
87+
with patched as (m_args, ):
88+
m_args.return_value.warning = warning
89+
assert (
90+
checker.fail_on_warn
91+
== (warning == "error"))
92+
assert "fail_on_warn" not in checker.__dict__
93+
94+
8095
def test_checker_failed():
8196
checker = Checker("path1", "path2", "path3")
8297
checker.errors = dict(foo=["err"] * 3, bar=["err"] * 5, baz=["err"] * 7)
@@ -97,19 +112,22 @@ def test_checker_fix():
97112

98113
@pytest.mark.parametrize("failed", [True, False])
99114
@pytest.mark.parametrize("warned", [True, False])
100-
def test_checker_has_failed(patches, failed, warned):
115+
@pytest.mark.parametrize("fail_on_warn", [True, False])
116+
def test_checker_has_failed(patches, failed, warned, fail_on_warn):
101117
checker = Checker("path1", "path2", "path3")
102118
patched = patches(
119+
("Checker.fail_on_warn", dict(new_callable=PropertyMock)),
103120
("Checker.failed", dict(new_callable=PropertyMock)),
104121
("Checker.warned", dict(new_callable=PropertyMock)),
105122
prefix="envoy.base.checker.checker")
106123

107-
with patched as (m_failed, m_warned):
124+
with patched as (m_fail_warn, m_failed, m_warned):
125+
m_fail_warn.return_value = fail_on_warn
108126
m_failed.return_value = failed
109127
m_warned.return_value = warned
110128
result = checker.has_failed
111129

112-
if failed or warned:
130+
if failed or (warned and fail_on_warn):
113131
assert result is True
114132
else:
115133
assert result is False

0 commit comments

Comments
 (0)