[pypy-svn] r41164 - in pypy/dist/pypy: lib objspace/std/test

ac at codespeak.net ac at codespeak.net
Fri Mar 23 13:39:55 CET 2007


Author: ac
Date: Fri Mar 23 13:39:54 2007
New Revision: 41164

Modified:
   pypy/dist/pypy/lib/_classobj.py
   pypy/dist/pypy/objspace/std/test/test_index.py
Log:
Add test abount non-existing __index__ method.
Fix tests to really test oldstyle classes.
Fix a bug in oldstyle classes



Modified: pypy/dist/pypy/lib/_classobj.py
==============================================================================
--- pypy/dist/pypy/lib/_classobj.py	(original)
+++ pypy/dist/pypy/lib/_classobj.py	Fri Mar 23 13:39:54 2007
@@ -404,7 +404,7 @@
         if func:
             return func()
         else:
-            raise AttributeError('object cannot be interpreted as an index')
+            raise TypeError('object cannot be interpreted as an index')
 
 
     # coerce

Modified: pypy/dist/pypy/objspace/std/test/test_index.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_index.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_index.py	Fri Mar 23 13:39:54 2007
@@ -1,7 +1,9 @@
 from py.test import raises
+from pypy.conftest import gettestobjspace
 
 class AppTest_IndexProtocol:
     def setup_class(self):
+        self.space = gettestobjspace(oldstyle=True)
         w_oldstyle = self.space.appexec([], """():
             class oldstyle:
                 def __index__(self):
@@ -14,6 +16,16 @@
                     return self.ind
             return newstyle""")
 
+        w_oldstyle_no_index = self.space.appexec([], """():
+            class oldstyle_no_index:
+                pass
+            return oldstyle_no_index""")
+
+        w_newstyle_no_index = self.space.appexec([], """():
+            class newstyle_no_index(object):
+                pass
+            return newstyle_no_index""")
+
         w_TrapInt = self.space.appexec([], """(): 
             class TrapInt(int):
                 def __index__(self):
@@ -28,8 +40,10 @@
 
         self.w_oldstyle = w_oldstyle
         self.w_o = self.space.call_function(w_oldstyle)
+        self.w_o_no_index = self.space.call_function(w_oldstyle_no_index)
         self.w_newstyle = w_newstyle
         self.w_n = self.space.call_function(w_newstyle)
+        self.w_n_no_index = self.space.call_function(w_newstyle_no_index)
 
         self.w_TrapInt = w_TrapInt
         self.w_TrapLong = w_TrapLong
@@ -40,6 +54,8 @@
         import operator
         assert operator.index(self.o) == -2
         assert operator.index(self.n) == 2
+        raises(TypeError, operator.index, self.o_no_index) 
+        raises(TypeError, operator.index, self.n_no_index) 
 
     def test_slice(self):
         self.o.ind = 1



More information about the Pypy-commit mailing list