annotate Lib/test/test_runpy.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 803edf9b1dd9
children 6768b2350c57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
1 # Test the runpy module
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
2 import unittest
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
3 import os
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
4 import os.path
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
5 import sys
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
6 import tempfile
42729
2480b864be03 Make test_runpy re-entrant.
Brett Cannon <bcannon@gmail.com>
parents: 42357
diff changeset
7 from test.test_support import verbose, run_unittest, forget
44116
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
8 from runpy import _run_code, _run_module_code, run_module
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
9
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
10 # Note: This module can't safely test _run_module_as_main as it
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
11 # runs its tests in the current process, which would mess with the
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
12 # real __main__ module (usually test.regrtest)
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
13 # See test_cmd_line_script for a test that executes that code path
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
14
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
15 # Set up the test code and expected results
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
16
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
17 class RunModuleCodeTest(unittest.TestCase):
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
18
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
19 expected_result = ["Top level assignment", "Lower level reference"]
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
20 test_source = (
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
21 "# Check basic code execution\n"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
22 "result = ['Top level assignment']\n"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
23 "def f():\n"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
24 " result.append('Lower level reference')\n"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
25 "f()\n"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
26 "# Check the sys module\n"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
27 "import sys\n"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
28 "run_argv0 = sys.argv[0]\n"
42356
d94d5b416a94 Tweak runpy test to do a better job of confirming that sys has been manipulated correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 42349
diff changeset
29 "run_name_in_sys_modules = __name__ in sys.modules\n"
d94d5b416a94 Tweak runpy test to do a better job of confirming that sys has been manipulated correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 42349
diff changeset
30 "if run_name_in_sys_modules:\n"
d94d5b416a94 Tweak runpy test to do a better job of confirming that sys has been manipulated correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 42349
diff changeset
31 " module_in_sys_modules = globals() is sys.modules[__name__].__dict__\n"
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
32 "# Check nested operation\n"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
33 "import runpy\n"
42825
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 42819
diff changeset
34 "nested = runpy._run_module_code('x=1\\n', mod_name='<run>')\n"
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
35 )
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
36
42825
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 42819
diff changeset
37 def test_run_code(self):
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 42819
diff changeset
38 saved_argv0 = sys.argv[0]
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 42819
diff changeset
39 d = _run_code(self.test_source, {})
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 42819
diff changeset
40 self.failUnless(d["result"] == self.expected_result)
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 42819
diff changeset
41 self.failUnless(d["__name__"] is None)
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 42819
diff changeset
42 self.failUnless(d["__file__"] is None)
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 42819
diff changeset
43 self.failUnless(d["__loader__"] is None)
44116
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
44 self.failUnless(d["__package__"] is None)
42825
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 42819
diff changeset
45 self.failUnless(d["run_argv0"] is saved_argv0)
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 42819
diff changeset
46 self.failUnless("run_name" not in d)
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 42819
diff changeset
47 self.failUnless(sys.argv[0] is saved_argv0)
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
48
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
49 def test_run_module_code(self):
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
50 initial = object()
39022
34cb9a6ce12d Revert the __module_name__ changes made in rev 47142. We'll revisit this in Python 2.6
Nick Coghlan <ncoghlan@gmail.com>
parents: 38951
diff changeset
51 name = "<Nonsense>"
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
52 file = "Some other nonsense"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
53 loader = "Now you're just being silly"
44116
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
54 package = '' # Treat as a top level module
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
55 d1 = dict(initial=initial)
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
56 saved_argv0 = sys.argv[0]
42819
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
57 d2 = _run_module_code(self.test_source,
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
58 d1,
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
59 name,
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
60 file,
44116
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
61 loader,
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
62 package)
42819
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
63 self.failUnless("result" not in d1)
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
64 self.failUnless(d2["initial"] is initial)
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
65 self.failUnless(d2["result"] == self.expected_result)
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
66 self.failUnless(d2["nested"]["x"] == 1)
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
67 self.failUnless(d2["__name__"] is name)
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
68 self.failUnless(d2["run_name_in_sys_modules"])
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
69 self.failUnless(d2["module_in_sys_modules"])
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
70 self.failUnless(d2["__file__"] is file)
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
71 self.failUnless(d2["run_argv0"] is file)
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
72 self.failUnless(d2["__loader__"] is loader)
44116
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
73 self.failUnless(d2["__package__"] is package)
42819
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
74 self.failUnless(sys.argv[0] is saved_argv0)
1b420e6e00eb Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 42729
diff changeset
75 self.failUnless(name not in sys.modules)
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
76
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
77
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
78 class RunModuleTest(unittest.TestCase):
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
79
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
80 def expect_import_error(self, mod_name):
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
81 try:
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
82 run_module(mod_name)
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
83 except ImportError:
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
84 pass
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
85 else:
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
86 self.fail("Expected import error for " + mod_name)
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
87
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
88 def test_invalid_names(self):
42349
3fe643d62ecc Correctly cleanup sys.modules after executing runpy relative import
Nick Coghlan <ncoghlan@gmail.com>
parents: 42337
diff changeset
89 # Builtin module
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
90 self.expect_import_error("sys")
42349
3fe643d62ecc Correctly cleanup sys.modules after executing runpy relative import
Nick Coghlan <ncoghlan@gmail.com>
parents: 42337
diff changeset
91 # Non-existent modules
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
92 self.expect_import_error("sys.imp.eric")
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
93 self.expect_import_error("os.path.half")
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
94 self.expect_import_error("a.bee")
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
95 self.expect_import_error(".howard")
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
96 self.expect_import_error("..eaten")
42349
3fe643d62ecc Correctly cleanup sys.modules after executing runpy relative import
Nick Coghlan <ncoghlan@gmail.com>
parents: 42337
diff changeset
97 # Package
3fe643d62ecc Correctly cleanup sys.modules after executing runpy relative import
Nick Coghlan <ncoghlan@gmail.com>
parents: 42337
diff changeset
98 self.expect_import_error("logging")
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
99
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
100 def test_library_module(self):
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
101 run_module("runpy")
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
102
42337
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
103 def _add_pkg_dir(self, pkg_dir):
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
104 os.mkdir(pkg_dir)
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
105 pkg_fname = os.path.join(pkg_dir, "__init__"+os.extsep+"py")
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
106 pkg_file = open(pkg_fname, "w")
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
107 pkg_file.close()
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
108 return pkg_fname
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
109
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
110 def _make_pkg(self, source, depth):
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
111 pkg_name = "__runpy_pkg__"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
112 test_fname = "runpy_test"+os.extsep+"py"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
113 pkg_dir = sub_dir = tempfile.mkdtemp()
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
114 if verbose: print " Package tree in:", sub_dir
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
115 sys.path.insert(0, pkg_dir)
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
116 if verbose: print " Updated sys.path:", sys.path[0]
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
117 for i in range(depth):
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
118 sub_dir = os.path.join(sub_dir, pkg_name)
42337
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
119 pkg_fname = self._add_pkg_dir(sub_dir)
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
120 if verbose: print " Next level in:", sub_dir
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
121 if verbose: print " Created:", pkg_fname
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
122 mod_fname = os.path.join(sub_dir, test_fname)
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
123 mod_file = open(mod_fname, "w")
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
124 mod_file.write(source)
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
125 mod_file.close()
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
126 if verbose: print " Created:", mod_fname
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
127 mod_name = (pkg_name+".")*depth + "runpy_test"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
128 return pkg_dir, mod_fname, mod_name
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
129
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
130 def _del_pkg(self, top, depth, mod_name):
42349
3fe643d62ecc Correctly cleanup sys.modules after executing runpy relative import
Nick Coghlan <ncoghlan@gmail.com>
parents: 42337
diff changeset
131 for entry in list(sys.modules):
3fe643d62ecc Correctly cleanup sys.modules after executing runpy relative import
Nick Coghlan <ncoghlan@gmail.com>
parents: 42337
diff changeset
132 if entry.startswith("__runpy_pkg__"):
37000
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
133 del sys.modules[entry]
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
134 if verbose: print " Removed sys.modules entries"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
135 del sys.path[0]
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
136 if verbose: print " Removed sys.path entry"
36998
451da3a52913 Make test_runpy close all references to test modules before trying to delete the underlying files
Nick Coghlan <ncoghlan@gmail.com>
parents: 36995
diff changeset
137 for root, dirs, files in os.walk(top, topdown=False):
451da3a52913 Make test_runpy close all references to test modules before trying to delete the underlying files
Nick Coghlan <ncoghlan@gmail.com>
parents: 36995
diff changeset
138 for name in files:
37000
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
139 try:
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
140 os.remove(os.path.join(root, name))
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
141 except OSError, ex:
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
142 if verbose: print ex # Persist with cleaning up
36998
451da3a52913 Make test_runpy close all references to test modules before trying to delete the underlying files
Nick Coghlan <ncoghlan@gmail.com>
parents: 36995
diff changeset
143 for name in dirs:
37000
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
144 fullname = os.path.join(root, name)
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
145 try:
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
146 os.rmdir(fullname)
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
147 except OSError, ex:
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
148 if verbose: print ex # Persist with cleaning up
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
149 try:
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
150 os.rmdir(top)
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
151 if verbose: print " Removed package tree"
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
152 except OSError, ex:
86f13301c3db Don't let cleanup errors mask real errors in the runpy tests
Nick Coghlan <ncoghlan@gmail.com>
parents: 36998
diff changeset
153 if verbose: print ex # Persist with cleaning up
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
154
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
155 def _check_module(self, depth):
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
156 pkg_dir, mod_fname, mod_name = (
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
157 self._make_pkg("x=1\n", depth))
42729
2480b864be03 Make test_runpy re-entrant.
Brett Cannon <bcannon@gmail.com>
parents: 42357
diff changeset
158 forget(mod_name)
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
159 try:
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
160 if verbose: print "Running from source:", mod_name
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
161 d1 = run_module(mod_name) # Read from source
42337
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
162 self.failUnless("x" in d1)
36998
451da3a52913 Make test_runpy close all references to test modules before trying to delete the underlying files
Nick Coghlan <ncoghlan@gmail.com>
parents: 36995
diff changeset
163 self.failUnless(d1["x"] == 1)
451da3a52913 Make test_runpy close all references to test modules before trying to delete the underlying files
Nick Coghlan <ncoghlan@gmail.com>
parents: 36995
diff changeset
164 del d1 # Ensure __loader__ entry doesn't keep file open
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
165 __import__(mod_name)
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
166 os.remove(mod_fname)
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
167 if verbose: print "Running from compiled:", mod_name
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
168 d2 = run_module(mod_name) # Read from bytecode
42337
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
169 self.failUnless("x" in d2)
36998
451da3a52913 Make test_runpy close all references to test modules before trying to delete the underlying files
Nick Coghlan <ncoghlan@gmail.com>
parents: 36995
diff changeset
170 self.failUnless(d2["x"] == 1)
451da3a52913 Make test_runpy close all references to test modules before trying to delete the underlying files
Nick Coghlan <ncoghlan@gmail.com>
parents: 36995
diff changeset
171 del d2 # Ensure __loader__ entry doesn't keep file open
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
172 finally:
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
173 self._del_pkg(pkg_dir, depth, mod_name)
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
174 if verbose: print "Module executed successfully"
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
175
44116
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
176 def _add_relative_modules(self, base_dir, source, depth):
42337
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
177 if depth <= 1:
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
178 raise ValueError("Relative module test needs depth > 1")
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
179 pkg_name = "__runpy_pkg__"
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
180 module_dir = base_dir
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
181 for i in range(depth):
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
182 parent_dir = module_dir
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
183 module_dir = os.path.join(module_dir, pkg_name)
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
184 # Add sibling module
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
185 sibling_fname = os.path.join(module_dir, "sibling"+os.extsep+"py")
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
186 sibling_file = open(sibling_fname, "w")
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
187 sibling_file.close()
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
188 if verbose: print " Added sibling module:", sibling_fname
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
189 # Add nephew module
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
190 uncle_dir = os.path.join(parent_dir, "uncle")
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
191 self._add_pkg_dir(uncle_dir)
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
192 if verbose: print " Added uncle package:", uncle_dir
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
193 cousin_dir = os.path.join(uncle_dir, "cousin")
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
194 self._add_pkg_dir(cousin_dir)
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
195 if verbose: print " Added cousin package:", cousin_dir
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
196 nephew_fname = os.path.join(cousin_dir, "nephew"+os.extsep+"py")
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
197 nephew_file = open(nephew_fname, "w")
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
198 nephew_file.close()
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
199 if verbose: print " Added nephew module:", nephew_fname
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
200
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
201 def _check_relative_imports(self, depth, run_name=None):
44116
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
202 contents = r"""\
42337
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
203 from __future__ import absolute_import
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
204 from . import sibling
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
205 from ..uncle.cousin import nephew
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
206 """
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
207 pkg_dir, mod_fname, mod_name = (
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
208 self._make_pkg(contents, depth))
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
209 try:
44116
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
210 self._add_relative_modules(pkg_dir, contents, depth)
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
211 pkg_name = mod_name.rpartition('.')[0]
42337
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
212 if verbose: print "Running from source:", mod_name
44116
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
213 d1 = run_module(mod_name, run_name=run_name) # Read from source
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
214 self.failUnless("__package__" in d1)
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
215 self.failUnless(d1["__package__"] == pkg_name)
42337
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
216 self.failUnless("sibling" in d1)
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
217 self.failUnless("nephew" in d1)
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
218 del d1 # Ensure __loader__ entry doesn't keep file open
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
219 __import__(mod_name)
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
220 os.remove(mod_fname)
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
221 if verbose: print "Running from compiled:", mod_name
44116
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
222 d2 = run_module(mod_name, run_name=run_name) # Read from bytecode
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
223 self.failUnless("__package__" in d2)
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
224 self.failUnless(d2["__package__"] == pkg_name)
42337
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
225 self.failUnless("sibling" in d2)
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
226 self.failUnless("nephew" in d2)
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
227 del d2 # Ensure __loader__ entry doesn't keep file open
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
228 finally:
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
229 self._del_pkg(pkg_dir, depth, mod_name)
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
230 if verbose: print "Module executed successfully"
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
231
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
232 def test_run_module(self):
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
233 for depth in range(4):
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
234 if verbose: print "Testing package depth:", depth
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
235 self._check_module(depth)
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
236
42337
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
237 def test_explicit_relative_import(self):
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
238 for depth in range(2, 5):
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
239 if verbose: print "Testing relative imports at depth:", depth
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
240 self._check_relative_imports(depth)
38d1beb650ba Add explicit relative import tests for runpy.run_module
Nick Coghlan <ncoghlan@gmail.com>
parents: 39022
diff changeset
241
44116
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
242 def test_main_relative_import(self):
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
243 for depth in range(2, 5):
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
244 if verbose: print "Testing main relative imports at depth:", depth
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
245 self._check_relative_imports(depth, "__main__")
803edf9b1dd9 Implement PEP 366
Nick Coghlan <ncoghlan@gmail.com>
parents: 42825
diff changeset
246
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
247
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
248 def test_main():
37003
4f44412e9f6c Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37001
diff changeset
249 run_unittest(RunModuleCodeTest)
4f44412e9f6c Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37001
diff changeset
250 run_unittest(RunModuleTest)
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
251
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
252 if __name__ == "__main__":
37003
4f44412e9f6c Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37001
diff changeset
253 test_main()