[pypy-commit] pypy default: Add 2 tests for patterns found in PyPy code
rlamy
noreply at buildbot.pypy.org
Tue Mar 24 20:11:42 CET 2015
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch:
Changeset: r76543:84912eddc058
Date: 2015-03-24 19:12 +0000
http://bitbucket.org/pypy/pypy/changeset/84912eddc058/
Log: Add 2 tests for patterns found in PyPy code
diff --git a/rpython/translator/c/test/test_exception.py b/rpython/translator/c/test/test_exception.py
--- a/rpython/translator/c/test/test_exception.py
+++ b/rpython/translator/c/test/test_exception.py
@@ -3,6 +3,7 @@
from rpython.translator.c.test import test_typed
from rpython.translator.c.test import test_backendoptimized
from rpython.rtyper.lltypesystem import lltype
+from rpython.rlib.rarithmetic import ovfcheck
getcompiled = test_typed.TestTypedTestCase().getcompiled
getcompiledopt = test_backendoptimized.TestTypedOptimizedTestCase().getcompiled
@@ -28,9 +29,9 @@
b = raise_(i) + 12
c = raise_(i) + 13
return a+b+c
- except TestException:
+ except TestException:
return 7
- except MyException:
+ except MyException:
return 123
except:
return 22
@@ -173,3 +174,41 @@
f1 = getcompiledopt(fn, [int])
res = f1(100)
assert res == 42
+
+def test_getitem_custom_exception():
+ class MyError(Exception):
+ pass
+ class BadContainer(object):
+ def __getitem__(self, n):
+ raise MyError
+ def f():
+ d = BadContainer()
+ try:
+ return d[0]
+ except KeyError:
+ return 1
+ def g():
+ try:
+ return f()
+ except MyError:
+ return -1
+
+ assert g() == -1
+ compiled = getcompiled(g, [])
+ assert compiled() == -1
+
+def test_ovf_propagation():
+ def div(a, b):
+ try:
+ return ovfcheck(a//b)
+ except ZeroDivisionError:
+ raise
+ def f():
+ div(4, 2)
+ try:
+ return div(-sys.maxint-1, -1)
+ except OverflowError:
+ return 0
+ assert f() == 0
+ compiled = getcompiled(f, [])
+ assert compiled() == 0
More information about the pypy-commit
mailing list