Commit 04054d9a authored by Victor Stinner's avatar Victor Stinner

Update test_support for my temp_dir/change_cwd changes

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