Ejemplo n.º 1
0
def test_check_output_unicode():
    assert sh.check_output(r"printf '\xE2\x98\xA0'") == '☠'

    # Test invalid unicode character
    assert sh.check_output(r"printf '\x85'") == '�'
    assert sh.check_output(r"printf '\x85'", errors='replace') == '�'
    assert sh.check_output(r"printf '\x85'", errors='ignore') == ''
    with pytest.raises(UnicodeDecodeError):
        sh.check_output(r"printf '\x85'", errors='strict')
Ejemplo n.º 2
0
def test_check_output_unicode():
    assert sh.check_output(r"printf '\xE2\x98\xA0'") == "☠"

    # Test invalid unicode character
    assert sh.check_output(r"printf '\x85'") == "�"
    assert sh.check_output(r"printf '\x85'", errors="replace") == "�"
    assert sh.check_output(r"printf '\x85'", errors="ignore") == ""
    with pytest.raises(UnicodeDecodeError):
        sh.check_output(r"printf '\x85'", errors="strict")
Ejemplo n.º 3
0
def test_check_output_timeout():
    ts_start = time.time()
    with pytest.raises(sh.TimeoutExpired):
        sh.check_output(SLEEP_CMD, timeout=0.1, shell=False)
    assert time.time() - ts_start < 0.5
Ejemplo n.º 4
0
def test_check_output_noshell3():
    with pytest.raises(FileNotFoundError):
        sh.check_output('notexist', shell=False)
Ejemplo n.º 5
0
def test_check_output_noshell2():
    with pytest.raises(sh.CalledProcessError):
        sh.check_output(EXIT1_CMD, shell=False)
Ejemplo n.º 6
0
def test_check_output_noshell1_win():
    assert sh.check_output(HELLO_CMD, shell=False) \
        .splitlines()[-1].strip() == 'Hello world!'
Ejemplo n.º 7
0
def test_check_output_noshell1_unix():
    assert sh.check_output(HELLO_CMD, shell=False) == 'Hello world!\n'
Ejemplo n.º 8
0
def test_check_output_obfuscate_pwd():
    # TODO intercept logging
    assert sh.check_output('echo -P mypass',
                           obfuscate_pwd='mypass') == "-P mypass\n"
Ejemplo n.º 9
0
def test_check_output_obfuscate_pwd():
    # TODO intercept logging
    assert sh.check_output("echo -P mypass",
                           obfuscate_pwd="mypass") == "-P mypass\n"
Ejemplo n.º 10
0
def test_check_output_nounset():
    with pytest.raises(sh.CalledProcessError):
        sh.check_output('echo $NOT_EXISTING_VARIABLE')
Ejemplo n.º 11
0
def test_check_output_errexit():
    with pytest.raises(sh.CalledProcessError):
        sh.check_output('notexist.sh')
Ejemplo n.º 12
0
def test_check_output_nodecode():
    assert sh.check_output('echo -n "Hello world"',
                           decode=False) == b'Hello world'
Ejemplo n.º 13
0
def test_check_output_quotes():
    assert sh.check_output("echo 'Hello world!'") == "Hello world!\n"
Ejemplo n.º 14
0
def test_check_output():
    assert sh.check_output('echo -n "Hello world"') == 'Hello world'
Ejemplo n.º 15
0
def test_check_output_real_fh_stringio():
    stderr = io.StringIO()
    sh.check_output('echo hello 1>&2', stderr=stderr)
    assert stderr.getvalue() == 'hello\n'
Ejemplo n.º 16
0
def test_check_output_real_fh_nosetests():
    sh.check_output('echo hello 1>&2', stderr=sys.stderr)
Ejemplo n.º 17
0
def test_check_output_pipefail():
    with pytest.raises(sh.CalledProcessError):
        sh.check_output('cat NOTEXIST | cat')