summaryrefslogtreecommitdiff
path: root/test/test_execfile.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2011-02-06 23:02:12 -0500
committerNed Batchelder <ned@nedbatchelder.com>2011-02-06 23:02:12 -0500
commit2afc485b2724f496c67e0660c9c3683c52634515 (patch)
treedf91bb766f3836f428e533a9a6907569793e45b4 /test/test_execfile.py
parent50bc61cd0b0a66ec6cc497ea6870765d627fb9be (diff)
downloadpython-coveragepy-git-2afc485b2724f496c67e0660c9c3683c52634515.tar.gz
Add tests and doc for Brandon's -m flag.
Diffstat (limited to 'test/test_execfile.py')
-rw-r--r--test/test_execfile.py43
1 files changed, 41 insertions, 2 deletions
diff --git a/test/test_execfile.py b/test/test_execfile.py
index f6e4dd7f..1c5b8024 100644
--- a/test/test_execfile.py
+++ b/test/test_execfile.py
@@ -2,7 +2,7 @@
import os, sys
-from coverage.execfile import run_python_file
+from coverage.execfile import run_python_file, run_python_module
from coverage.misc import NoSource
sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k
@@ -10,7 +10,7 @@ from coveragetest import CoverageTest
here = os.path.dirname(__file__)
-class RunTest(CoverageTest):
+class RunFileTest(CoverageTest):
"""Test cases for `run_python_file`."""
def test_run_python_file(self):
@@ -76,3 +76,42 @@ class RunTest(CoverageTest):
def test_no_such_file(self):
self.assertRaises(NoSource, run_python_file, "xyzzy.py", [])
+
+
+class RunModuleTest(CoverageTest):
+ """Test run_python_module."""
+
+ run_in_temp_dir = False
+
+ def setUp(self):
+ super(RunModuleTest, self).setUp()
+ # Parent class saves and restores sys.path, we can just modify it.
+ sys.path.append(self.nice_file(os.path.dirname(__file__), 'modules'))
+
+ def test_runmod1(self):
+ run_python_module("runmod1", ["runmod1", "hello"])
+ self.assertEqual(self.stdout(), "runmod1: passed hello\n")
+
+ def test_runmod2(self):
+ run_python_module("pkg1.runmod2", ["runmod2", "hello"])
+ self.assertEqual(self.stdout(), "runmod2: passed hello\n")
+
+ def test_runmod3(self):
+ run_python_module("pkg1.sub.runmod3", ["runmod3", "hello"])
+ self.assertEqual(self.stdout(), "runmod3: passed hello\n")
+
+ def test_pkg1_main(self):
+ run_python_module("pkg1", ["pkg1", "hello"])
+ self.assertEqual(self.stdout(), "pkg1.__main__: passed hello\n")
+
+ def test_pkg1_sub_main(self):
+ run_python_module("pkg1.sub", ["pkg1.sub", "hello"])
+ self.assertEqual(self.stdout(), "pkg1.sub.__main__: passed hello\n")
+
+ def test_no_such_module(self):
+ self.assertRaises(NoSource, run_python_module, "i_dont_exist", [])
+ self.assertRaises(NoSource, run_python_module, "i.dont_exist", [])
+ self.assertRaises(NoSource, run_python_module, "i.dont.exist", [])
+
+ def test_no_main(self):
+ self.assertRaises(NoSource, run_python_module, "pkg2", ["pkg2", "hi"])