summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rwxr-xr-xLib/test/test_array.py2
-rw-r--r--Lib/test/test_buffer.py56
-rw-r--r--Lib/test/test_bytes.py16
-rw-r--r--Lib/test/test_io.py2
-rw-r--r--Lib/test/test_marshal.py4
-rw-r--r--Lib/test/test_repr.py6
-rw-r--r--Lib/test/test_struct.py14
-rw-r--r--Lib/test/test_types.py48
-rw-r--r--Lib/test/test_unicode.py2
9 files changed, 20 insertions, 130 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index db029f3..5e4bde6 100755
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -708,7 +708,7 @@ class BaseTest(unittest.TestCase):
def test_buffer(self):
a = array.array(self.typecode, self.example)
- b = bytes(buffer(a))
+ b = bytes(memoryview(a))
self.assertEqual(b[0], a.tostring()[0])
def test_weakref(self):
diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py
deleted file mode 100644
index 834c05b..0000000
--- a/Lib/test/test_buffer.py
+++ /dev/null
@@ -1,56 +0,0 @@
-"""Unit tests for buffer objects.
-
-For now, we just test (the brand new) rich comparison.
-
-"""
-
-import unittest
-from test import test_support
-
-class BufferTests(unittest.TestCase):
-
- def test_comparison(self):
- a = buffer("a.b.c")
- b = buffer("a.b" + ".c")
- self.assert_(a == b)
- self.assert_(a <= b)
- self.assert_(a >= b)
- self.assert_(a == "a.b.c")
- self.assert_(a <= "a.b.c")
- self.assert_(a >= "a.b.c")
- b = buffer("a.b.c.d")
- self.assert_(a != b)
- self.assert_(a <= b)
- self.assert_(a < b)
- self.assert_(a != "a.b.c.d")
- self.assert_(a < "a.b.c.d")
- self.assert_(a <= "a.b.c.d")
- b = buffer("a.b")
- self.assert_(a != b)
- self.assert_(a >= b)
- self.assert_(a > b)
- self.assert_(a != "a.b")
- self.assert_(a > "a.b")
- self.assert_(a >= "a.b")
- b = object()
- self.assert_(a != b)
- self.failIf(a == b)
- self.assertRaises(TypeError, lambda: a < b)
-
- def test_extended_getslice(self):
- # Test extended slicing by comparing with list slicing.
- s = bytes(range(255, -1, -1))
- b = buffer(s)
- indices = (0, None, 1, 3, 19, 300, -1, -2, -31, -300)
- for start in indices:
- for stop in indices:
- # Skip step 0 (invalid)
- for step in indices[1:]:
- self.assertEqual(b[start:stop:step],
- s[start:stop:step])
-
-def test_main():
- test_support.run_unittest(BufferTests)
-
-if __name__ == "__main__":
- test_main()
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index cfcd282..61950cc 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -343,7 +343,7 @@ class BytesTest(unittest.TestCase):
def test_from_buffer(self):
sample = str8("Hello world\n\x80\x81\xfe\xff")
- buf = buffer(sample)
+ buf = memoryview(sample)
b = bytes(buf)
self.assertEqual(b, bytes(map(ord, sample)))
@@ -456,8 +456,8 @@ class BytesTest(unittest.TestCase):
b = bytes([0x1a, 0x2b, 0x30])
self.assertEquals(bytes.fromhex('1a2B30'), b)
self.assertEquals(bytes.fromhex(' 1A 2B 30 '), b)
- self.assertEquals(bytes.fromhex(buffer(b'')), bytes())
- self.assertEquals(bytes.fromhex(buffer(b'0000')), bytes([0, 0]))
+ self.assertEquals(bytes.fromhex(memoryview(b'')), bytes())
+ self.assertEquals(bytes.fromhex(memoryview(b'0000')), bytes([0, 0]))
self.assertRaises(ValueError, bytes.fromhex, 'a')
self.assertRaises(ValueError, bytes.fromhex, 'rt')
self.assertRaises(ValueError, bytes.fromhex, '1a b cd')
@@ -630,7 +630,7 @@ class BytesTest(unittest.TestCase):
self.assertEqual(b' a bb c '.split(None, 3), [b'a', b'bb', b'c'])
def test_split_buffer(self):
- self.assertEqual(b'a b'.split(buffer(b' ')), [b'a', b'b'])
+ self.assertEqual(b'a b'.split(memoryview(b' ')), [b'a', b'b'])
def test_split_string_error(self):
self.assertRaises(TypeError, b'a b'.split, ' ')
@@ -653,7 +653,7 @@ class BytesTest(unittest.TestCase):
self.assertEqual(b' a bb c '.rsplit(None, 3), [b'a', b'bb', b'c'])
def test_rplit_buffer(self):
- self.assertEqual(b'a b'.rsplit(buffer(b' ')), [b'a', b'b'])
+ self.assertEqual(b'a b'.rsplit(memoryview(b' ')), [b'a', b'b'])
def test_rplit_string_error(self):
self.assertRaises(TypeError, b'a b'.rsplit, ' ')
@@ -707,9 +707,9 @@ class BytesTest(unittest.TestCase):
self.assertEqual(b.rstrip(), b' \t\n\r\f\vabc')
def test_strip_buffer(self):
- self.assertEqual(b'abc'.strip(buffer(b'ac')), b'b')
- self.assertEqual(b'abc'.lstrip(buffer(b'ac')), b'bc')
- self.assertEqual(b'abc'.rstrip(buffer(b'ac')), b'ab')
+ self.assertEqual(b'abc'.strip(memoryview(b'ac')), b'b')
+ self.assertEqual(b'abc'.lstrip(memoryview(b'ac')), b'bc')
+ self.assertEqual(b'abc'.rstrip(memoryview(b'ac')), b'ab')
def test_strip_string_error(self):
self.assertRaises(TypeError, b'abc'.strip, 'b')
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 5c30e50..644593d 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -251,7 +251,7 @@ class IOTest(unittest.TestCase):
def test_array_writes(self):
a = array.array('i', range(10))
- n = len(buffer(a))
+ n = len(memoryview(a))
f = io.open(test_support.TESTFN, "wb", 0)
self.assertEqual(f.write(a), n)
f.close()
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
index 47e610f..3e44886 100644
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -98,9 +98,9 @@ class StringTestCase(unittest.TestCase, HelperMixin):
for s in ["", "Andr\xe8 Previn", "abc", " "*10000]:
self.helper(s)
- def test_buffer(self):
+ def test_bytes(self):
for s in [b"", b"Andr\xe8 Previn", b"abc", b" "*10000]:
- self.helper(buffer(s))
+ self.helper(s)
class ExceptionTestCase(unittest.TestCase):
def test_exceptions(self):
diff --git a/Lib/test/test_repr.py b/Lib/test/test_repr.py
index 075aca9..8d9e99d 100644
--- a/Lib/test/test_repr.py
+++ b/Lib/test/test_repr.py
@@ -163,12 +163,6 @@ class ReprTests(unittest.TestCase):
eq(r([[[[[[{}]]]]]]), "[[[[[[{}]]]]]]")
eq(r([[[[[[[{}]]]]]]]), "[[[[[[[...]]]]]]]")
- def test_buffer(self):
- # XXX doesn't test buffers with no b_base or read-write buffers (see
- # bufferobject.c). The test is fairly incomplete too. Sigh.
- x = buffer('foo')
- self.failUnless(repr(x).startswith('<read-only buffer for 0x'))
-
def test_cell(self):
# XXX Hmm? How to get at a cell object?
pass
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index c7019a4..83d7efb 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -541,7 +541,7 @@ def test_1530559():
test_1530559()
###########################################################################
-# Packing and unpacking to/from buffers.
+# Packing and unpacking to/from memory views.
# Copied and modified from unittest.
def assertRaises(excClass, callableObj, *args, **kwargs):
@@ -556,7 +556,7 @@ def test_unpack_from():
test_string = b'abcd01234'
fmt = '4s'
s = struct.Struct(fmt)
- for cls in (str, str8, buffer, bytes):
+ for cls in (str, str8, bytes): # XXX + memoryview
if verbose:
print("test_unpack_from using", cls.__name__)
data = cls(test_string)
@@ -567,7 +567,7 @@ def test_unpack_from():
vereq(s.unpack_from(data, i), (data[i:i+4],))
for i in range(6, len(test_string) + 1):
simple_err(s.unpack_from, data, i)
- for cls in (str, buffer):
+ for cls in (str, str8, bytes): # XXX + memoryview
data = cls(test_string)
vereq(struct.unpack_from(fmt, data), ('abcd',))
vereq(struct.unpack_from(fmt, data, 2), ('cd01',))
@@ -619,19 +619,19 @@ def test_pack_into_fn():
assertRaises(struct.error, pack_into, small_buf, 0, test_string)
assertRaises(struct.error, pack_into, small_buf, 2, test_string)
-def test_unpack_with_buffer():
+def test_unpack_with_memoryview():
# SF bug 1563759: struct.unpack doens't support buffer protocol objects
data1 = array.array('B', b'\x12\x34\x56\x78')
- data2 = buffer(b'......\x12\x34\x56\x78......', 6, 4)
+ data2 = memoryview(b'\x12\x34\x56\x78') # XXX b'......XXXX......', 6, 4
for data in [data1, data2]:
value, = struct.unpack('>I', data)
vereq(value, 0x12345678)
-# Test methods to pack and unpack from buffers rather than strings.
+# Test methods to pack and unpack from memoryviews rather than strings.
test_unpack_from()
test_pack_into()
test_pack_into_fn()
-test_unpack_with_buffer()
+test_unpack_with_memoryview()
def test_bool():
for prefix in tuple("<>!=")+('',):
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index a40145b..70c281f 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -203,54 +203,6 @@ class TypesTests(unittest.TestCase):
self.assertRaises(TypeError, type, 1, 2)
self.assertRaises(TypeError, type, 1, 2, 3, 4)
- def test_buffers(self):
- self.assertRaises(ValueError, buffer, 'asdf', -1)
- self.assertRaises(TypeError, buffer, None)
-
- a = buffer(b'asdf')
- hash(a)
- b = a * 5
- if a == b:
- self.fail('buffers should not be equal')
- if str(b) != ('asdf' * 5):
- self.fail('repeated buffer has wrong content')
- if str(a * 0) != '':
- self.fail('repeated buffer zero times has wrong content')
- if str(a + buffer(b'def')) != 'asdfdef':
- self.fail('concatenation of buffers yields wrong content')
- if str(buffer(a)) != 'asdf':
- self.fail('composing buffers failed')
- if str(buffer(a, 2)) != 'df':
- self.fail('specifying buffer offset failed')
- if str(buffer(a, 0, 2)) != 'as':
- self.fail('specifying buffer size failed')
- if str(buffer(a, 1, 2)) != 'sd':
- self.fail('specifying buffer offset and size failed')
- self.assertRaises(ValueError, buffer, buffer(b'asdf', 1), -1)
- if str(buffer(buffer(b'asdf', 0, 2), 0)) != 'as':
- self.fail('composing length-specified buffer failed')
- if str(buffer(buffer(b'asdf', 0, 2), 0, 5000)) != 'as':
- self.fail('composing length-specified buffer failed')
- if str(buffer(buffer(b'asdf', 0, 2), 0, -1)) != 'as':
- self.fail('composing length-specified buffer failed')
- if str(buffer(buffer(b'asdf', 0, 2), 1, 2)) != 's':
- self.fail('composing length-specified buffer failed')
-
- try: a[1] = 'g'
- except TypeError: pass
- else: self.fail("buffer assignment should raise TypeError")
-
- try: a[0:1] = 'g'
- except TypeError: pass
- else: self.fail("buffer slice assignment should raise TypeError")
-
- # array.array() returns an object that does not implement a char buffer,
- # something which int() uses for conversion.
- import array
- try: int(buffer(array.array('b')))
- except TypeError: pass
- else: self.fail("char buffer (at C level) not working")
-
def test_main():
run_unittest(TypesTests)
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 1358419..d33643a 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -713,7 +713,7 @@ class UnicodeTest(
if not sys.platform.startswith('java'):
self.assertEqual(
str(
- buffer(b'character buffers are decoded to unicode'),
+ memoryview(b'character buffers are decoded to unicode'),
'utf-8',
'strict'
),