From 3a329a0cdb7c305880d6f0adbd73d278cd3c76d2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 8 Feb 2017 12:49:02 +0100 Subject: Update test_support for my temp_dir/change_cwd changes --- Lib/test/test_support.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'Lib/test/test_support.py') diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index e83a4d6426..dd0c7bc232 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -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() -- cgit v1.2.1 From 523c06aebf562b35e1fa84080bd051b608fe7d7f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 8 Feb 2017 15:49:10 +0100 Subject: 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. --- Lib/test/test_support.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Lib/test/test_support.py') diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index dd0c7bc232..0dbe02eeb3 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -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() -- cgit v1.2.1