[pypy-svn] pypy bytearray: (lac, mfoord) test bytearray.split and partition with memoryview argument

mfoord commits-noreply at bitbucket.org
Thu Jan 20 18:36:38 CET 2011


Author: Michael Foord <michael at voidspace.org.uk>
Branch: bytearray
Changeset: r41056:9d2c5004e8dd
Date: 2011-01-20 18:36 +0100
http://bitbucket.org/pypy/pypy/changeset/9d2c5004e8dd/

Log:	(lac, mfoord) test bytearray.split and partition with memoryview
	argument test bytearray.split with default argument (None)

diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -509,6 +509,7 @@
 
 def str_split__Bytearray_ANY_ANY(space, w_bytearray, w_by, w_maxsplit=-1):
     w_str = str__Bytearray(space, w_bytearray)
+    w_by = space.wrap(space.bufferstr_w(w_by))
     w_list = space.call_method(w_str, "split", w_by, w_maxsplit)
     list_w = space.listview(w_list)
     for i in range(len(list_w)):
@@ -517,6 +518,7 @@
 
 def str_rsplit__Bytearray_ANY_ANY(space, w_bytearray, w_by, w_maxsplit=-1):
     w_str = str__Bytearray(space, w_bytearray)
+    w_by = space.wrap(space.bufferstr_w(w_by))
     w_list = space.call_method(w_str, "rsplit", w_by, w_maxsplit)
     list_w = space.listview(w_list)
     for i in range(len(list_w)):
@@ -525,6 +527,7 @@
 
 def str_partition__Bytearray_ANY(space, w_bytearray, w_sub):
     w_str = str__Bytearray(space, w_bytearray)
+    w_sub = space.wrap(space.bufferstr_w(w_sub))
     w_tuple = stringobject.str_partition__String_String(space, w_str, w_sub)
     w_a, w_b, w_c = space.fixedview(w_tuple, 3)
     return space.newtuple([
@@ -534,6 +537,7 @@
 
 def str_rpartition__Bytearray_ANY(space, w_bytearray, w_sub):
     w_str = str__Bytearray(space, w_bytearray)
+    w_sub = space.wrap(space.bufferstr_w(w_sub))
     w_tuple = stringobject.str_rpartition__String_String(space, w_str, w_sub)
     w_a, w_b, w_c = space.fixedview(w_tuple, 3)
     return space.newtuple([

diff --git a/pypy/objspace/std/test/test_bytes.py b/pypy/objspace/std/test/test_bytes.py
--- a/pypy/objspace/std/test/test_bytes.py
+++ b/pypy/objspace/std/test/test_bytes.py
@@ -193,12 +193,19 @@
             assert set(type(x) for x in result) == set([bytearray])
 
         b = bytearray('mississippi')
-        check(b.split('i'), eval("[b'm', b'ss', b'ss', b'pp', b'']"))
-        check(b.rsplit('i'), eval("[b'm', b'ss', b'ss', b'pp', b'']"))
-        check(b.rsplit('i', 2), eval("[b'mississ', b'pp', b'']"))
+        check(b.split('i'), ['m', 'ss', 'ss', 'pp', ''])
+        check(b.split(memoryview('i')), ['m', 'ss', 'ss', 'pp', ''])
+        check(b.rsplit('i'), ['m', b'ss', b'ss', b'pp', b''])
+        check(b.rsplit(memoryview('i')), ['m', b'ss', b'ss', b'pp', b''])
+        check(b.rsplit('i', 2), ['mississ', 'pp', ''])
 
-        check(b.partition(eval("b'ss'")), eval("(b'mi', b'ss', b'issippi')"))
-        check(b.rpartition(eval("b'ss'")), eval("(b'missi', b'ss', b'ippi')"))
+        check(bytearray('foo bar').split(), ['foo', 'bar'])
+        check(bytearray('foo bar').split(None), ['foo', 'bar'])
+
+        check(b.partition('ss'), ('mi', 'ss', 'issippi'))
+        check(b.partition(memoryview('ss')), ('mi', 'ss', 'issippi'))
+        check(b.rpartition('ss'), ('missi', 'ss', 'ippi'))
+        check(b.rpartition(memoryview('ss')), ('missi', 'ss', 'ippi'))
 
     def test_append(self):
         b = bytearray('abc')


More information about the Pypy-commit mailing list