[Python-checkins] r54523 - sandbox/trunk/2to3/tests/support.py sandbox/trunk/2to3/tests/test_grammar.py sandbox/trunk/2to3/tests/test_util.py
collin.winter
python-checkins at python.org
Thu Mar 22 01:31:13 CET 2007
Author: collin.winter
Date: Thu Mar 22 01:31:11 2007
New Revision: 54523
Modified:
sandbox/trunk/2to3/tests/support.py
sandbox/trunk/2to3/tests/test_grammar.py
sandbox/trunk/2to3/tests/test_util.py
Log:
Refactor common parsing code into tests.support.parse_string().
Modified: sandbox/trunk/2to3/tests/support.py
==============================================================================
--- sandbox/trunk/2to3/tests/support.py (original)
+++ sandbox/trunk/2to3/tests/support.py Thu Mar 22 01:31:11 2007
@@ -1,13 +1,26 @@
"""Support code for test_*.py files"""
# Author: Collin Winter
+# Python imports
import unittest
import sys
import os.path
import re
from textwrap import dedent
-TestCase = unittest.TestCase
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
+
+# Local imports
+import pytree
+from pgen2 import driver
+
+test_dir = os.path.dirname(__file__)
+grammar_path = os.path.join(test_dir, "..", "Grammar.txt")
+grammar = driver.load_grammar(grammar_path)
+driver = driver.Driver(grammar, convert=pytree.convert)
+
+def parse_string(string):
+ return driver.parse_string(reformat(string), debug=True)
# Python 2.3's TestSuite is not iter()-able
if sys.version_info < (2, 4):
@@ -23,4 +36,4 @@
def reformat(string):
return dedent(string) + "\n\n"
-sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
+TestCase = unittest.TestCase
Modified: sandbox/trunk/2to3/tests/test_grammar.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_grammar.py (original)
+++ sandbox/trunk/2to3/tests/test_grammar.py Thu Mar 22 01:31:11 2007
@@ -10,23 +10,17 @@
# Testing imports
import support
+from support import driver, test_dir
# Python imports
import os.path
# Local imports
-import pytree
-from pgen2 import driver
from pgen2.parse import ParseError
-test_dir = os.path.dirname(__file__)
-grammar_path = os.path.join(test_dir, "..", "Grammar.txt")
-grammar = driver.load_grammar(grammar_path)
-driver = driver.Driver(grammar, convert=pytree.convert)
-
class GrammarTest(support.TestCase):
def validate(self, code):
- driver.parse_string(support.reformat(code), debug=True)
+ support.parse_string(code)
def invalid_syntax(self, code):
try:
Modified: sandbox/trunk/2to3/tests/test_util.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_util.py (original)
+++ sandbox/trunk/2to3/tests/test_util.py Thu Mar 22 01:31:11 2007
@@ -11,18 +11,11 @@
# Local imports
import pytree
from fixes import util
-from pgen2 import driver
-from pgen2.parse import ParseError
-
-test_dir = os.path.dirname(__file__)
-grammar_path = os.path.join(test_dir, "..", "Grammar.txt")
-grammar = driver.load_grammar(grammar_path)
-driver = driver.Driver(grammar, convert=pytree.convert)
def parse(code):
# The topmost node is file_input, which we don't care about.
# The next-topmost node is a *_stmt node, which we also don't care about
- tree = driver.parse_string(support.reformat(code), debug=True)
+ tree = support.parse_string(code)
node = tree.children[0].children[0]
node.parent = None
return node
More information about the Python-checkins
mailing list