|
| 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