Author: Matti Picus <matti.pi...@gmail.com>
Branch: issue2752
Changeset: r94267:0c1b091fb92b
Date: 2018-04-08 12:03 +0300
http://bitbucket.org/pypy/pypy/changeset/0c1b091fb92b/

Log:    simplify more

diff --git a/pypy/module/cpyext/test/test_bufferobject.py 
b/pypy/module/cpyext/test/test_bufferobject.py
--- a/pypy/module/cpyext/test/test_bufferobject.py
+++ b/pypy/module/cpyext/test/test_bufferobject.py
@@ -73,7 +73,6 @@
             """
                 PyObject *obj, *collect, *tup;
                 Py_buffer bp;
-                char expected_i = '0';
                 if (!PyArg_ParseTuple(args, "OO", &obj, &collect))
                     return NULL;
 
@@ -83,27 +82,18 @@
                     return NULL;
                 
                 tup = PyTuple_New(0); /* for collect() */
-                for (size_t i = 0; i < bp.len; ++i)
-                {
-                    if (((unsigned char*)bp.buf)[i] == expected_i)
-                    {
-                        if (++expected_i >= '8')
-                            expected_i = '0';
-                    }
-                    else
-                    {
-                        PyErr_Format(PyExc_ValueError,
-                                "mismatch: 0x%x [%x %x %x %x...] instead of 
0x%x on pos=%d (got len=%d)",
-                                ((unsigned char*)bp.buf)[i],
-                                ((unsigned char*)bp.buf)[i+1],
-                                ((unsigned char*)bp.buf)[i+2],
-                                ((unsigned char*)bp.buf)[i+3],
-                        ((unsigned char*)bp.buf)[i+4],
-                        expected_i, i, bp.len);
-                        PyBuffer_Release(&bp);
-                        Py_DECREF(tup);
-                        return NULL;
-                    }
+                if (((unsigned char*)bp.buf)[0] != '0') {
+                    PyErr_Format(PyExc_ValueError,
+                            "mismatch: 0x%x [%x %x %x %x...] instead of '0' 
(got len=%d)",
+                            ((unsigned char*)bp.buf)[0],
+                            ((unsigned char*)bp.buf)[1],
+                            ((unsigned char*)bp.buf)[2],
+                            ((unsigned char*)bp.buf)[3],
+                            ((unsigned char*)bp.buf)[4],
+                            bp.len);
+                    PyBuffer_Release(&bp);
+                    Py_DECREF(tup);
+                    return NULL;
                 }
 
                 PyBuffer_Release(&bp);
@@ -120,11 +110,11 @@
                 if len(data) >= bufsize:
                     break
             return data
-        for j, block in enumerate(iter(lambda: getdata(bufsize), b'')):
+        for j in range(2000):
+            block = getdata(bufsize)
+            assert block[:8] == '01234567'
             try:
                 module.test_mod(block, gc.collect)
             except ValueError as e:
                 print("%s at it=%d" % (e, j))
                 assert False
-            if j > 2000:
-                break
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to