|
32 | 32 | from pip._internal.utils.misc import (
|
33 | 33 | call_subprocess, egg_link_path, ensure_dir, format_command_args,
|
34 | 34 | get_installed_distributions, get_prog, make_subprocess_output_error,
|
35 |
| - normalize_path, normalize_version_info, path_to_url, redact_netloc, |
36 |
| - redact_password_from_url, remove_auth_from_url, rmtree, |
| 35 | + normalize_path, normalize_version_info, path_to_display, path_to_url, |
| 36 | + redact_netloc, redact_password_from_url, remove_auth_from_url, rmtree, |
37 | 37 | split_auth_from_netloc, split_auth_netloc_from_url, untar_file, unzip_file,
|
38 | 38 | )
|
39 | 39 | from pip._internal.utils.temp_dir import AdjacentTempDirectory, TempDirectory
|
@@ -384,6 +384,24 @@ def test_rmtree_retries_for_3sec(tmpdir, monkeypatch):
|
384 | 384 | rmtree('foo')
|
385 | 385 |
|
386 | 386 |
|
| 387 | +@pytest.mark.parametrize('path, fs_encoding, expected', [ |
| 388 | + (None, None, None), |
| 389 | + # Test passing a text (unicode) string. |
| 390 | + (u'/path/déf', None, u'/path/déf'), |
| 391 | + # Test a bytes object with a non-ascii character. |
| 392 | + (u'/path/déf'.encode('utf-8'), 'utf-8', u'/path/déf'), |
| 393 | + # Test a bytes object with a character that can't be decoded. |
| 394 | + (u'/path/déf'.encode('utf-8'), 'ascii', u"b'/path/d\\xc3\\xa9f'"), |
| 395 | + (u'/path/déf'.encode('utf-16'), 'utf-8', |
| 396 | + u"b'\\xff\\xfe/\\x00p\\x00a\\x00t\\x00h\\x00/" |
| 397 | + "\\x00d\\x00\\xe9\\x00f\\x00'"), |
| 398 | +]) |
| 399 | +def test_path_to_display(monkeypatch, path, fs_encoding, expected): |
| 400 | + monkeypatch.setattr(sys, 'getfilesystemencoding', lambda: fs_encoding) |
| 401 | + actual = path_to_display(path) |
| 402 | + assert actual == expected, 'actual: {!r}'.format(actual) |
| 403 | + |
| 404 | + |
387 | 405 | class Test_normalize_path(object):
|
388 | 406 | # Technically, symlinks are possible on Windows, but you need a special
|
389 | 407 | # permission bit to create them, and Python 2 doesn't support it anyway, so
|
@@ -796,6 +814,58 @@ def test_make_subprocess_output_error__non_ascii_command_arg(monkeypatch):
|
796 | 814 | assert actual == expected, u'actual: {}'.format(actual)
|
797 | 815 |
|
798 | 816 |
|
| 817 | +@pytest.mark.skipif("sys.version_info < (3,)") |
| 818 | +def test_make_subprocess_output_error__non_ascii_cwd_python_3(monkeypatch): |
| 819 | + """ |
| 820 | + Test a str (text) cwd with a non-ascii character in Python 3. |
| 821 | + """ |
| 822 | + cmd_args = ['test'] |
| 823 | + cwd = '/path/to/cwd/déf' |
| 824 | + actual = make_subprocess_output_error( |
| 825 | + cmd_args=cmd_args, |
| 826 | + cwd=cwd, |
| 827 | + lines=[], |
| 828 | + exit_status=1, |
| 829 | + ) |
| 830 | + expected = dedent("""\ |
| 831 | + Command errored out with exit status 1: |
| 832 | + command: test |
| 833 | + cwd: /path/to/cwd/déf |
| 834 | + Complete output (0 lines): |
| 835 | + ----------------------------------------""") |
| 836 | + assert actual == expected, 'actual: {}'.format(actual) |
| 837 | + |
| 838 | + |
| 839 | +@pytest.mark.parametrize('encoding', [ |
| 840 | + 'utf-8', |
| 841 | + # Test a Windows encoding. |
| 842 | + 'cp1252', |
| 843 | +]) |
| 844 | +@pytest.mark.skipif("sys.version_info >= (3,)") |
| 845 | +def test_make_subprocess_output_error__non_ascii_cwd_python_2( |
| 846 | + monkeypatch, encoding, |
| 847 | +): |
| 848 | + """ |
| 849 | + Test a str (bytes object) cwd with a non-ascii character in Python 2. |
| 850 | + """ |
| 851 | + cmd_args = ['test'] |
| 852 | + cwd = u'/path/to/cwd/déf'.encode(encoding) |
| 853 | + monkeypatch.setattr(sys, 'getfilesystemencoding', lambda: encoding) |
| 854 | + actual = make_subprocess_output_error( |
| 855 | + cmd_args=cmd_args, |
| 856 | + cwd=cwd, |
| 857 | + lines=[], |
| 858 | + exit_status=1, |
| 859 | + ) |
| 860 | + expected = dedent(u"""\ |
| 861 | + Command errored out with exit status 1: |
| 862 | + command: test |
| 863 | + cwd: /path/to/cwd/déf |
| 864 | + Complete output (0 lines): |
| 865 | + ----------------------------------------""") |
| 866 | + assert actual == expected, u'actual: {}'.format(actual) |
| 867 | + |
| 868 | + |
799 | 869 | # This test is mainly important for checking unicode in Python 2.
|
800 | 870 | def test_make_subprocess_output_error__non_ascii_line():
|
801 | 871 | """
|
|
0 commit comments