File: test_processwrapper.py

package info (click to toggle)
labgrid 25.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,796 kB
  • sloc: python: 21,352; sh: 846; makefile: 35
file content (50 lines) | stat: -rw-r--r-- 1,031 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pytest
import subprocess
import textwrap

from labgrid.util.helper import processwrapper


def test_processwrapper_passes():
    processwrapper.check_output(["true"])


def test_processwrapper_fails():
    with pytest.raises(subprocess.CalledProcessError):
        processwrapper.check_output(["false"])


def test_processwrapper_output(tmpdir):
    content = textwrap.dedent(
        """\
        A
        B
        C
        """
    )

    tmpfile = tmpdir.join("output.txt")
    tmpfile.write(content)

    output = processwrapper.check_output(["cat", str(tmpfile)])

    assert output.decode("utf-8") == content


def test_processwrapper_input():
    content = textwrap.dedent(
        """\
        A
        B
        C
        """
    )

    output = processwrapper.check_output(["cat", "-"], input=content.encode("utf-8"))

    assert output.decode("utf-8") == content


def test_processwrapper_empty_input():
    output = processwrapper.check_output(["cat", "-"], input=b"")
    assert output.decode("utf-8") == ""