Esempio 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')
Esempio 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")
Esempio 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
Esempio n. 4
0
def test_check_output_noshell3():
    with pytest.raises(FileNotFoundError):
        sh.check_output('notexist', shell=False)
Esempio n. 5
0
def test_check_output_noshell2():
    with pytest.raises(sh.CalledProcessError):
        sh.check_output(EXIT1_CMD, shell=False)
Esempio n. 6
0
def test_check_output_noshell1_win():
    assert sh.check_output(HELLO_CMD, shell=False) \
        .splitlines()[-1].strip() == 'Hello world!'
Esempio n. 7
0
def test_check_output_noshell1_unix():
    assert sh.check_output(HELLO_CMD, shell=False) == 'Hello world!\n'
Esempio 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"
Esempio 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"
Esempio n. 10
0
def test_check_output_nounset():
    with pytest.raises(sh.CalledProcessError):
        sh.check_output('echo $NOT_EXISTING_VARIABLE')
Esempio n. 11
0
def test_check_output_errexit():
    with pytest.raises(sh.CalledProcessError):
        sh.check_output('notexist.sh')
Esempio n. 12
0
def test_check_output_nodecode():
    assert sh.check_output('echo -n "Hello world"',
                           decode=False) == b'Hello world'
Esempio n. 13
0
def test_check_output_quotes():
    assert sh.check_output("echo 'Hello world!'") == "Hello world!\n"
Esempio n. 14
0
def test_check_output():
    assert sh.check_output('echo -n "Hello world"') == 'Hello world'
Esempio 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'
Esempio n. 16
0
def test_check_output_real_fh_nosetests():
    sh.check_output('echo hello 1>&2', stderr=sys.stderr)
Esempio n. 17
0
def test_check_output_pipefail():
    with pytest.raises(sh.CalledProcessError):
        sh.check_output('cat NOTEXIST | cat')