]> granicus.if.org Git - python/commitdiff
Update test_support for my temp_dir/change_cwd changes
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 8 Feb 2017 11:49:02 +0000 (12:49 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 8 Feb 2017 11:49:02 +0000 (12:49 +0100)
Lib/test/support/__init__.py
Lib/test/test_support.py

index 58e4f92ead196042397e37f90ec01514a3117c8a..d82ac88d77d330fc26735d0ecb1f5933603544be 100644 (file)
@@ -985,7 +985,7 @@ def change_cwd(path, quiet=False):
     except OSError as exc:
         if not quiet:
             raise
-        warnings.warn(f'tests may fail, unable to change current working '
+        warnings.warn(f'tests may fail, unable to change the current working '
                       f'directory to {path}: {exc}',
                       RuntimeWarning, stacklevel=3)
     try:
index e83a4d6426a8b2d05517eb76c77bb4e5220afd73..dd0c7bc2325b2824202047b0d4b93eac1a8bb052 100644 (file)
@@ -155,8 +155,11 @@ class TestSupport(unittest.TestCase):
         finally:
             shutil.rmtree(path)
 
-        expected = ['tests may fail, unable to create temp dir: ' + path]
-        self.assertEqual(warnings, expected)
+        self.assertEqual(len(warnings), 1, warnings)
+        warn = warnings[0]
+        self.assertTrue(warn.startswith(f'tests may fail, unable to create '
+                                        f'temporary directory {path}: '),
+                        warn)
 
     # Tests for change_cwd()
 
@@ -197,8 +200,12 @@ class TestSupport(unittest.TestCase):
                     self.assertEqual(os.getcwd(), new_cwd)
                 warnings = [str(w.message) for w in recorder.warnings]
 
-        expected = ['tests may fail, unable to change CWD to: ' + bad_dir]
-        self.assertEqual(warnings, expected)
+        self.assertEqual(len(warnings), 1, warnings)
+        warn = warnings[0]
+        self.assertTrue(warn.startswith(f'tests may fail, unable to change '
+                                        f'the current working directory '
+                                        f'to {bad_dir}: '),
+                        warn)
 
     # Tests for change_cwd()
 
@@ -209,7 +216,13 @@ class TestSupport(unittest.TestCase):
             with support.change_cwd(path=path, quiet=True):
                 pass
             messages = [str(w.message) for w in recorder.warnings]
-        self.assertEqual(messages, ['tests may fail, unable to change CWD to: ' + path])
+
+        self.assertEqual(len(messages), 1, messages)
+        msg = messages[0]
+        self.assertTrue(msg.startswith(f'tests may fail, unable to change '
+                                       f'the current working directory '
+                                       f'to {path}: '),
+                        msg)
 
     # Tests for temp_cwd()