File: common.py

package info (click to toggle)
python-milc 1.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 788 kB
  • sloc: python: 1,868; sh: 55; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 793 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
from milc import cli


def check_command(command, *args, input=None):
    cmd = [command, *args]

    if input:
        return cli.run(cmd, combined_output=True, stdin=None, input=input)

    return cli.run(cmd, combined_output=True)


def check_returncode(result, expected=0):
    """Print stdout if `result.returncode` does not match `expected`.
    """
    if result.returncode != expected:
        print('`%s` stdout:' % ' '.join(result.args))
        print(result.stdout)
        print('returncode:', result.returncode)
    assert result.returncode == expected


def check_assert(result, assertion):
    if not assertion:
        print('`%s` stdout:' % ' '.join(result.args))
        print(repr(result.stdout))
        print('returncode:', result.returncode)
        raise AssertionError