[Python-checkins] CVS: python/dist/src/Lib/test test_funcattrs.py,1.5,1.6
Barry Warsaw
bwarsaw@users.sourceforge.net
Mon, 26 Feb 2001 10:07:28 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv24765
Modified Files:
test_funcattrs.py
Log Message:
Additional tests for current, PEP described semantics:
- func.__dict__ is None until the first attribute is assigned
- del func.__dict__ is equivalent to func.__dict__ = None
- disallowing assignment to function attribute through unbound method
(it was always illegal to assign through bound method).
- verifying that setting attribute explicitly on underlying function
via meth.im_func is okay.
Index: test_funcattrs.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_funcattrs.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** test_funcattrs.py 2001/02/09 20:17:14 1.5
--- test_funcattrs.py 2001/02/26 18:07:26 1.6
***************
*** 17,20 ****
--- 17,23 ----
raise TestFailed, 'expected AttributeError'
+ if b.__dict__ <> None:
+ raise TestFailed, 'expected unassigned func.__dict__ to be None'
+
b.publish = 1
if b.publish <> 1:
***************
*** 29,32 ****
--- 32,45 ----
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()
f2 = F()
***************
*** 46,51 ****
raise TestFailed, 'expected AttributeError'
! F.a.publish = 1
if F.a.publish <> 1:
raise TestFailed, 'unbound method attribute not set to expected value'
--- 59,74 ----
raise TestFailed, 'expected AttributeError'
+ # In Python 2.1 beta 1, we disallowed setting attributes on unbound methods
+ # (it was already disallowed on bound methods). See the PEP for details.
+ try:
+ F.a.publish = 1
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, 'expected TypeError'
! # But setting it explicitly on the underlying function object is okay.
! F.a.im_func.publish = 1
!
if F.a.publish <> 1:
raise TestFailed, 'unbound method attribute not set to expected value'
***************
*** 67,71 ****
raise TestFailed, 'expected TypeError'
! F.a.myclass = F
f1.a.myclass
f2.a.myclass
--- 90,103 ----
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
!
f1.a.myclass
f2.a.myclass
***************
*** 84,89 ****
else:
raise TestFailed, 'expected TypeError'
- F.a.__dict__ = {'one': 11, 'two': 22, 'three': 33}
if f1.a.two <> 22:
raise TestFailed, 'setting __dict__'
--- 116,122 ----
else:
raise TestFailed, 'expected TypeError'
+
+ F.a.im_func.__dict__ = {'one': 11, 'two': 22, 'three': 33}
if f1.a.two <> 22:
raise TestFailed, 'setting __dict__'