diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2019-11-25 15:43:44 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2019-11-25 15:54:39 -0500 |
commit | a28e873891003ad31762e1214d32f54ec423fd62 (patch) | |
tree | e9af8c2f06a415795279ccf568a19ff9a669e6a5 /tests | |
parent | 69dbdcece78118d14aa45cacbe0d22eae494e99e (diff) | |
download | python-coveragepy-git-a28e873891003ad31762e1214d32f54ec423fd62.tar.gz |
Adapt to 3.9's way of reporting files using absolute paths.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_execfile.py | 14 | ||||
-rw-r--r-- | tests/test_process.py | 19 |
2 files changed, 23 insertions, 10 deletions
diff --git a/tests/test_execfile.py b/tests/test_execfile.py index 7ced605a..e3d62005 100644 --- a/tests/test_execfile.py +++ b/tests/test_execfile.py @@ -14,6 +14,7 @@ import sys from coverage import env from coverage.backward import binary_bytes from coverage.execfile import run_python_file, run_python_module +from coverage.files import python_reported_file from coverage.misc import NoCode, NoSource from tests.coveragetest import CoverageTest, TESTS_DIR, UsingModulesMixin @@ -45,7 +46,7 @@ class RunFileTest(CoverageTest): self.assertEqual(mod_globs['__main__.DATA'], "xyzzy") # Argv should have the proper values. - self.assertEqual(mod_globs['argv0'], TRY_EXECFILE) + self.assertEqual(mod_globs['argv0'], python_reported_file(TRY_EXECFILE)) self.assertEqual(mod_globs['argv1-n'], ["arg1", "arg2"]) # __builtins__ should have the right values, like open(). @@ -84,7 +85,9 @@ class RunFileTest(CoverageTest): self.assertEqual(self.stdout(), "a is 1\n") def test_no_such_file(self): - with self.assertRaisesRegex(NoSource, "No file to run: 'xyzzy.py'"): + path = python_reported_file('xyzzy.py') + msg = re.escape("No file to run: '{}'".format(path)) + with self.assertRaisesRegex(NoSource, msg): run_python_file(["xyzzy.py"]) def test_directory_with_main(self): @@ -156,7 +159,9 @@ class RunPycFileTest(CoverageTest): os.remove(pycfile) def test_no_such_pyc_file(self): - with self.assertRaisesRegex(NoCode, "No file to run: 'xyzzy.pyc'"): + path = python_reported_file('xyzzy.pyc') + msg = re.escape("No file to run: '{}'".format(path)) + with self.assertRaisesRegex(NoCode, msg): run_python_file(["xyzzy.pyc"]) def test_running_py_from_binary(self): @@ -166,8 +171,9 @@ class RunPycFileTest(CoverageTest): with open(bf, "wb") as f: f.write(b'\x7fELF\x02\x01\x01\x00\x00\x00') + path = python_reported_file('binary') msg = ( - r"Couldn't run 'binary' as Python code: " + re.escape("Couldn't run '{}' as Python code: ".format(path)) + r"(TypeError|ValueError): " r"(" r"compile\(\) expected string without null bytes" # for py2 diff --git a/tests/test_process.py b/tests/test_process.py index 06e429dd..e9e19e8a 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -18,6 +18,7 @@ import pytest import coverage from coverage import env from coverage.data import line_counts +from coverage.files import python_reported_file from coverage.misc import output_encoding from tests.coveragetest import CoverageTest @@ -472,9 +473,10 @@ class ProcessTest(CoverageTest): self.assertMultiLineEqual(out, out2) # But also make sure that the output is what we expect. - self.assertIn('File "throw.py", line 5, in f2', out) + path = python_reported_file('throw.py') + msg = 'File "{}", line 5,? in f2'.format(re.escape(path)) + self.assertRegex(out, msg) self.assertIn('raise Exception("hey!")', out) - self.assertNotIn('coverage', out) self.assertEqual(status, 1) def test_code_exits(self): @@ -582,9 +584,13 @@ class ProcessTest(CoverageTest): out = self.run_command("coverage html") self.assertEqual(out.count("Module xyzzy was never imported."), 0) - def test_warnings_if_never_run(self): + def test_warns_if_never_run(self): + # Note: the name of the function can't have "warning" in it, or the + # absolute path of the file will have "warning" in it, and an assertion + # will fail. out = self.run_command("coverage run i_dont_exist.py") - self.assertIn("No file to run: 'i_dont_exist.py'", out) + path = python_reported_file('i_dont_exist.py') + self.assertIn("No file to run: '{}'".format(path), out) self.assertNotIn("warning", out) self.assertNotIn("Exception", out) @@ -1321,12 +1327,13 @@ class YankedDirectoryTest(CoverageTest): def test_removing_directory_with_error(self): self.make_file("bug806.py", self.BUG_806) out = self.run_command("coverage run bug806.py") + path = python_reported_file('bug806.py') self.assertEqual(out, textwrap.dedent("""\ Traceback (most recent call last): - File "bug806.py", line 8, in <module> + File "{}", line 8, in <module> print(sys.argv[1]) IndexError: list index out of range - """)) + """.format(path))) def possible_pth_dirs(): |