[Python-checkins] CVS: python/dist/src/Lib/test test_descr.py,1.87,1.88
Tim Peters
tim_one@users.sourceforge.net
2001年10月11日 19:38:27 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv9055/python/Lib/test
Modified Files:
test_descr.py
Log Message:
SF bug [#470040] ParseTuple t# vs subclasses.
inherit_slots(): tp_as_buffer was getting inherited as if it were a
method pointer, rather than a pointer to a vector of method pointers. As
a result, inheriting from a type that implemented buffer methods was
ineffective, leaving all the tp_as_buffer slots NULL in the subclass.
Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.87
retrieving revision 1.88
diff -C2 -d -r1.87 -r1.88
*** test_descr.py 2001年10月11日 18:33:53 1.87
--- test_descr.py 2001年10月12日 02:38:24 1.88
***************
*** 2299,2304 ****
else:
raise TestFailed, "d.foo should be undefined now"
-
def test_main():
class_docstrings()
--- 2299,2334 ----
else:
raise TestFailed, "d.foo should be undefined now"
+ def buffer_inherit():
+ import binascii
+ # SF bug [#470040] ParseTuple t# vs subclasses.
+ if verbose:
+ print "Testing that buffer interface is inherited ..."
+
+ class MyStr(str):
+ pass
+ base = 'abc'
+ m = MyStr(base)
+ # b2a_hex uses the buffer interface to get its argument's value, via
+ # PyArg_ParseTuple 't#' code.
+ vereq(binascii.b2a_hex(m), binascii.b2a_hex(base))
+
+ # It's not clear that unicode will continue to support the character
+ # buffer interface, and this test will fail if that's taken away.
+ class MyUni(unicode):
+ pass
+ base = u'abc'
+ m = MyUni(base)
+ vereq(binascii.b2a_hex(m), binascii.b2a_hex(base))
+
+ class MyInt(int):
+ pass
+ m = MyInt(42)
+ try:
+ binascii.b2a_hex(m)
+ raise TestFailed('subclass of int should not have a buffer interface')
+ except TypeError:
+ pass
+
def test_main():
class_docstrings()
***************
*** 2348,2351 ****
--- 2378,2382 ----
binopoverride()
subclasspropagation()
+ buffer_inherit()
if verbose: print "All OK"