[pypy-commit] pypy kill-someobject: Fix test_exception. Adds a general way to expect fatal RPython errors.

arigo noreply at buildbot.pypy.org
Wed Oct 10 11:51:59 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: kill-someobject
Changeset: r57968:b11c05a74ff1
Date: 2012-10-10 11:51 +0200
http://bitbucket.org/pypy/pypy/changeset/b11c05a74ff1/

Log:	Fix test_exception. Adds a general way to expect fatal RPython
	errors.

diff --git a/pypy/translator/c/test/test_exception.py b/pypy/translator/c/test/test_exception.py
--- a/pypy/translator/c/test/test_exception.py
+++ b/pypy/translator/c/test/test_exception.py
@@ -62,23 +62,20 @@
             return 5
         else:
             return 2
-    f1 = getcompiled(f)
+    f1 = getcompiled(f, [])
     assert f1() == 5
 
 def test_raise_outside_testfn():
     def testfn(n):
         if n < 0:
             raise ValueError("hello")
+        elif n > 0:
+            raise MyException("world")
         else:
-            raise MyException("world")
+            return 0
     f1 = getcompiled(testfn, [int])
-    assert py.test.raises(ValueError, f1, -1)
-    try:
-        f1(1)
-    except Exception, e:
-        assert str(e) == 'MyException'   # which is genc's best effort
-    else:
-        py.test.fail("f1(1) did not raise anything")
+    f1(-1, expected_exception_name='ValueError')
+    f1(1, expected_exception_name='MyException')
 
 def test_memoryerror():
     # in rev 30717 this test causes a segfault on some Linux, but usually
@@ -113,7 +110,7 @@
     assert f1(10) == 42
     assert f1(sys.maxint) == 1000
     for i in range(20):
-        assert f1((sys.maxint+1) // 2 - i) == 1000
+        assert f1(int((sys.maxint+1) // 2 - i)) == 1000
     assert f1(sys.maxint // 2 - 16384) == 1000
     assert f1(sys.maxint // 2 + 16384) == 1000
 
@@ -126,11 +123,7 @@
     assert res is None, repr(res)
     res = f1(42)
     assert res is None, repr(res)
-    e = py.test.raises(Exception, f1, -2)
-    assert e.type.__name__ == 'AssertionError'
-    # ^^^ indirection, because we really want
-    # the original AssertionError and not the
-    # one patched by the py lib
+    f1(-2, expected_exception_name='AssertionError')
 
 
 def test_reraise_exception():
diff --git a/pypy/translator/c/test/test_genc.py b/pypy/translator/c/test/test_genc.py
--- a/pypy/translator/c/test/test_genc.py
+++ b/pypy/translator/c/test/test_genc.py
@@ -93,16 +93,24 @@
         pass
 
     def f(*args, **kwds):
-        if 'expected_extra_mallocs' in kwds:
-            expected_extra_mallocs = kwds.pop('expected_extra_mallocs')
-        else:
-            expected_extra_mallocs = 0
+        expected_extra_mallocs = kwds.pop('expected_extra_mallocs', 0)
+        expected_exception_name = kwds.pop('expected_exception_name', None)
         assert not kwds
         assert len(args) == len(argtypes)
         for arg, argtype in zip(args, argtypes):
             assert isinstance(arg, argtype)
-        stdout = t.driver.cbuilder.cmdexec(" ".join([llrepr_in(arg) for arg in args]))
+
+        stdout = t.driver.cbuilder.cmdexec(
+            " ".join([llrepr_in(arg) for arg in args]),
+            expect_crash=(expected_exception_name is not None))
         print stdout
+        if expected_exception_name is not None:
+            stdout, stderr = stdout
+            stderr, lastline, empty = stderr.rsplit('\n', 2)
+            assert empty == ''
+            assert lastline == ('Fatal RPython error: ' +
+                                expected_exception_name)
+            return None
         stdout, lastline, empty = stdout.rsplit('\n', 2)
         assert empty == ''
         assert lastline.startswith('MALLOC COUNTERS: ')


More information about the pypy-commit mailing list