diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-09-25 15:53:30 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-09-25 15:53:30 (GMT) |
commit | 3331a20464d7018e8e0b0f7710690dd1575be3b6 (patch) | |
tree | 79f345d27b7ed52abd0c7beaf8494b2594bdb5f8 /Lib | |
parent | 8b7ebafe6597b130463a684795109a6ef38e3eb6 (diff) | |
parent | 1654d74e9a6250491bfb923424c4cf83af2af7a6 (diff) | |
download | cpython-3331a20464d7018e8e0b0f7710690dd1575be3b6.zip cpython-3331a20464d7018e8e0b0f7710690dd1575be3b6.tar.gz cpython-3331a20464d7018e8e0b0f7710690dd1575be3b6.tar.bz2 |
merge 3.2
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/lib2to3/fixer_util.py | 4 | ||||
-rw-r--r-- | Lib/lib2to3/refactor.py | 2 | ||||
-rw-r--r-- | Lib/test/test_compileall.py | 16 |
3 files changed, 15 insertions, 7 deletions
diff --git a/Lib/lib2to3/fixer_util.py b/Lib/lib2to3/fixer_util.py index 92f0da9..2b5bb1d 100644 --- a/Lib/lib2to3/fixer_util.py +++ b/Lib/lib2to3/fixer_util.py @@ -274,9 +274,9 @@ def find_root(node): """Find the top level namespace.""" # Scamper up to the top level namespace while node.type != syms.file_input: - assert node.parent, "Tree is insane! root found before "\ - "file_input node was found." node = node.parent + if not node: + raise ValueError("root found before file_input node was found.") return node def does_tree_import(package, name, node): diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py index 1e85810..201e193 100644 --- a/Lib/lib2to3/refactor.py +++ b/Lib/lib2to3/refactor.py @@ -445,7 +445,7 @@ class RefactoringTool(object): try: find_root(node) - except AssertionError: + except ValueError: # this node has been cut off from a # previous transformation ; skip continue diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py index 6ec105c..ba9fe46 100644 --- a/Lib/test/test_compileall.py +++ b/Lib/test/test_compileall.py @@ -134,15 +134,21 @@ class EncodingTest(unittest.TestCase): class CommandLineTests(unittest.TestCase): """Test compileall's CLI.""" + def _get_run_args(self, args): + interp_args = ['-S'] + if sys.flags.optimize: + interp_args.append({1 : '-O', 2 : '-OO'}[sys.flags.optimize]) + return interp_args + ['-m', 'compileall'] + list(args) + def assertRunOK(self, *args, **env_vars): rc, out, err = script_helper.assert_python_ok( - '-S', '-m', 'compileall', *args, **env_vars) + *self._get_run_args(args), **env_vars) self.assertEqual(b'', err) return out def assertRunNotOK(self, *args, **env_vars): rc, out, err = script_helper.assert_python_failure( - '-S', '-m', 'compileall', *args, **env_vars) + *self._get_run_args(args), **env_vars) return rc, out, err def assertCompiled(self, fn): @@ -198,7 +204,9 @@ class CommandLineTests(unittest.TestCase): self.assertRunOK('-b', '-q', self.pkgdir) # Verify the __pycache__ directory contents. self.assertFalse(os.path.exists(self.pkgdir_cachedir)) - expected = sorted(['__init__.py', '__init__.pyc', 'bar.py', 'bar.pyc']) + opt = 'c' if __debug__ else 'o' + expected = sorted(['__init__.py', '__init__.py' + opt, 'bar.py', + 'bar.py' + opt]) self.assertEqual(sorted(os.listdir(self.pkgdir)), expected) def test_multiple_runs(self): @@ -326,7 +334,7 @@ class CommandLineTests(unittest.TestCase): f2 = script_helper.make_script(self.pkgdir, 'f2', '') f3 = script_helper.make_script(self.pkgdir, 'f3', '') f4 = script_helper.make_script(self.pkgdir, 'f4', '') - p = script_helper.spawn_python('-m', 'compileall', '-i', '-') + p = script_helper.spawn_python(*(self._get_run_args(()) + ['-i', '-'])) p.stdin.write((f3+os.linesep).encode('ascii')) script_helper.kill_python(p) self.assertNotCompiled(f1) |