コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
ファイル: _proc.py プロジェクト: ActiveState/applib
    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))
コード例 #4
0
    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))