Skip to content

Commit 19c02ef

Browse files
committed
#428: Fixed detecting report coverage failures
1 parent f57e8c0 commit 19c02ef

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

doc/changes/unreleased.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Summary
44

5-
With #420, any GitHub repos using the PTB for **documentation** will also need to
5+
With #420, any GitHub repos using the PTB for **documentation** will also need to
66
reconfigure the GitHub Pages settings for each repo:
77
1. Go to the affected repo's GitHub page
88
2. Select 'Settings'
@@ -30,4 +30,8 @@ permissions to be increased for specific jobs.
3030
## ✨ Features
3131

3232
* [#161](https://github.com/exasol/python-toolbox/issues/161): Added support for installing extras & not using a cache to the python-environment action
33-
* [#408](https://github.com/exasol/python-toolbox/issues/408): Added support for GitHub runners who do not per default have pipx to use the python-environment action
33+
* [#408](https://github.com/exasol/python-toolbox/issues/408): Added support for GitHub runners who do not per default have pipx to use the python-environment action
34+
35+
## Bugfixes
36+
37+
* #428: Fixed detecting report coverage failures

exasol/toolbox/metrics.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,20 @@ def total_coverage(file: Union[str, Path]) -> float:
112112
encoding="utf-8",
113113
)
114114
stdout = p.stdout.strip()
115-
if (p.returncode == 1) and (stdout == "No data to report."):
116-
print(
115+
116+
if p.returncode != 0:
117+
message = (
117118
f"The following command"
118119
f" returned non-zero exit status {p.returncode}:\n"
119120
f' {" ".join(p.args)}\n'
120-
f"{stdout}\n"
121-
"Returning total coverage 100 %.",
122-
file=sys.stderr,
121+
f"{stdout}"
123122
)
124-
return 100.0
123+
if (p.returncode == 1) and (stdout == "No data to report."):
124+
print(f"{message}\nReturning total coverage 100 %.", file=sys.stderr)
125+
return 100.0
126+
else:
127+
raise RuntimeError(message)
128+
125129
with open(report, encoding="utf-8") as r:
126130
data = json.load(r)
127131
total: float = data["totals"]["percent_covered"]

exasol/toolbox/nox/_metrics.py

+27-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__ import annotations
22

33
import argparse
4+
from dataclasses import dataclass
5+
from pathlib import Path
46

57
import nox
68
from nox import Session
@@ -13,6 +15,21 @@
1315
from noxconfig import PROJECT_CONFIG
1416

1517

18+
@dataclass
19+
class RequiredFile:
20+
"""
21+
Describes a required file and the related nox task to generate this
22+
file.
23+
"""
24+
25+
def __init__(self, file: Path | str, task: str):
26+
self.file = file if isinstance(file, Path) else PROJECT_CONFIG.root / file
27+
self.task = task
28+
29+
def __str__(self) -> str:
30+
return f"{self.file.name} generated by `{self.task}`"
31+
32+
1633
@nox.session(name="project:report", python=False)
1734
def report(session: Session) -> None:
1835
"""
@@ -45,14 +62,17 @@ def report(session: Session) -> None:
4562
help="Output format to produce.",
4663
choices=formats,
4764
)
48-
required_files = (
49-
PROJECT_CONFIG.root / ".coverage",
50-
PROJECT_CONFIG.root / ".lint.txt",
51-
PROJECT_CONFIG.root / ".security.json",
52-
)
53-
if not all(file.exists() for file in required_files):
65+
required_files = [
66+
RequiredFile(".coverage", "test:coverage"),
67+
RequiredFile(".lint.txt", "lint:code"),
68+
RequiredFile(".security.json", "lint:security"),
69+
]
70+
if missing_files := [f for f in required_files if not f.file.exists()]:
71+
missing = "\n- file ".join(str(f) for f in missing_files)
5472
session.error(
55-
"Please make sure you run the `test:coverage`, `lint:security` and the `lint:code` target first"
73+
"Some required files are missing.\n"
74+
"Please make sure you run the related nox tasks first:\n"
75+
f"{missing}"
5676
)
5777
sha1 = str(
5878
session.run("git", "rev-parse", "HEAD", external=True, silent=True)

0 commit comments

Comments
 (0)