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 | 5e45baa100135e2ef327feb767e8e027a58d1637 (patch) | |
tree | 352e759ace46d27e92a66b35045313abe7121e15 /tests/test_process.py | |
parent | 3e6e85a71c1ad66cd8ed658a61bedbff38f47dd1 (diff) | |
download | python-coveragepy-git-5e45baa100135e2ef327feb767e8e027a58d1637.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 7c8b0c2d..fcd88827 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) |