[Python-checkins] CVS: python/dist/src/Lib/test test_funcattrs.py,1.6,1.7

Barry Warsaw bwarsaw@users.sourceforge.net
Tue, 14 Aug 2001 11:28:30 -0700


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

Modified Files:
	test_funcattrs.py 
Log Message:
Test the new semantics for setting and deleting a function's __dict__
attribute.  Deleting it, or setting it to a non-dictionary result in a
TypeError.  Note that getting it the first time magically initializes
it to an empty dict so that func.__dict__ will always appear to be a
dictionary (never None).

Closes SF bug #446645.


Index: test_funcattrs.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_funcattrs.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** test_funcattrs.py	2001/02/26 18:07:26	1.6
--- test_funcattrs.py	2001/08/14 18:28:28	1.7
***************
*** 12,22 ****
  try:
      b.publish
! except AttributeError:
!     pass
! else:
!     raise TestFailed, 'expected AttributeError'
  
! if b.__dict__ <> None:
!     raise TestFailed, 'expected unassigned func.__dict__ to be None'
  
  b.publish = 1
--- 12,20 ----
  try:
      b.publish
! except AttributeError: pass
! else: raise TestFailed, 'expected AttributeError'
  
! if b.__dict__ <> {}:
!     raise TestFailed, 'expected unassigned func.__dict__ to be {}'
  
  b.publish = 1
***************
*** 32,44 ****
      raise TestFailed, 'attribute not in dir()'
  
! del b.__dict__
! if b.__dict__ <> None:
!     raise TestFailed, 'del func.__dict__ did not result in __dict__ == None'
  
  b.publish = 1
! b.__dict__ = None
! if b.__dict__ <> None:
!     raise TestFailed, 'func.__dict__ = None did not result in __dict__ == None'
  
  
  f1 = F()
--- 30,50 ----
      raise TestFailed, 'attribute not in dir()'
  
! try:
!     del b.__dict__
! except TypeError: pass
! else: raise TestFailed, 'del func.__dict__ expected TypeError'
  
  b.publish = 1
! try:
!     b.__dict__ = None
! except TypeError: pass
! else: raise TestFailed, 'func.__dict__ = None expected TypeError'
  
+ d = {'hello': 'world'}
+ b.__dict__ = d
+ if b.func_dict is not d:
+     raise TestFailed, 'func.__dict__ assignment to dictionary failed'
+ if b.hello <> 'world':
+     raise TestFailed, 'attribute after func.__dict__ assignment failed'
  
  f1 = F()
***************
*** 47,61 ****
  try:
      F.a.publish
! except AttributeError:
!     pass
! else:
!     raise TestFailed, 'expected AttributeError'
  
  try:
      f1.a.publish
! except AttributeError:
!     pass
! else:
!     raise TestFailed, 'expected AttributeError'
  
  # In Python 2.1 beta 1, we disallowed setting attributes on unbound methods
--- 53,63 ----
  try:
      F.a.publish
! except AttributeError: pass
! else: raise TestFailed, 'expected AttributeError'
  
  try:
      f1.a.publish
! except AttributeError: pass
! else: raise TestFailed, 'expected AttributeError'
  
  # In Python 2.1 beta 1, we disallowed setting attributes on unbound methods
***************
*** 63,70 ****
  try:
      F.a.publish = 1
! except TypeError:
!     pass
! else:
!     raise TestFailed, 'expected TypeError'
  
  # But setting it explicitly on the underlying function object is okay.
--- 65,70 ----
  try:
      F.a.publish = 1
! except TypeError: pass
! else: raise TestFailed, 'expected TypeError'
  
  # But setting it explicitly on the underlying function object is okay.
***************
*** 85,100 ****
  try:
      f1.a.publish = 0
! except TypeError:
!     pass
! else:
!     raise TestFailed, 'expected TypeError'
  
  # See the comment above about the change in semantics for Python 2.1b1
  try:
      F.a.myclass = F
! except TypeError:
!     pass
! else:
!     raise TestFailed, 'expected TypeError'
  
  F.a.im_func.myclass = F
--- 85,96 ----
  try:
      f1.a.publish = 0
! except TypeError: pass
! else: raise TestFailed, 'expected TypeError'
  
  # See the comment above about the change in semantics for Python 2.1b1
  try:
      F.a.myclass = F
! except TypeError: pass
! else: raise TestFailed, 'expected TypeError'
  
  F.a.im_func.myclass = F
***************
*** 106,110 ****
  
  if f1.a.myclass is not f2.a.myclass or \
!    f1.a.myclass is not F.a.myclass:
      raise TestFailed, 'attributes were not the same'
  
--- 102,106 ----
  
  if f1.a.myclass is not f2.a.myclass or \
!        f1.a.myclass is not F.a.myclass:
      raise TestFailed, 'attributes were not the same'
  
***************
*** 112,119 ****
  try:
      F.a.__dict__ = (1, 2, 3)
! except TypeError:
!     pass
! else:
!     raise TestFailed, 'expected TypeError'
  
  F.a.im_func.__dict__ = {'one': 11, 'two': 22, 'three': 33}
--- 108,113 ----
  try:
      F.a.__dict__ = (1, 2, 3)
! except TypeError: pass
! else: raise TestFailed, 'expected TypeError'
  
  F.a.im_func.__dict__ = {'one': 11, 'two': 22, 'three': 33}
***************
*** 127,134 ****
  try:
      F.a.__dict__ = d
! except TypeError:
!     pass
! else:
!     raise TestFailed
  
  if f2.a.one <> f1.a.one <> F.a.one <> 11:
--- 121,126 ----
  try:
      F.a.__dict__ = d
! except TypeError: pass
! else: raise TestFailed
  
  if f2.a.one <> f1.a.one <> F.a.one <> 11:
***************
*** 176,184 ****
  def another():
      pass
- del another.__dict__
- del another.func_dict
- another.func_dict = None
  
  try:
      del another.bar
  except AttributeError: pass
--- 168,188 ----
  def another():
      pass
  
  try:
+     del another.__dict__
+ except TypeError: pass
+ else: raise TestFailed
+ 
+ try:
+     del another.func_dict
+ except TypeError: pass
+ else: raise TestFailed
+ 
+ try:
+     another.func_dict = None
+ except TypeError: pass
+ else: raise TestFailed
+ 
+ try:
      del another.bar
  except AttributeError: pass
***************
*** 198,202 ****
      print 1
  
! if foo==bar: raise TestFailed
  
  d={}
--- 202,207 ----
      print 1
  
! if foo==bar:
!     raise TestFailed
  
  d={}