[Python-checkins] r66782 - in sandbox/trunk/2to3/lib2to3: fixes/fix_getcwdu.py tests/test_fixers.py

benjamin.peterson python-checkins at python.org
Sat Oct 4 09:33:47 CEST 2008


Author: benjamin.peterson
Date: Sat Oct  4 00:51:36 2008
New Revision: 66782

Log:
add Victor Stinner's fixer for os.getcwdu -> os.getcwd #4023

Added:
   sandbox/trunk/2to3/lib2to3/fixes/fix_getcwdu.py   (contents, props changed)
Modified:
   sandbox/trunk/2to3/lib2to3/tests/test_fixers.py

Added: sandbox/trunk/2to3/lib2to3/fixes/fix_getcwdu.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_getcwdu.py	Sat Oct  4 00:51:36 2008
@@ -0,0 +1,18 @@
+"""
+Fixer that changes os.getcwdu() to os.getcwd().
+"""
+# Author: Victor Stinner
+
+# Local imports
+from .. import fixer_base
+from ..fixer_util import Name
+
+class FixGetcwdu(fixer_base.BaseFix):
+
+    PATTERN = """
+              power< 'os' trailer< dot='.' name='getcwdu' > any* >
+              """
+
+    def transform(self, node, results):
+        name = results["name"]
+        name.replace(Name("getcwd", prefix=name.get_prefix()))

Modified: sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_fixers.py	(original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_fixers.py	Sat Oct  4 00:51:36 2008
@@ -3603,6 +3603,67 @@
         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__)


More information about the Python-checkins mailing list