summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid Beazley <dave@dabeaz.com>2013-05-21 20:14:04 -0500
committerDavid Beazley <dave@dabeaz.com>2013-05-21 20:14:04 -0500
commit37a9c85897de1704a29878b4b949b0c3fa676ef8 (patch)
treeae99ae96ab12a0105155912b329ad7768d7446ad /test
parentea6129fd53ce0b7161dc274ff002642b69f035a1 (diff)
downloadply-37a9c85897de1704a29878b4b949b0c3fa676ef8.tar.gz
Fixed yacc tests to account for dict hash key randomization
Diffstat (limited to 'test')
-rwxr-xr-xtest/testlex.py3
-rw-r--r--test/testyacc.py24
-rw-r--r--test/yacc_prec1.py4
3 files changed, 24 insertions, 7 deletions
diff --git a/test/testlex.py b/test/testlex.py
index 1f7dd1b..e436781 100755
--- a/test/testlex.py
+++ b/test/testlex.py
@@ -34,7 +34,7 @@ def pymodule_out_exists(filename):
def pymodule_out_remove(filename):
os.remove(make_pymodule_path(filename))
-def check_expected(result,expected):
+def check_expected(result, expected):
if sys.version_info[0] >= 3:
if isinstance(result,str):
result = result.encode('ascii')
@@ -43,7 +43,6 @@ def check_expected(result,expected):
resultlines = result.splitlines()
expectedlines = expected.splitlines()
-
if len(resultlines) != len(expectedlines):
return False
diff --git a/test/testyacc.py b/test/testyacc.py
index 1a98b4f..4329d3b 100644
--- a/test/testyacc.py
+++ b/test/testyacc.py
@@ -34,7 +34,7 @@ def pymodule_out_exists(filename):
def pymodule_out_remove(filename):
os.remove(make_pymodule_path(filename))
-
+# Old implementation (not safe for Python 3.3)
def check_expected(result,expected):
resultlines = []
for line in result.splitlines():
@@ -52,6 +52,26 @@ def check_expected(result,expected):
return False
return True
+# Check the output to see if it contains all of a set of expected output lines.
+# This alternate implementation looks weird, but is needed to properly handle
+# some variations in error message order that occurs due to dict hash table
+# randomization that was introduced in Python 3.3
+def check_expected(result, expected):
+ resultlines = set()
+ for line in result.splitlines():
+ if line.startswith("WARNING: "):
+ line = line[9:]
+ elif line.startswith("ERROR: "):
+ line = line[7:]
+ resultlines.add(line)
+
+ # Selectively remove expected lines from the output
+ for eline in expected.splitlines():
+ resultlines = set(line for line in resultlines if not line.endswith(eline))
+
+ # Return True if no result lines remain
+ return not bool(resultlines)
+
def run_import(module):
code = "import "+module
exec(code)
@@ -371,6 +391,4 @@ class YaccErrorWarningTests(unittest.TestCase):
"Precedence rule 'left' defined for unknown symbol '/'\n"
))
-
-
unittest.main()
diff --git a/test/yacc_prec1.py b/test/yacc_prec1.py
index 2ca6afc..99fcd90 100644
--- a/test/yacc_prec1.py
+++ b/test/yacc_prec1.py
@@ -12,8 +12,8 @@ from calclex import tokens
# Parsing rules
precedence = (
- ('left','+','-'),
- ('left','*','/'),
+ ('left', '+', '-'),
+ ('left', '*', '/'),
('right','UMINUS'),
)