summaryrefslogtreecommitdiff
path: root/test/testyacc.py
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/testyacc.py
parentea6129fd53ce0b7161dc274ff002642b69f035a1 (diff)
downloadply-37a9c85897de1704a29878b4b949b0c3fa676ef8.tar.gz
Fixed yacc tests to account for dict hash key randomization
Diffstat (limited to 'test/testyacc.py')
-rw-r--r--test/testyacc.py24
1 files changed, 21 insertions, 3 deletions
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()