diff options
| author | Benjamin Peterson <benjamin@python.org> | 2008-10-04 21:33:08 (GMT) |
|---|---|---|
| committer | Benjamin Peterson <benjamin@python.org> | 2008-10-04 21:33:08 (GMT) |
| commit | be2c0a9fe3fc77ed185dbeff569abf8b4ee39516 (patch) | |
| tree | 72f56bd5bcbd576544cbe1ae8581a6de9e597a2f /Lib/lib2to3/tests/test_fixers.py | |
| parent | 81f66f3c650ac84f1eaba6d8dc118e9d96fd8ff2 (diff) | |
| download | cpython-be2c0a9fe3fc77ed185dbeff569abf8b4ee39516.zip cpython-be2c0a9fe3fc77ed185dbeff569abf8b4ee39516.tar.gz cpython-be2c0a9fe3fc77ed185dbeff569abf8b4ee39516.tar.bz2 | |
Merged revisions 66766-66767,66771-66772,66774,66776,66783-66787,66790,66793,66797 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r66766 | benjamin.peterson | 2008-10-03 06:52:06 -0500 (Fri, 03 Oct 2008) | 1 line
update the mac installer script
................
r66767 | andrew.kuchling | 2008-10-03 07:26:42 -0500 (Fri, 03 Oct 2008) | 1 line
Docstring typo.
................
r66771 | hirokazu.yamamoto | 2008-10-03 11:18:42 -0500 (Fri, 03 Oct 2008) | 2 lines
Fixed following error when DocXMLRPCServer failed.
UnboundLocalError: local variable 'serv' referenced before assignment
................
r66772 | andrew.kuchling | 2008-10-03 11:29:19 -0500 (Fri, 03 Oct 2008) | 1 line
Mention exception in docstring
................
r66774 | andrew.kuchling | 2008-10-03 11:42:52 -0500 (Fri, 03 Oct 2008) | 1 line
Typo fix
................
r66776 | hirokazu.yamamoto | 2008-10-03 12:34:49 -0500 (Fri, 03 Oct 2008) | 2 lines
Issue #1706863: Fixed "'NoneType' object has no attribute 'rfind'" error when sqlite libfile not found.
................
r66783 | andrew.kuchling | 2008-10-03 20:02:29 -0500 (Fri, 03 Oct 2008) | 1 line
Use correct capitalization of NaN
................
r66784 | andrew.kuchling | 2008-10-03 20:03:42 -0500 (Fri, 03 Oct 2008) | 1 line
Docstring change: Specify exception raised
................
r66785 | andrew.kuchling | 2008-10-03 20:04:24 -0500 (Fri, 03 Oct 2008) | 1 line
Docstring changes: Specify exceptions raised
................
r66786 | andrew.kuchling | 2008-10-03 20:05:56 -0500 (Fri, 03 Oct 2008) | 3 lines
Docstring change for *partition: use same tense as other docstrings.
Hyphenate left- and right-justified.
Fix 'registerd' typo
................
r66787 | andrew.kuchling | 2008-10-03 22:08:56 -0500 (Fri, 03 Oct 2008) | 1 line
two corrections
................
r66790 | andrew.kuchling | 2008-10-04 11:52:01 -0500 (Sat, 04 Oct 2008) | 1 line
Set svn:keywords
................
r66793 | georg.brandl | 2008-10-04 13:26:01 -0500 (Sat, 04 Oct 2008) | 2 lines
#4041: don't refer to removed and outdated modules.
................
r66797 | benjamin.peterson | 2008-10-04 15:55:50 -0500 (Sat, 04 Oct 2008) | 19 lines
Merged revisions 66707,66775,66782 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r66707 | benjamin.peterson | 2008-09-30 18:27:10 -0500 (Tue, 30 Sep 2008) | 1 line
fix #4001: fix_imports didn't check for __init__.py before converting to relative imports
........
r66775 | collin.winter | 2008-10-03 12:08:26 -0500 (Fri, 03 Oct 2008) | 4 lines
Add an alternative iterative pattern matching system that, while slower, correctly parses files that cause the faster recursive pattern matcher to fail with a recursion error. lib2to3 falls back to the iterative matcher if the recursive one fails.
Fixes http://bugs.python.org/issue2532. Thanks to Nick Edds.
........
r66782 | benjamin.peterson | 2008-10-03 17:51:36 -0500 (Fri, 03 Oct 2008) | 1 line
add Victor Stinner's fixer for os.getcwdu -> os.getcwd #4023
........
................
Diffstat (limited to 'Lib/lib2to3/tests/test_fixers.py')
| -rwxr-xr-x | Lib/lib2to3/tests/test_fixers.py | 103 |
1 files changed, 96 insertions, 7 deletions
diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py index e62e0f9..705b04e 100755 --- a/Lib/lib2to3/tests/test_fixers.py +++ b/Lib/lib2to3/tests/test_fixers.py @@ -9,10 +9,10 @@ except ImportError: import support # Python imports +import os import unittest from itertools import chain from operator import itemgetter -from os.path import dirname, pathsep # Local imports from .. import pygram @@ -3274,14 +3274,19 @@ class Test_import(FixerTestCase): # Need to replace fix_import's exists method # so we can check that it's doing the right thing self.files_checked = [] + self.present_files = set() self.always_exists = True def fake_exists(name): self.files_checked.append(name) - return self.always_exists + return self.always_exists or (name in self.present_files) from ..fixes import fix_import fix_import.exists = fake_exists + def tearDown(self): + from lib2to3.fixes import fix_import + fix_import.exists = os.path.exists + def check_both(self, b, a): self.always_exists = True FixerTestCase.check(self, b, a) @@ -3291,10 +3296,12 @@ class Test_import(FixerTestCase): def test_files_checked(self): def p(path): # Takes a unix path and returns a path with correct separators - return pathsep.join(path.split("/")) + return os.path.pathsep.join(path.split("/")) self.always_exists = False - expected_extensions = ('.py', pathsep, '.pyc', '.so', '.sl', '.pyd') + self.present_files = set(['__init__.py']) + expected_extensions = ('.py', os.path.pathsep, '.pyc', '.so', + '.sl', '.pyd') names_to_test = (p("/spam/eggs.py"), "ni.py", p("../../shrubbery.py")) for name in names_to_test: @@ -3302,11 +3309,32 @@ class Test_import(FixerTestCase): self.filename = name self.unchanged("import jam") - if dirname(name): name = dirname(name) + '/jam' - else: name = 'jam' + if os.path.dirname(name): + name = os.path.dirname(name) + '/jam' + else: + name = 'jam' expected_checks = set(name + ext for ext in expected_extensions) + expected_checks.add("__init__.py") + + self.assertEqual(set(self.files_checked), expected_checks) - self.failUnlessEqual(set(self.files_checked), expected_checks) + def test_not_in_package(self): + s = "import bar" + self.always_exists = False + self.present_files = set(["bar.py"]) + self.unchanged(s) + + def test_in_package(self): + b = "import bar" + a = "from . import bar" + self.always_exists = False + self.present_files = set(["__init__.py", "bar.py"]) + self.check(b, a) + + def test_comments_and_indent(self): + b = "import bar # Foo" + a = "from . import bar # Foo" + self.check(b, a) def test_from(self): b = "from foo import bar, baz" @@ -3577,6 +3605,67 @@ class Test_metaclass(FixerTestCase): self.check(b, a) +class Test_getcwdu(FixerTestCase): + + fixer = 'getcwdu' + + def test_basic(self): + b = """os.getcwdu""" + a = """os.getcwd""" + self.check(b, a) + + b = """os.getcwdu()""" + a = """os.getcwd()""" + self.check(b, a) + + b = """meth = os.getcwdu""" + a = """meth = os.getcwd""" + self.check(b, a) + + b = """os.getcwdu(args)""" + a = """os.getcwd(args)""" + self.check(b, a) + + def test_comment(self): + b = """os.getcwdu() # Foo""" + a = """os.getcwd() # Foo""" + self.check(b, a) + + def test_unchanged(self): + s = """os.getcwd()""" + self.unchanged(s) + + s = """getcwdu()""" + self.unchanged(s) + + s = """os.getcwdb()""" + self.unchanged(s) + + def test_indentation(self): + b = """ + if 1: + os.getcwdu() + """ + a = """ + if 1: + os.getcwd() + """ + self.check(b, a) + + def test_multilation(self): + b = """os .getcwdu()""" + a = """os .getcwd()""" + self.check(b, a) + + b = """os. getcwdu""" + a = """os. getcwd""" + self.check(b, a) + + b = """os.getcwdu ( )""" + a = """os.getcwd ( )""" + self.check(b, a) + + if __name__ == "__main__": import __main__ support.run_all_tests(__main__) |
