[pypy-svn] rev 839 - in pypy/trunk/src/pypy: appspace/test interpreter

rocco at codespeak.net rocco at codespeak.net
Fri Jun 20 05:02:56 CEST 2003


Author: rocco
Date: Fri Jun 20 05:02:56 2003
New Revision: 839

Modified:
   pypy/trunk/src/pypy/appspace/test/test_exceptcomp.py
   pypy/trunk/src/pypy/interpreter/baseobjspace.py
Log:
Update test_exceptcomp.py to use new app-level testing conventions and fix exception matching in nested tuples.

Modified: pypy/trunk/src/pypy/appspace/test/test_exceptcomp.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/test/test_exceptcomp.py	(original)
+++ pypy/trunk/src/pypy/appspace/test/test_exceptcomp.py	Fri Jun 20 05:02:56 2003
@@ -3,35 +3,37 @@
 New for PyPy - Could be incorporated into CPython regression tests.
 """
 import autopath
-
-import unittest
 from pypy.tool import test
 
-class TestExceptionComp(test.TestCase):
+class TestExceptionComp(test.AppTestCase):
 
-    def test_string(self):
-        string = "string"
-        try:
-            raise string
-        except string:
-            pass
-        except:
-            self.fail("Identical string exceptions do not match.") 
+    def setUp(self):
+        self.space = test.objspace()
 
-    def test_stringfail(self):
-        string1 = "string1"
-        string1_ = "string" + "1"
-        assert string1 is not string1_
-        try:
-            raise string1
-        except "string2":
-            self.fail("Different string exceptions match.") 
-        except string1_:
-            self.fail("Non Identical string exceptions match.")
-        except string1:
-            pass
-        except:
-            self.fail("Unknown value for variable raise.")
+### XXX - String exceptions depreciated?
+##    def test_string(self):
+##        string = "string"
+##        try:
+##            raise string
+##        except string:
+##            pass
+##        except:
+##            self.fail("Identical string exceptions do not match.") 
+##
+##    def test_stringfail(self):
+##        string1 = "string1"
+##        string1_ = "string" + "1"
+##        assert string1 is not string1_
+##        try:
+##            raise string1
+##        except "string2":
+##            self.fail("Different string exceptions match.") 
+##        except string1_:
+##            self.fail("Non Identical string exceptions match.")
+##        except string1:
+##            pass
+##        except:
+##            self.fail("Unknown value for variable raise.")
             
 
     def test_exception(self):
@@ -122,5 +124,15 @@
         except:
             self.fail("Exception does not match self in nested tuple.") 
 
+    def test_deeptuples(self):
+        try:
+            raise IOError
+        except (FloatingPointError,(OSError,
+                                    (SyntaxError,IOError,ZeroDivisionError)),
+                (MemoryError, NotImplementedError)):
+            pass
+        except:
+            self.fail("Exception does not match self in deeply nested tuple.")
+            
 if __name__ == "__main__":
     test.main()

Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/trunk/src/pypy/interpreter/baseobjspace.py	Fri Jun 20 05:02:56 2003
@@ -116,28 +116,22 @@
 
     def exception_match(self, w_exc_type, w_check_class):
         """Checks if the given exception type matches 'w_check_class'."""
-        #Match identical items.
-        w_rv = self.is_(w_exc_type, w_check_class)
-        if self.is_true(w_rv):
-            return w_rv
-        #Match subclasses.
-        try:
-            w_rv = self.issubtype(w_exc_type, w_check_class)
-        except: pass
-        else:
-            if self.is_true(w_rv):
-                return w_rv
-        #Match tuples containing identical or parent classes
-        try:
-            exclst = self.unpackiterable(w_check_class)
-        except:
-            #w_check_class is not iterable
-            return self.w_False
-        #w_check_class is iterable
-        for w_item in exclst:
+        check_list = [w_check_class]
+        while check_list:
+            w_item = check_list.pop()
+            #Test within iterables (i.e. tuples)
+            try:
+                exclst = self.unpackiterable(w_item)
+                check_list.extend(exclst)
+            except:
+                #w_check_class is not iterable
+                pass
+            #w_item should now be an Exception (or string?)
+            #Match identical items.
             w_rv = self.is_(w_exc_type, w_item)
             if self.is_true(w_rv):
                 return w_rv
+            #Match subclasses.
             try:
                 w_rv = self.issubtype(w_exc_type, w_item)
             except: pass


More information about the Pypy-commit mailing list