diff options
| author | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-01 17:15:27 -0400 |
|---|---|---|
| committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-01 17:15:27 -0400 |
| commit | 83c5a53febfd8a7028a688678e3d5308e667a862 (patch) | |
| tree | 8323303e70f6a223ee952d680156f675ee9ae5d8 /tests/test_process.py | |
| parent | 162bab174bf05323e75e247411b8c86e49420415 (diff) | |
| download | python-coveragepy-83c5a53febfd8a7028a688678e3d5308e667a862.tar.gz | |
Support directories on the 'coverage run' command line. #252
Diffstat (limited to 'tests/test_process.py')
| -rw-r--r-- | tests/test_process.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test_process.py b/tests/test_process.py index 7c8b0c2..fcd8882 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -7,6 +7,7 @@ import glob import os import os.path +import re import sys import textwrap @@ -387,6 +388,26 @@ class ProcessTest(CoverageTest): out_py = self.run_command("python -m tests.try_execfile") self.assertMultiLineEqual(out_cov, out_py) + def test_coverage_run_dir_is_like_python_dir(self): + tryfile = os.path.join(HERE, "try_execfile.py") + with open(tryfile) as f: + self.make_file("with_main/__main__.py", f.read()) + out_cov = self.run_command("coverage run with_main") + out_py = self.run_command("python with_main") + + # The coverage.py results are not identical to the Python results, and + # I don't know why. For now, ignore those failures. If someone finds + # a real problem with the discrepancies, we can work on it some more. + ignored = r"__file__|__loader__|__package__" + # PyPy includes the current directory in the path when running a + # directory, while CPython and coverage.py do not. Exclude that from + # the comparison also... + if env.PYPY: + ignored += "|"+re.escape(os.getcwd()) + out_cov = remove_matching_lines(out_cov, ignored) + out_py = remove_matching_lines(out_py, ignored) + self.assertMultiLineEqual(out_cov, out_py) + def test_coverage_run_dashm_equal_to_doubledashsource(self): """regression test for #328 @@ -995,3 +1016,9 @@ class ProcessStartupWithSourceTest(ProcessCoverageMixin, CoverageTest): def test_script_pkg_sub(self): self.assert_pth_and_source_work_together('', 'pkg', 'sub') + + +def remove_matching_lines(text, pat): + """Return `text` with all lines matching `pat` removed.""" + lines = [l for l in text.splitlines(True) if not re.search(pat, l)] + return "".join(lines) |
