]> granicus.if.org Git - python/commitdiff
support: temp_dir() and change_cwd() uses repr() in error message
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 8 Feb 2017 14:49:10 +0000 (15:49 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 8 Feb 2017 14:49:10 +0000 (15:49 +0100)
Serhiy Storshaka pointed me that str(path) can emit a BytesWarning: use
repr(path) instead.

Lib/test/support/__init__.py
Lib/test/test_support.py

index d82ac88d77d330fc26735d0ecb1f5933603544be..6658ece735cfe907e2d0c1ab650f96e5be9cdfd0 100644 (file)
@@ -958,7 +958,7 @@ def temp_dir(path=None, quiet=False):
             if not quiet:
                 raise
             warnings.warn(f'tests may fail, unable to create '
-                          f'temporary directory {path}: {exc}',
+                          f'temporary directory {path!r}: {exc}',
                           RuntimeWarning, stacklevel=3)
     try:
         yield path
@@ -986,7 +986,7 @@ def change_cwd(path, quiet=False):
         if not quiet:
             raise
         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)
     try:
         yield os.getcwd()
index dd0c7bc2325b2824202047b0d4b93eac1a8bb052..0dbe02eeb388b60f3d09779cf445b91cfc65f5fe 100644 (file)
@@ -158,7 +158,7 @@ class TestSupport(unittest.TestCase):
         self.assertEqual(len(warnings), 1, warnings)
         warn = warnings[0]
         self.assertTrue(warn.startswith(f'tests may fail, unable to create '
-                                        f'temporary directory {path}: '),
+                                        f'temporary directory {path!r}: '),
                         warn)
 
     # Tests for change_cwd()
@@ -204,7 +204,7 @@ class TestSupport(unittest.TestCase):
         warn = warnings[0]
         self.assertTrue(warn.startswith(f'tests may fail, unable to change '
                                         f'the current working directory '
-                                        f'to {bad_dir}: '),
+                                        f'to {bad_dir!r}: '),
                         warn)
 
     # Tests for change_cwd()
@@ -221,7 +221,7 @@ class TestSupport(unittest.TestCase):
         msg = messages[0]
         self.assertTrue(msg.startswith(f'tests may fail, unable to change '
                                        f'the current working directory '
-                                       f'to {path}: '),
+                                       f'to {path!r}: '),
                         msg)
 
     # Tests for temp_cwd()