From: Fred Drake Date: Thu, 2 May 2002 04:49:48 +0000 (+0000) Subject: Backport buffer() tests trunk to avoid regression failures. X-Git-Tag: v2.2.2b1~391 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0beb34ce1869c4020b2bfed230ced062236b1b8f;p=thirdparty%2FPython%2Fcpython.git Backport buffer() tests trunk to avoid regression failures. --- diff --git a/Lib/test/output/test_types b/Lib/test/output/test_types index 065594d6a8a6..46832bf40f75 100644 --- a/Lib/test/output/test_types +++ b/Lib/test/output/test_types @@ -13,3 +13,4 @@ test_types 6.5.3 Lists 6.5.3a Additional list operations 6.6 Mappings == Dictionaries +6.7 Buffers diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index 5d945728f5c1..9d34f3c96d41 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -397,3 +397,32 @@ else: raise TestFailed, 'type(), w/2 args expected TypeError' try: type(1, 2, 3, 4) except TypeError: pass else: raise TestFailed, 'type(), w/4 args expected TypeError' + +print '6.7 Buffers' +try: buffer('asdf', -1) +except ValueError: pass +else: raise TestFailed, "buffer('asdf', -1) should raise ValueError" + +try: buffer(None) +except TypeError: pass +else: raise TestFailed, "buffer(None) should raise TypeError" + +a = buffer('asdf') +hash(a) +b = a * 5 +if a == b: + raise TestFailed, 'buffers should not be equal' +if str(b) != ('asdf' * 5): + raise TestFailed, 'repeated buffer has wrong content' +if str(a * 0) != '': + raise TestFailed, 'repeated buffer zero times has wrong content' +if str(a + buffer('def')) != 'asdfdef': + raise TestFailed, 'concatenation of buffers yields wrong content' + +try: a[1] = 'g' +except TypeError: pass +else: raise TestFailed, "buffer assignment should raise TypeError" + +try: a[0:1] = 'g' +except TypeError: pass +else: raise TestFailed, "buffer slice assignment should raise TypeError"