Skip to content

Commit 23681e2

Browse files
NaddiNadjasafl
authored andcommitted
feat(tests/cli): add tests for log level
Signed-off-by: Nadja Brix Koch <[email protected]>
1 parent 36c2503 commit 23681e2

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

tests/core/aux_loglevel.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import logging as log
2+
3+
4+
def main(args, cijoe):
5+
log.critical("critical")
6+
log.error("error")
7+
log.warning("warning")
8+
log.info("info")
9+
log.debug("debug")
10+
11+
return 0

tests/core/test_loglevel.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import subprocess
2+
from pathlib import Path
3+
4+
5+
def run_loglevel_script(tmp_path, loglevel) -> subprocess.CompletedProcess[str]:
6+
config_path = (tmp_path / "test-config-empty.toml").resolve()
7+
config_path.write_text("")
8+
9+
script_file = Path(__file__).absolute().parent / "aux_loglevel.py"
10+
11+
command = [
12+
"cijoe",
13+
str(script_file),
14+
"--config",
15+
str(config_path),
16+
"--no-report",
17+
]
18+
19+
if loglevel:
20+
command += [f"-{loglevel*'l'}"]
21+
22+
return subprocess.run(
23+
command,
24+
cwd=str(tmp_path),
25+
capture_output=True,
26+
text=True,
27+
)
28+
29+
30+
def test_no_loglevel_parameter(tmp_path):
31+
result = run_loglevel_script(tmp_path, 0)
32+
33+
assert result.returncode == 0
34+
assert "critical" in result.stderr
35+
assert "error" in result.stderr
36+
assert "warning" not in result.stderr
37+
assert "info" not in result.stderr
38+
assert "debug" not in result.stderr
39+
40+
41+
def test_one_loglevel_parameter(tmp_path):
42+
result = run_loglevel_script(tmp_path, 1)
43+
44+
assert result.returncode == 0
45+
assert "warning" in result.stderr
46+
assert "info" in result.stderr
47+
assert "debug" not in result.stderr
48+
49+
50+
def test_two_loglevel_parameter(tmp_path):
51+
result = run_loglevel_script(tmp_path, 2)
52+
53+
assert result.returncode == 0
54+
assert "debug" in result.stderr
55+
56+
57+
def test_more_loglevel_parameter(tmp_path):
58+
result = run_loglevel_script(tmp_path, 5)
59+
60+
assert result.returncode == 0
61+
assert "debug" in result.stderr

0 commit comments

Comments
 (0)