def test_make_subprocess_output_error__non_ascii_command_arg(monkeypatch): """ Test a command argument with a non-ascii character. """ cmd_args = ['foo', 'déf'] if sys.version_info[0] == 2: # Check in Python 2 that the str (bytes object) with the non-ascii # character has the encoding we expect. (This comes from the source # code encoding at the top of the file.) assert cmd_args[1].decode('utf-8') == u'déf' # We need to monkeypatch so the encoding will be correct on Windows. monkeypatch.setattr(locale, 'getpreferredencoding', lambda: 'utf-8') actual = make_subprocess_output_error( cmd_args=cmd_args, cwd='/path/to/cwd', lines=[], exit_status=1, ) expected = dedent(u"""\ Command errored out with exit status 1: command: foo 'déf' cwd: /path/to/cwd Complete output (0 lines): ----------------------------------------""") assert actual == expected, u'actual: {}'.format(actual)
def test_make_subprocess_output_error__non_ascii_line(): """ Test a line with a non-ascii character. """ lines = [u'curly-quote: \u2018\n'] actual = make_subprocess_output_error( cmd_args=['test'], cwd='/path/to/cwd', lines=lines, exit_status=1, ) expected = dedent(u"""\ Command errored out with exit status 1: command: test cwd: /path/to/cwd Complete output (1 lines): curly-quote: \u2018 ----------------------------------------""") assert actual == expected, u'actual: {}'.format(actual)
def test_make_subprocess_output_error__non_ascii_cwd_python_3(monkeypatch): """ Test a str (text) cwd with a non-ascii character in Python 3. """ cmd_args = ['test'] cwd = '/path/to/cwd/déf' actual = make_subprocess_output_error( cmd_args=cmd_args, cwd=cwd, lines=[], exit_status=1, ) expected = dedent("""\ Command errored out with exit status 1: command: test cwd: /path/to/cwd/déf Complete output (0 lines): ----------------------------------------""") assert actual == expected, 'actual: {}'.format(actual)
def test_make_subprocess_output_error(): cmd_args = ['test', 'has space'] cwd = '/path/to/cwd' lines = ['line1\n', 'line2\n', 'line3\n'] actual = make_subprocess_output_error( cmd_args=cmd_args, cwd=cwd, lines=lines, exit_status=3, ) expected = dedent("""\ Command errored out with exit status 3: command: test 'has space' cwd: /path/to/cwd Complete output (3 lines): line1 line2 line3 ----------------------------------------""") assert actual == expected, 'actual: {}'.format(actual)
def test_make_subprocess_output_error__non_ascii_cwd_python_2( monkeypatch, encoding, ): """ Test a str (bytes object) cwd with a non-ascii character in Python 2. """ cmd_args = ['test'] cwd = u'/path/to/cwd/déf'.encode(encoding) monkeypatch.setattr(sys, 'getfilesystemencoding', lambda: encoding) actual = make_subprocess_output_error( cmd_args=cmd_args, cwd=cwd, lines=[], exit_status=1, ) expected = dedent(u"""\ Command errored out with exit status 1: command: test cwd: /path/to/cwd/déf Complete output (0 lines): ----------------------------------------""") assert actual == expected, u'actual: {}'.format(actual)