Completed
Push — master ( 1a32f0...6baa7b )
by Klaus
01:15
created

test_python_tee_output()   A

Complexity

Conditions 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
dl 0
loc 17
rs 9.2
c 1
b 0
f 0
1
#!/usr/bin/env python
2
# coding=utf-8
3
from __future__ import division, print_function, unicode_literals
4
import os
5
import sys
6
from sacred.stdout_capturing import get_stdcapturer
7
from sacred.optional import libc
8
9
10
def test_python_tee_output(capsys):
11
    expected_lines = {
12
        "captured stdout",
13
        "captured stderr"}
14
15
    capture_stdout = get_stdcapturer("PY")
16
    with capsys.disabled():
17
        print('before (stdout)')
18
        print('before (stderr)')
19
        with capture_stdout() as (f, final_out):
20
            print("captured stdout")
21
            print("captured stderr")
22
23
        print('after (stdout)')
24
        print('after (stderr)')
25
26
        assert set(final_out[0].strip().split("\n")) == expected_lines
27
28
29
def test_fd_tee_output(capsys):
30
    expected_lines = {
31
        "captured stdout",
32
        "captured stderr",
33
        "and this is from echo"}
34
    if not sys.platform.startswith('win'):
35
        # FIXME: this line randomly doesn't show on windows (skip for now)
36
        expected_lines.add("stdout from C")
37
38
    capture_stdout = get_stdcapturer("FD")
39
    with capsys.disabled():
40
        print('before (stdout)')
41
        print('before (stderr)')
42
        with capture_stdout() as (f, final_out):
43
            print("captured stdout")
44
            print("captured stderr")
45
            if not sys.platform.startswith('win'):
46
                libc.puts(b'stdout from C')
47
                libc.fflush(None)
48
            os.system('echo and this is from echo')
49
50
        print('after (stdout)')
51
        print('after (stderr)')
52
53
        assert set(final_out[0].strip().split("\n")) == expected_lines
54