test_empty_output()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 13
rs 9.95
c 0
b 0
f 0
cc 1
nop 0
1
"""Test module for empty output functionality."""
2
3
import os
4
import subprocess
5
import sys
6
7
import pytest
8
9
if sys.platform.startswith("win"):
10
    pytest.skip("skip these tests for windows", allow_module_level=True)
11
12
13
here = os.path.dirname(os.path.abspath(__file__))
14
15
verbose_file = os.path.join(here, "verbose.py")
16
non_verbose_file = os.path.join(here, "non_verbose.py")
17
18
19
def _run_subprocess(script):
20
    output = []
21
    process = subprocess.Popen(  # noqa: S603
22
        [sys.executable, "-u", script],
23
        stdout=subprocess.PIPE,
24
        stderr=subprocess.PIPE,
25
        text=True,
26
        bufsize=1,  # Line buffered
27
        env={**os.environ, "PYTHONUNBUFFERED": "1"},
28
    )
29
    # Read output line by line
30
    while True:
31
        line = process.stdout.readline()
32
        if line:
33
            output.append(line)
34
        if not line and process.poll() is not None:
35
            break
36
37
    return "".join(output), process.stderr.read()
38
39
40
def test_empty_output():
41
    """Test that verbose and non-verbose modes produce expected output."""
42
    stdout_verb, stderr_verb = _run_subprocess(verbose_file)
43
    stdout_non_verb, stderr_non_verb = _run_subprocess(non_verbose_file)
44
45
    print("\n stdout_verb \n", stdout_verb, "\n")
46
    print("\n stderr_verb \n", stderr_verb, "\n")
47
48
    print("\n stdout_non_verb \n", stdout_non_verb, "\n")
49
    print("\n stderr_non_verb \n", stderr_non_verb, "\n")
50
51
    assert "Results:" in stdout_verb
52
    assert not stdout_non_verb
53