[pypy-svn] pypy default: use an Exception to signal match failure
antocuni
commits-noreply at bitbucket.org
Thu Feb 24 18:25:41 CET 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r42265:10fbd717649b
Date: 2011-02-24 16:55 +0100
http://bitbucket.org/pypy/pypy/changeset/10fbd717649b/
Log: use an Exception to signal match failure
diff --git a/pypy/module/pypyjit/test_pypy_c/model.py b/pypy/module/pypyjit/test_pypy_c/model.py
--- a/pypy/module/pypyjit/test_pypy_c/model.py
+++ b/pypy/module/pypyjit/test_pypy_c/model.py
@@ -160,6 +160,8 @@
matcher = OpMatcher(ops)
return matcher.match(expected_src)
+class InvalidMatch(Exception):
+ pass
class OpMatcher(object):
@@ -221,20 +223,30 @@
self.alpha_map[v1] = v2
return self.alpha_map[v1] == v2
+ def _assert(self, cond, message):
+ if not cond:
+ raise InvalidMatch(message)
+
def match_op(self, op, (exp_opname, exp_res, exp_args)):
- assert op.name == exp_opname
+ self._assert(op.name == exp_opname, "operation mismatch")
self.match_var(op.res, exp_res)
- assert len(op.args) == len(exp_args), "wrong number of arguments"
+ self._assert(len(op.args) == len(exp_args), "wrong number of arguments")
for arg, exp_arg in zip(op.args, exp_args):
- assert self.match_var(arg, exp_arg), "variable mismatch"
-
+ self._assert(self.match_var(arg, exp_arg), "variable mismatch")
+
+ def match_loop(self, expected_ops):
+ self._assert(len(self.ops) == len(expected_ops), "wrong number of operations")
+ for op, exp_op in zip(self.ops, expected_ops):
+ self.match_op(op, exp_op)
def match(self, expected_src):
expected_src = self.preprocess_expected_src(expected_src)
- #
expected_ops = self.parse_ops(expected_src)
- assert len(self.ops) == len(expected_ops), "wrong number of operations"
- for op, exp_op in zip(self.ops, expected_ops):
- self.match_op(op, exp_op)
- return True
+ try:
+ self.match_loop(expected_ops)
+ except InvalidMatch:
+ #raise # uncomment this and use py.test --pdb for better debugging
+ return False
+ else:
+ return True
diff --git a/pypy/module/pypyjit/test_pypy_c/test_model.py b/pypy/module/pypyjit/test_pypy_c/test_model.py
--- a/pypy/module/pypyjit/test_pypy_c/test_model.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_model.py
@@ -83,14 +83,10 @@
class TestOpMatcher(object):
def match(self, src1, src2):
- """Wrapper around LoopWithIds.match_ops"""
from pypy.tool.jitlogparser.parser import parse
loop = parse(src1)
matcher = OpMatcher(loop.operations)
- try:
- return matcher.match(src2)
- except AssertionError:
- return False
+ return matcher.match(src2)
def test_match_var(self):
match_var = OpMatcher([]).match_var
@@ -299,7 +295,7 @@
jump(p0, p1, p2, p3, i8)
""")
#
- py.test.raises(AssertionError, loop.match, """
+ assert not loop.match("""
i6 = int_lt(i4, 1003)
guard_true(i6)
i8 = int_add(i5, 1) # variable mismatch
@@ -341,7 +337,7 @@
guard_no_exception()
""")
#
- py.test.raises(AssertionError, loop.match_by_id, 'increment', """
+ assert not loop.match_by_id('increment', """
p12 = call(ConstClass(rbigint.SUB), p4, ConstPtr(ptr11))
guard_no_exception()
""")
More information about the Pypy-commit
mailing list