def test_safe_unicode(): from applib.misc import safe_unicode import six abc_bytes = b'ab\nc' abc_text = 'ab\nc' assert safe_unicode(abc_bytes) == abc_text assert safe_unicode(abc_text) == abc_text foo_text = 'abc' # note: \x89 is ignored. foo_bytes = b'\x89abc' assert safe_unicode(foo_text) == foo_text assert safe_unicode(foo_bytes) == foo_text
def test_sh_runerror_unicode(): # https://github.com/activestate/applib/issues/12 with pytest.raises(sh.RunError): try: sh.run('echo ' + "\u1234" + " & nonexistant") except sh.RunError as e: print(safe_unicode(e)) raise
def __init__(self, cmd, stdout, stderr, errors): self.stdout = stdout self.stderr = stderr msg = errors[:] msg.extend([ 'command: {0}'.format(safe_unicode(cmd)), 'pwd: {0}'.format(xjoin(os.getcwd()))]) if stderr is None: msg.append( 'OUTPUT:\n{0}'.format(_limit_str(safe_unicode(stdout)))) else: msg.extend([ 'STDERR:\n{0}'.format(_limit_str(safe_unicode(stderr))), 'STDOUT:\n{0}'.format(_limit_str(safe_unicode(stdout)))]) super(RunError, self).__init__('\n'.join(msg))
def __init__(self, cmd, stdout, stderr, errors): self.stdout = stdout self.stderr = stderr msg = errors[:] msg.extend([ 'command: {0}'.format(safe_unicode(cmd)), 'pwd: {0}'.format(xjoin(os.getcwd())) ]) if stderr is None: msg.append('OUTPUT:\n{0}'.format(_limit_str(safe_unicode(stdout)))) else: msg.extend([ 'STDERR:\n{0}'.format(_limit_str(safe_unicode(stderr))), 'STDOUT:\n{0}'.format(_limit_str(safe_unicode(stdout))) ]) super(RunError, self).__init__('\n'.join(msg))