[Python-checkins] r73959 - sandbox/trunk/2to3/lib2to3/tests/test_refactor.py

benjamin.peterson python-checkins at python.org
Sat Jul 11 23:40:08 CEST 2009


Author: benjamin.peterson
Date: Sat Jul 11 23:40:08 2009
New Revision: 73959

Log:
add tests for refactor_dir()

Modified:
   sandbox/trunk/2to3/lib2to3/tests/test_refactor.py

Modified: sandbox/trunk/2to3/lib2to3/tests/test_refactor.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_refactor.py	(original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_refactor.py	Sat Jul 11 23:40:08 2009
@@ -7,6 +7,7 @@
 import operator
 import StringIO
 import tempfile
+import shutil
 import unittest
 
 from lib2to3 import refactor, pygram, fixer_base
@@ -143,6 +144,36 @@
         test_file = os.path.join(FIXER_DIR, "parrot_example.py")
         self.check_file_refactoring(test_file, _DEFAULT_FIXERS)
 
+    def test_refactor_dir(self):
+        def check(structure, expected):
+            def mock_refactor_file(self, f, *args):
+                got.append(f)
+            save_func = refactor.RefactoringTool.refactor_file
+            refactor.RefactoringTool.refactor_file = mock_refactor_file
+            rt = self.rt()
+            got = []
+            dir = tempfile.mkdtemp(prefix="2to3-test_refactor")
+            try:
+                os.mkdir(os.path.join(dir, "a_dir"))
+                for fn in structure:
+                    open(os.path.join(dir, fn), "wb").close()
+                rt.refactor_dir(dir)
+            finally:
+                refactor.RefactoringTool.refactor_file = save_func
+                shutil.rmtree(dir)
+            self.assertEqual(got,
+                             [os.path.join(dir, path) for path in expected])
+        check([], [])
+        tree = ["nothing",
+                "hi.py",
+                ".dumb",
+                ".after.py"]
+        expected = ["hi.py"]
+        check(tree, expected)
+        tree = ["hi.py",
+                "a_dir/stuff.py"]
+        check(tree, tree)
+
     def test_file_encoding(self):
         fn = os.path.join(TEST_DATA_DIR, "different_encoding.py")
         self.check_file_refactoring(fn)


More information about the Python-checkins mailing list