Passed
Push — master ( 91a232...6b9e1e )
by Simon
01:43 queued 13s
created

tests.test_empty_output.test_empty_output   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 6

2 Functions

Rating   Name   Duplication   Size   Complexity  
A _run_subprocess() 0 19 5
A test_empty_output() 0 12 1
1
import os, sys, subprocess
2
3
here = os.path.dirname(os.path.abspath(__file__))
4
5
verbose_file = os.path.join(here, "verbose.py")
6
non_verbose_file = os.path.join(here, "non_verbose.py")
7
8
9
def _run_subprocess(script):
10
    output = []
11
    process = subprocess.Popen(
12
        [sys.executable, "-u", script],
13
        stdout=subprocess.PIPE,
14
        stderr=subprocess.PIPE,
15
        text=True,
16
        bufsize=1,  # Line buffered
17
        env={**os.environ, "PYTHONUNBUFFERED": "1"},
18
    )
19
    # Read output line by line
20
    while True:
21
        line = process.stdout.readline()
22
        if line:
23
            output.append(line)
24
        if not line and process.poll() is not None:
25
            break
26
27
    return "".join(output), process.stderr.read()
28
29
30
def test_empty_output():
31
    stdout_verb, stderr_verb = _run_subprocess(verbose_file)
32
    stdout_non_verb, stderr_non_verb = _run_subprocess(non_verbose_file)
33
34
    print("\n stdout_verb \n", stdout_verb, "\n")
35
    print("\n stderr_verb \n", stderr_verb, "\n")
36
37
    print("\n stdout_non_verb \n", stdout_non_verb, "\n")
38
    print("\n stderr_non_verb \n", stderr_non_verb, "\n")
39
40
    assert "Results:" in stdout_verb
41
    assert not stdout_non_verb
42