From 9ae35a5f6a4fed487ef6c14edd6b4eb4f5c1b7f0 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 6 Jul 2019 17:17:07 -0400 Subject: Add tests of bug #806, and ensure it's fixed even if the program ends with an exception --- tests/test_process.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests') diff --git a/tests/test_process.py b/tests/test_process.py index 0979cc2c..a5303338 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -1293,6 +1293,36 @@ class UnicodeFilePathsTest(CoverageTest): self.assertEqual(out, report_expected) +class YankedDirectoryTest(CoverageTest): + """Tests of what happens when the current directory is deleted.""" + + BUG_806 = """\ + import os + import sys + import tempfile + + tmpdir = tempfile.mkdtemp() + os.chdir(tmpdir) + os.rmdir(tmpdir) + print(sys.argv[1]) + """ + + def test_removing_directory(self): + self.make_file("bug806.py", self.BUG_806) + out = self.run_command("coverage run bug806.py noerror") + self.assertEqual(out, "noerror\n") + + def test_removing_directory_with_error(self): + self.make_file("bug806.py", self.BUG_806) + out = self.run_command("coverage run bug806.py") + self.assertEqual(out, textwrap.dedent("""\ + Traceback (most recent call last): + File "bug806.py", line 8, in + print(sys.argv[1]) + IndexError: list index out of range + """)) + + def possible_pth_dirs(): """Produce a sequence of directories for trying to write .pth files.""" # First look through sys.path, and if we find a .pth file, then it's a good -- cgit v1.2.1