summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2006-06-28 10:41:47 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2006-06-28 10:41:47 (GMT)
commit999a336ad7aaf6819a0e703f87dbc0bc9f599030 (patch)
tree8ed38fd57b7ecbc6648413c142aeafe30ee2cb34 /Lib/test
parent0f8b31a2dad17ed18ff11fbe36e8d56dce4de0b5 (diff)
downloadcpython-999a336ad7aaf6819a0e703f87dbc0bc9f599030.zip
cpython-999a336ad7aaf6819a0e703f87dbc0bc9f599030.tar.gz
cpython-999a336ad7aaf6819a0e703f87dbc0bc9f599030.tar.bz2
Make full module name available as __module_name__ even when __name__ is set to something else (like '__main__')
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_runpy.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/Lib/test/test_runpy.py b/Lib/test/test_runpy.py
index 88e9900..acbd3fc 100644
--- a/Lib/test/test_runpy.py
+++ b/Lib/test/test_runpy.py
@@ -23,6 +23,8 @@ class RunModuleCodeTest(unittest.TestCase):
"run_argv0 = sys.argv[0]\n"
"if __name__ in sys.modules:\n"
" run_name = sys.modules[__name__].__name__\n"
+ "if __module_name__ in sys.modules:\n"
+ " mod_name = sys.modules[__module_name__].__module_name__\n"
"# Check nested operation\n"
"import runpy\n"
"nested = runpy._run_module_code('x=1\\n', mod_name='<run>',\n"
@@ -32,14 +34,16 @@ class RunModuleCodeTest(unittest.TestCase):
def test_run_module_code(self):
initial = object()
- name = "<Nonsense>"
+ run_name = "<Nonsense>"
+ mod_name = "<ModuleNonsense>"
file = "Some other nonsense"
loader = "Now you're just being silly"
d1 = dict(initial=initial)
saved_argv0 = sys.argv[0]
d2 = _run_module_code(self.test_source,
d1,
- name,
+ run_name,
+ mod_name,
file,
loader,
True)
@@ -47,19 +51,23 @@ class RunModuleCodeTest(unittest.TestCase):
self.failUnless(d2["initial"] is initial)
self.failUnless(d2["result"] == self.expected_result)
self.failUnless(d2["nested"]["x"] == 1)
- self.failUnless(d2["__name__"] is name)
- self.failUnless(d2["run_name"] is name)
+ self.failUnless(d2["__name__"] is run_name)
+ self.failUnless(d2["run_name"] is run_name)
+ self.failUnless(d2["__module_name__"] is mod_name)
+ self.failUnless(d2["mod_name"] is mod_name)
self.failUnless(d2["__file__"] is file)
self.failUnless(d2["run_argv0"] is file)
self.failUnless(d2["__loader__"] is loader)
self.failUnless(sys.argv[0] is saved_argv0)
- self.failUnless(name not in sys.modules)
+ self.failUnless(mod_name not in sys.modules)
+ self.failUnless(run_name not in sys.modules)
def test_run_module_code_defaults(self):
saved_argv0 = sys.argv[0]
d = _run_module_code(self.test_source)
self.failUnless(d["result"] == self.expected_result)
self.failUnless(d["__name__"] is None)
+ self.failUnless(d["__module_name__"] is None)
self.failUnless(d["__file__"] is None)
self.failUnless(d["__loader__"] is None)
self.failUnless(d["run_argv0"] is saved_argv0)