|
20 | 20 | import collections |
21 | 21 | import contextlib |
22 | 22 | import datetime |
23 | | -import distutils.spawn |
24 | 23 | import errno |
25 | 24 | import functools |
26 | 25 | import json |
@@ -543,8 +542,8 @@ def get_winver(): |
543 | 542 | return (wv[0], wv[1], sp) |
544 | 543 |
|
545 | 544 |
|
546 | | -# In Python 3 paths are unicode objects by default. Surrogate escapes are used |
547 | | -# to handle non-character data. |
| 545 | +# In Python 3 paths are unicode objects by default. Surrogate escapes |
| 546 | +# are used to handle non-character data. |
548 | 547 | def encode_path(path): |
549 | 548 | if PY3: |
550 | 549 | return path.encode(sys.getfilesystemencoding(), |
@@ -3253,18 +3252,21 @@ def test_proc_open_files(self): |
3253 | 3252 |
|
3254 | 3253 |
|
3255 | 3254 | class TestNonUnicode(unittest.TestCase): |
3256 | | - "Test handling of non-utf8 data." |
| 3255 | + """Test handling of non-utf8 data.""" |
3257 | 3256 |
|
3258 | 3257 | @classmethod |
3259 | 3258 | def setUpClass(cls): |
3260 | | - cls.temp_directory = tempfile.mkdtemp(suffix=b"") |
| 3259 | + if PY3: |
| 3260 | + # Fix around https://bugs.python.org/issue24230 |
| 3261 | + cls.temp_directory = tempfile.mkdtemp().encode('utf8') |
| 3262 | + else: |
| 3263 | + cls.temp_directory = tempfile.mkdtemp(suffix=b"") |
3261 | 3264 |
|
3262 | | - # Return an executable that runs until we close its stdin |
| 3265 | + # Return an executable that runs until we close its stdin. |
3263 | 3266 | if WINDOWS: |
3264 | | - cls.test_executable = distutils.spawn.find_executable("cmd.exe") |
| 3267 | + cls.test_executable = which("cmd.exe") |
3265 | 3268 | else: |
3266 | | - assert POSIX |
3267 | | - cls.test_executable = "/bin/cat" |
| 3269 | + cls.test_executable = which("cat") |
3268 | 3270 |
|
3269 | 3271 | @classmethod |
3270 | 3272 | def tearDownClass(cls): |
@@ -3310,8 +3312,6 @@ def test_proc_cmdline(self): |
3310 | 3312 | cmd = [self.test_executable] |
3311 | 3313 | if WINDOWS: |
3312 | 3314 | cmd.extend(["/K", "type \xc0\x80"]) |
3313 | | - else: |
3314 | | - cmd.extend([b"\xc0\x80", b"-"]) |
3315 | 3315 | subp = get_test_subprocess(cmd=cmd, |
3316 | 3316 | stdin=subprocess.PIPE, |
3317 | 3317 | stdout=subprocess.PIPE, |
@@ -3342,10 +3342,10 @@ def test_proc_open_files(self): |
3342 | 3342 | test_script = os.path.join(self.temp_directory, b"test.py") |
3343 | 3343 | with open(test_script, "wt") as f: |
3344 | 3344 | f.write(textwrap.dedent(r""" |
3345 | | - import sys, os |
3346 | | - with open(%r, "wb") as f1, open(__file__, "rb") as f2: |
3347 | | - sys.stdin.read() |
3348 | | - """ % funny_file)) |
| 3345 | + import sys |
| 3346 | + with open(%r, "wb") as f1, open(__file__, "rb") as f2: |
| 3347 | + sys.stdin.read() |
| 3348 | + """ % funny_file)) |
3349 | 3349 | self.addCleanup(safe_remove, test_script) |
3350 | 3350 | subp = get_test_subprocess(cmd=[PYTHON, decode_path(test_script)], |
3351 | 3351 | stdin=subprocess.PIPE, |
|
0 commit comments