[pypy-svn] r20388 - pypy/branch/somepbc-refactoring/pypy/translator/c/test

arigo at codespeak.net arigo at codespeak.net
Tue Nov 29 13:56:47 CET 2005


Author: arigo
Date: Tue Nov 29 13:56:46 2005
New Revision: 20388

Modified:
   pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_exception.py
Log:
Fixed test_exception, using Yet Another style: grabbing the
getcompiled() method of TestTypedTestCase.



Modified: pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_exception.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_exception.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_exception.py	Tue Nov 29 13:56:46 2005
@@ -1,5 +1,7 @@
 import py
-from pypy.translator.translator import Translator
+from pypy.translator.c.test import test_typed
+
+getcompiled = test_typed.TestTypedTestCase().getcompiled
 
 
 class TestException(Exception):
@@ -16,7 +18,7 @@
             raise MyException()
         else:
             return 3
-    def fn(i):
+    def fn(i=int):
         try:
             a = raise_(i) + 11
             b = raise_(i) + 12
@@ -29,27 +31,19 @@
         except:
             return 22
         return 66
-    t = Translator(fn)
-    t.annotate([int]).simplify()
-    t.specialize()
-    #t.view()
-    f = t.ccompile()
+    f = getcompiled(fn)
     assert f(0) == fn(0)
     assert f(1) == fn(1)
     assert f(2) == fn(2)
 
 def test_implicit_index_error_lists():
-    def fn(n):
+    def fn(n=int):
         lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
         try:
             return lst[n]
         except:
             return 2
-    t = Translator(fn)
-    t.annotate([int]).simplify()
-    t.specialize()
-    #t.view()
-    f = t.ccompile()
+    f = getcompiled(fn)
     assert f(-1) == fn(-1)
     assert f( 0) == fn( 0)
     assert f(10) == fn(10)
@@ -64,25 +58,16 @@
             return 5
         else:
             return 2
-
-    t = Translator(f)
-    t.annotate([]).simplify()
-    t.specialize()
-    #t.view()
-    f1 = t.ccompile()
+    f1 = getcompiled(f)
     assert f1() == 5
 
 def test_raise_outside_testfn():
-    def testfn(n):
+    def testfn(n=int):
         if n < 0:
             raise ValueError("hello")
         else:
             raise MyException("world")
-
-    t = Translator(testfn)
-    t.annotate([int]).simplify()
-    t.specialize()
-    f1 = t.ccompile()
+    f1 = getcompiled(testfn)
     assert py.test.raises(ValueError, f1, -1)
     try:
         f1(1)
@@ -92,17 +77,14 @@
         py.test.fail("f1(1) did not raise anything")
 
 def test_assert():
-    def testfn(n):
+    def testfn(n=int):
         assert n >= 0
 
     # big confusion with py.test's AssertionError handling here...
     # some hacks to try to disable it for the current test.
     saved = no_magic()
     try:
-        t = Translator(testfn)
-        t.annotate([int]).simplify()
-        t.specialize()
-        f1 = t.ccompile()
+        f1 = getcompiled(testfn)
         res = f1(0)
         assert res is None, repr(res)
         res = f1(42)



More information about the Pypy-commit mailing list