Commit 3722f1f4 authored by Victor Stinner's avatar Victor Stinner

support: temp_dir() and change_cwd() uses repr() in error message

Serhiy Storshaka pointed me that str(path) can emit a BytesWarning: use
repr(path) instead.
parent 620580f2
...@@ -958,7 +958,7 @@ def temp_dir(path=None, quiet=False): ...@@ -958,7 +958,7 @@ def temp_dir(path=None, quiet=False):
if not quiet: if not quiet:
raise raise
warnings.warn(f'tests may fail, unable to create ' warnings.warn(f'tests may fail, unable to create '
f'temporary directory {path}: {exc}', f'temporary directory {path!r}: {exc}',
RuntimeWarning, stacklevel=3) RuntimeWarning, stacklevel=3)
try: try:
yield path yield path
...@@ -986,7 +986,7 @@ def change_cwd(path, quiet=False): ...@@ -986,7 +986,7 @@ def change_cwd(path, quiet=False):
if not quiet: if not quiet:
raise raise
warnings.warn(f'tests may fail, unable to change the current working ' warnings.warn(f'tests may fail, unable to change the current working '
f'directory to {path}: {exc}', f'directory to {path!r}: {exc}',
RuntimeWarning, stacklevel=3) RuntimeWarning, stacklevel=3)
try: try:
yield os.getcwd() yield os.getcwd()
......
...@@ -158,7 +158,7 @@ class TestSupport(unittest.TestCase): ...@@ -158,7 +158,7 @@ class TestSupport(unittest.TestCase):
self.assertEqual(len(warnings), 1, warnings) self.assertEqual(len(warnings), 1, warnings)
warn = warnings[0] warn = warnings[0]
self.assertTrue(warn.startswith(f'tests may fail, unable to create ' self.assertTrue(warn.startswith(f'tests may fail, unable to create '
f'temporary directory {path}: '), f'temporary directory {path!r}: '),
warn) warn)
# Tests for change_cwd() # Tests for change_cwd()
...@@ -204,7 +204,7 @@ class TestSupport(unittest.TestCase): ...@@ -204,7 +204,7 @@ class TestSupport(unittest.TestCase):
warn = warnings[0] warn = warnings[0]
self.assertTrue(warn.startswith(f'tests may fail, unable to change ' self.assertTrue(warn.startswith(f'tests may fail, unable to change '
f'the current working directory ' f'the current working directory '
f'to {bad_dir}: '), f'to {bad_dir!r}: '),
warn) warn)
# Tests for change_cwd() # Tests for change_cwd()
...@@ -221,7 +221,7 @@ class TestSupport(unittest.TestCase): ...@@ -221,7 +221,7 @@ class TestSupport(unittest.TestCase):
msg = messages[0] msg = messages[0]
self.assertTrue(msg.startswith(f'tests may fail, unable to change ' self.assertTrue(msg.startswith(f'tests may fail, unable to change '
f'the current working directory ' f'the current working directory '
f'to {path}: '), f'to {path!r}: '),
msg) msg)
# Tests for temp_cwd() # Tests for temp_cwd()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment