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')
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")
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
def test_check_output_noshell3(): with pytest.raises(FileNotFoundError): sh.check_output('notexist', shell=False)
def test_check_output_noshell2(): with pytest.raises(sh.CalledProcessError): sh.check_output(EXIT1_CMD, shell=False)
def test_check_output_noshell1_win(): assert sh.check_output(HELLO_CMD, shell=False) \ .splitlines()[-1].strip() == 'Hello world!'
def test_check_output_noshell1_unix(): assert sh.check_output(HELLO_CMD, shell=False) == 'Hello world!\n'
def test_check_output_obfuscate_pwd(): # TODO intercept logging assert sh.check_output('echo -P mypass', obfuscate_pwd='mypass') == "-P mypass\n"
def test_check_output_obfuscate_pwd(): # TODO intercept logging assert sh.check_output("echo -P mypass", obfuscate_pwd="mypass") == "-P mypass\n"
def test_check_output_nounset(): with pytest.raises(sh.CalledProcessError): sh.check_output('echo $NOT_EXISTING_VARIABLE')
def test_check_output_errexit(): with pytest.raises(sh.CalledProcessError): sh.check_output('notexist.sh')
def test_check_output_nodecode(): assert sh.check_output('echo -n "Hello world"', decode=False) == b'Hello world'
def test_check_output_quotes(): assert sh.check_output("echo 'Hello world!'") == "Hello world!\n"
def test_check_output(): assert sh.check_output('echo -n "Hello world"') == 'Hello world'
def test_check_output_real_fh_stringio(): stderr = io.StringIO() sh.check_output('echo hello 1>&2', stderr=stderr) assert stderr.getvalue() == 'hello\n'
def test_check_output_real_fh_nosetests(): sh.check_output('echo hello 1>&2', stderr=sys.stderr)
def test_check_output_pipefail(): with pytest.raises(sh.CalledProcessError): sh.check_output('cat NOTEXIST | cat')