summaryrefslogtreecommitdiff
path: root/tests/test_process.py
diff options
context:
space:
mode:
authorbuck <buck.2019@gmail.com>2014-10-15 12:04:05 -0700
committerbuck <buck.2019@gmail.com>2014-10-15 12:04:05 -0700
commita3cb81edd6053a273447ba3821655320ed234a41 (patch)
tree8a1a84f15ccace44c409d297f7350a4b3f1cb3a7 /tests/test_process.py
parentc2f80902e35e5e4f638d66d1a1996e1ba6dca642 (diff)
downloadpython-coveragepy-git-a3cb81edd6053a273447ba3821655320ed234a41.tar.gz
make --source and -m play nice together
--HG-- branch : __main__-support extra : rebase_source : c9ca9fddecafddd5ef4db9cc64ca1c0972130aab
Diffstat (limited to 'tests/test_process.py')
-rw-r--r--tests/test_process.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test_process.py b/tests/test_process.py
index ac5c6e1b..e53e64c9 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -331,6 +331,55 @@ class ProcessTest(CoverageTest):
out_py = self.run_command("python -m tests.try_execfile")
self.assertMultiLineEqual(out_cov, out_py)
+ def test_coverage_run_dashm_equal_to_doubledashsource(self):
+ """regression test for #328
+
+ When imported by -m, a module's __name__ is __main__, but we need the
+ --source machinery to know and respect the original name.
+ """
+ # These -m commands assume the coverage tree is on the path.
+ out_cov = self.run_command(
+ "coverage run --source tests.try_execfile -m tests.try_execfile"
+ )
+ out_py = self.run_command("python -m tests.try_execfile")
+ self.assertMultiLineEqual(out_cov, out_py)
+
+ def test_coverage_run_dashm_superset_of_doubledashsource(self):
+ """Edge case: --source foo -m foo.bar"""
+ # These -m commands assume the coverage tree is on the path.
+ out_cov = self.run_command(
+ "coverage run --source tests -m tests.try_execfile"
+ )
+ out_py = self.run_command("python -m tests.try_execfile")
+ self.assertMultiLineEqual(out_cov, out_py)
+
+ st, out = self.run_command_status("coverage report")
+ self.assertEqual(st, 0)
+ self.assertEqual(self.line_count(out), 6, out)
+
+ def test_coverage_run_script_imports_doubledashsource(self):
+ self.make_file("myscript", """\
+ import sys
+ sys.dont_write_bytecode = True
+
+ def main():
+ import tests.try_execfile
+
+ if __name__ == '__main__':
+ main()
+ """)
+
+ # These -m commands assume the coverage tree is on the path.
+ out_cov = self.run_command(
+ "coverage run --source tests myscript"
+ )
+ out_py = self.run_command("python myscript")
+ self.assertMultiLineEqual(out_cov, out_py)
+
+ st, out = self.run_command_status("coverage report")
+ self.assertEqual(st, 0)
+ self.assertEqual(self.line_count(out), 6, out)
+
def test_coverage_run_dashm_is_like_python_dashm_off_path(self):
# https://bitbucket.org/ned/coveragepy/issue/242
tryfile = os.path.join(here, "try_execfile.py")