[Python-checkins] python/dist/src/Lib/test test_descr.py,1.181,1.182

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Tue, 11 Feb 2003 19:30:37 -0800


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv26151/Lib/test

Modified Files:
	test_descr.py 
Log Message:
SF #532767: isinstance(x, X) should work when x is a proxy for an X
instance, as long as x.__class__ is X or a subclass thereof.
Did a little cleanup of PyObject_IsInstance() too.


Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.181
retrieving revision 1.182
diff -C2 -d -r1.181 -r1.182
*** test_descr.py	11 Feb 2003 18:44:42 -0000	1.181
--- test_descr.py	12 Feb 2003 03:30:34 -0000	1.182
***************
*** 3736,3740 ****
  def meth_class_get():
      # Full coverage of descrobject.c::classmethod_get()
!     if verbose: print "Testing __get__ method of METH_CLASS C methods..."
      # Baseline
      arg = [1, 2, 3]
--- 3736,3741 ----
  def meth_class_get():
      # Full coverage of descrobject.c::classmethod_get()
!     if verbose:
!         print "Testing __get__ method of METH_CLASS C methods..."
      # Baseline
      arg = [1, 2, 3]
***************
*** 3773,3776 ****
--- 3774,3803 ----
          raise TestFailed, "shouldn't have allowed descr.__get__(None, int)"
  
+ def isinst_isclass():
+     if verbose:
+         print "Testing proxy isinstance() and isclass()..."
+     class Proxy(object):
+         def __init__(self, obj):
+             self.__obj = obj
+         def __getattribute__(self, name):
+             if name.startswith("_Proxy__"):
+                 return object.__getattribute__(self, name)
+             else:
+                 return getattr(self.__obj, name)
+     # Test with a classic class
+     class C:
+         pass
+     a = C()
+     pa = Proxy(a)
+     verify(isinstance(a, C))  # Baseline
+     verify(isinstance(pa, C)) # Test
+     # Test with a new-style class
+     class C(object):
+         pass
+     a = C()
+     pa = Proxy(a)
+     verify(isinstance(a, C))  # Baseline
+     verify(isinstance(pa, C)) # Test
+ 
  
  def test_main():
***************
*** 3860,3863 ****
--- 3887,3891 ----
      dict_type_with_metaclass()
      meth_class_get()
+     isinst_isclass()
  
      if verbose: print "All OK"