[Python-checkins] r56374 - in sandbox/trunk/2to3: tests/support.py tests/test_all_fixers.py tests/test_parser.py

collin.winter python-checkins at python.org
Sat Jul 14 20:23:48 CEST 2007


Author: collin.winter
Date: Sat Jul 14 20:23:48 2007
New Revision: 56374

Modified:
   sandbox/trunk/2to3/   (props changed)
   sandbox/trunk/2to3/tests/support.py
   sandbox/trunk/2to3/tests/test_all_fixers.py
   sandbox/trunk/2to3/tests/test_parser.py
Log:
Create a helper function for tests that use the project's files as input data (fixer and parser tests).


Modified: sandbox/trunk/2to3/tests/support.py
==============================================================================
--- sandbox/trunk/2to3/tests/support.py	(original)
+++ sandbox/trunk/2to3/tests/support.py	Sat Jul 14 20:23:48 2007
@@ -4,6 +4,7 @@
 # Python imports
 import unittest
 import sys
+import os
 import os.path
 import re
 from textwrap import dedent
@@ -15,6 +16,7 @@
 from pgen2 import driver
 
 test_dir = os.path.dirname(__file__)
+proj_dir = os.path.normpath(os.path.join(test_dir, ".."))
 grammar_path = os.path.join(test_dir, "..", "Grammar.txt")
 grammar = driver.load_grammar(grammar_path)
 driver = driver.Driver(grammar, convert=pytree.convert)
@@ -36,4 +38,10 @@
 def reformat(string):
     return dedent(string) + "\n\n"
 
+def all_project_files():
+    for dirpath, dirnames, filenames in os.walk(proj_dir):
+        for filename in filenames:
+            if filename.endswith(".py"):
+                yield os.path.join(dirpath, filename)
+
 TestCase = unittest.TestCase

Modified: sandbox/trunk/2to3/tests/test_all_fixers.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_all_fixers.py	(original)
+++ sandbox/trunk/2to3/tests/test_all_fixers.py	Sat Jul 14 20:23:48 2007
@@ -39,22 +39,10 @@
         self.refactor.refactor_tree(tree, stream_name)
         return str(tree)
 
-    def test_examples_file(self):
-        # Just test that we can parse examples.py without failing
-        basedir = os.path.dirname(refactor.__file__)
-        example = os.path.join(basedir, "example.py")
-        self.refactor_stream("example.py", open(example))
-
-    def test_fixers(self):
-        # Just test that we can parse all the fixers without failing
-        basedir = os.path.dirname(refactor.__file__)
-        fixerdir = os.path.join(basedir, "fixes")
-        for filename in os.listdir(fixerdir):
-            if not filename.endswith(".py"):
-                continue
-            print "Fixing %s..." % filename
-            fixer = os.path.join(fixerdir, filename)
-            self.refactor_stream(fixer, open(fixer))
+    def test_all_project_files(self):
+        for filepath in support.all_project_files():
+            print "Fixing %s..." % filepath
+            self.refactor_stream(filepath, open(filepath))
 
 
 if __name__ == "__main__":

Modified: sandbox/trunk/2to3/tests/test_parser.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_parser.py	(original)
+++ sandbox/trunk/2to3/tests/test_parser.py	Sat Jul 14 20:23:48 2007
@@ -18,17 +18,12 @@
 
     """A cut-down version of pytree_idempotency.py."""
 
-    def test_2to3_files(self):
-        proj_dir = os.path.join(test_dir, "..")
-
-        for dirpath, dirnames, filenames in os.walk(proj_dir):
-            for filename in filenames:
-                if filename.endswith(".py"):
-                    filepath = os.path.join(dirpath, filename)
-                    print "Parsing %s..." % os.path.normpath(filepath)
-                    tree = driver.parse_file(filepath, debug=True)
-                    if diff(filepath, tree):
-                        self.fail("Idempotency failed: %s" % filename)
+    def test_all_project_files(self):
+        for filepath in support.all_project_files():
+            print "Parsing %s..." % filepath
+            tree = driver.parse_file(filepath, debug=True)
+            if diff(filepath, tree):
+                self.fail("Idempotency failed: %s" % filepath)
 
 
 def diff(fn, tree):


More information about the Python-checkins mailing list