diff options
author | Christian Heimes <christian@cheimes.de> | 2007-12-03 21:02:03 +0000 |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-12-03 21:02:03 +0000 |
commit | cbf3b5cb76906fba15dbf59a1e83c540a447b907 (patch) | |
tree | 191de62298cf0af90595802cd47cff23d8f39d80 /Lib/test/test_runpy.py | |
parent | f9290773fc026c5064fa96e1d06c3924e49fa89b (diff) | |
download | cpython-git-cbf3b5cb76906fba15dbf59a1e83c540a447b907.tar.gz |
Merged revisions 59275-59303 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NOTE: The merge does NOT contain the modified file Python/import.c from
r59288. I can't get it running. Nick, please check in the PEP 366
manually.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
........
r59279 | georg.brandl | 2007-12-02 19:17:50 +0100 (Sun, 02 Dec 2007) | 2 lines
Fix a sentence I missed before. Do not merge to 3k.
........
r59281 | georg.brandl | 2007-12-02 22:58:54 +0100 (Sun, 02 Dec 2007) | 3 lines
Add documentation for PySys_* functions.
Written by Charlie Shepherd for GHOP. Also fixes #1245.
........
r59288 | nick.coghlan | 2007-12-03 13:55:17 +0100 (Mon, 03 Dec 2007) | 1 line
Implement PEP 366
........
r59290 | christian.heimes | 2007-12-03 14:47:29 +0100 (Mon, 03 Dec 2007) | 3 lines
Applied my patch #1455 with some extra fixes for VS 2005
The new msvc9compiler module supports VS 2005 and VS 2008. I've also fixed build_ext to support PCbuild8 and PCbuild9 and backported my fix for xxmodule.c from py3k. The old code msvccompiler is still in place in case somebody likes to build an extension with VS 2003 or earlier.
I've also updated the cygwin compiler module for VS 2005 and VS 2008. It works with VS 2005 but I'm unable to test it with VS 2008. We have to wait for a new version of cygwin.
........
r59291 | christian.heimes | 2007-12-03 14:55:16 +0100 (Mon, 03 Dec 2007) | 1 line
Added comment to Misc/NEWS for r59290
........
r59292 | christian.heimes | 2007-12-03 15:28:04 +0100 (Mon, 03 Dec 2007) | 1 line
I followed MA Lemberg's suggestion and added comments to the late initialization of the type slots.
........
r59293 | facundo.batista | 2007-12-03 17:29:52 +0100 (Mon, 03 Dec 2007) | 3 lines
Speedup and cleaning of __str__. Thanks Mark Dickinson.
........
r59294 | facundo.batista | 2007-12-03 18:55:00 +0100 (Mon, 03 Dec 2007) | 4 lines
Faster _fix function, and some reordering for a more elegant
coding. Thanks Mark Dickinson.
........
r59295 | martin.v.loewis | 2007-12-03 20:20:02 +0100 (Mon, 03 Dec 2007) | 5 lines
Issue #1727780: Support loading pickles of random.Random objects created
on 32-bit systems on 64-bit systems, and vice versa. As a consequence
of the change, Random pickles created by Python 2.6 cannot be loaded
in Python 2.5.
........
r59297 | facundo.batista | 2007-12-03 20:49:54 +0100 (Mon, 03 Dec 2007) | 3 lines
Two small fixes. Issue 1547.
........
r59299 | georg.brandl | 2007-12-03 20:57:02 +0100 (Mon, 03 Dec 2007) | 2 lines
#1548: fix apostroph placement.
........
r59300 | christian.heimes | 2007-12-03 21:01:02 +0100 (Mon, 03 Dec 2007) | 3 lines
Patch #1537 from Chad Austin
Change GeneratorExit's base class from Exception to BaseException
(This time I'm applying the patch to the correct sandbox.)
........
r59302 | georg.brandl | 2007-12-03 21:03:46 +0100 (Mon, 03 Dec 2007) | 3 lines
Add examples to the xmlrpclib docs.
Written for GHOP by Josip Dzolonga.
........
Diffstat (limited to 'Lib/test/test_runpy.py')
-rw-r--r-- | Lib/test/test_runpy.py | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/Lib/test/test_runpy.py b/Lib/test/test_runpy.py index b003f17a5e..ffa36dc75b 100644 --- a/Lib/test/test_runpy.py +++ b/Lib/test/test_runpy.py @@ -5,7 +5,12 @@ import os.path import sys import tempfile from test.test_support import verbose, run_unittest, forget -from runpy import _run_code, _run_module_code, _run_module_as_main, run_module +from runpy import _run_code, _run_module_code, run_module + +# Note: This module can't safely test _run_module_as_main as it +# runs its tests in the current process, which would mess with the +# real __main__ module (usually test.regrtest) +# See test_cmd_line_script for a test that executes that code path # Set up the test code and expected results @@ -36,6 +41,7 @@ class RunModuleCodeTest(unittest.TestCase): self.failUnless(d["__name__"] is None) self.failUnless(d["__file__"] is None) self.failUnless(d["__loader__"] is None) + self.failUnless(d["__package__"] is None) self.failUnless(d["run_argv0"] is saved_argv0) self.failUnless("run_name" not in d) self.failUnless(sys.argv[0] is saved_argv0) @@ -45,13 +51,15 @@ class RunModuleCodeTest(unittest.TestCase): name = "<Nonsense>" file = "Some other nonsense" loader = "Now you're just being silly" + package = '' # Treat as a top level module d1 = dict(initial=initial) saved_argv0 = sys.argv[0] d2 = _run_module_code(self.test_source, d1, name, file, - loader) + loader, + package) self.failUnless("result" not in d1) self.failUnless(d2["initial"] is initial) self.assertEqual(d2["result"], self.expected_result) @@ -62,6 +70,7 @@ class RunModuleCodeTest(unittest.TestCase): self.failUnless(d2["__file__"] is file) self.failUnless(d2["run_argv0"] is file) self.failUnless(d2["__loader__"] is loader) + self.failUnless(d2["__package__"] is package) self.failUnless(sys.argv[0] is saved_argv0) self.failUnless(name not in sys.modules) @@ -164,7 +173,7 @@ class RunModuleTest(unittest.TestCase): self._del_pkg(pkg_dir, depth, mod_name) if verbose: print("Module executed successfully") - def _add_relative_modules(self, base_dir, depth): + def _add_relative_modules(self, base_dir, source, depth): if depth <= 1: raise ValueError("Relative module test needs depth > 1") pkg_name = "__runpy_pkg__" @@ -190,7 +199,7 @@ class RunModuleTest(unittest.TestCase): if verbose: print(" Added nephew module:", nephew_fname) def _check_relative_imports(self, depth, run_name=None): - contents = """\ + contents = r"""\ from __future__ import absolute_import from . import sibling from ..uncle.cousin import nephew @@ -198,16 +207,21 @@ from ..uncle.cousin import nephew pkg_dir, mod_fname, mod_name = ( self._make_pkg(contents, depth)) try: - self._add_relative_modules(pkg_dir, depth) + self._add_relative_modules(pkg_dir, contents, depth) + pkg_name = mod_name.rpartition('.')[0] if verbose: print("Running from source:", mod_name) - d1 = run_module(mod_name) # Read from source + d1 = run_module(mod_name, run_name=run_name) # Read from source + self.failUnless("__package__" in d1) + self.failUnless(d1["__package__"] == pkg_name) self.failUnless("sibling" in d1) self.failUnless("nephew" in d1) del d1 # Ensure __loader__ entry doesn't keep file open __import__(mod_name) os.remove(mod_fname) if verbose: print("Running from compiled:", mod_name) - d2 = run_module(mod_name) # Read from bytecode + d2 = run_module(mod_name, run_name=run_name) # Read from bytecode + self.failUnless("__package__" in d2) + self.failUnless(d2["__package__"] == pkg_name) self.failUnless("sibling" in d2) self.failUnless("nephew" in d2) del d2 # Ensure __loader__ entry doesn't keep file open @@ -225,6 +239,11 @@ from ..uncle.cousin import nephew if verbose: print("Testing relative imports at depth:", depth) self._check_relative_imports(depth) + def test_main_relative_import(self): + for depth in range(2, 5): + if verbose: print("Testing main relative imports at depth:", depth) + self._check_relative_imports(depth, "__main__") + def test_main(): run_unittest(RunModuleCodeTest) |