summaryrefslogtreecommitdiff
path: root/test/test_execfile.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-04-03 23:32:19 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-04-03 23:32:19 -0400
commita56bfefc8d9dac39be06037f2fc074d048b522bc (patch)
treed1423b45a514ac4d71f06a693bcc1e54c70a02c3 /test/test_execfile.py
parent4910434d33d0928374bf966c00c07feda5b32d77 (diff)
downloadpython-coveragepy-git-a56bfefc8d9dac39be06037f2fc074d048b522bc.tar.gz
Factor execfile out of cmdline, so that we can call python main programs properly: now they get the correct value for __file__.
Diffstat (limited to 'test/test_execfile.py')
-rw-r--r--test/test_execfile.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/test_execfile.py b/test/test_execfile.py
new file mode 100644
index 00000000..90340f57
--- /dev/null
+++ b/test/test_execfile.py
@@ -0,0 +1,19 @@
+from coverage.execfile import run_python_file
+import cStringIO, os, sys, unittest
+
+here = os.path.dirname(__file__)
+
+class RunTests(unittest.TestCase):
+ def setUp(self):
+ self.oldstdout = sys.stdout
+ self.stdout = sys.stdout = cStringIO.StringIO()
+
+ def tearDown(self):
+ self.stdout = self.oldstdout
+
+ def test_run_python_file(self):
+ tryfile = os.path.join(here, "try_execfile.py")
+ run_python_file(tryfile)
+ mod_globs = eval(self.stdout.getvalue())
+ self.assertEqual(mod_globs['__name__'], "__main__")
+ self.assertEqual(os.path.basename(mod_globs['__file__']), "try_execfile.py")