[Python-checkins] r61754 - in python/branches/trunk-bytearray: Lib/test/buffer_tests.py Lib/test/test_bytes.py Objects/bytesobject.c

christian.heimes python-checkins at python.org
Sat Mar 22 21:22:39 CET 2008


Author: christian.heimes
Date: Sat Mar 22 21:22:19 2008
New Revision: 61754

Modified:
   python/branches/trunk-bytearray/Lib/test/buffer_tests.py
   python/branches/trunk-bytearray/Lib/test/test_bytes.py
   python/branches/trunk-bytearray/Objects/bytesobject.c
Log:
Disabled bytearray.extend for now since it causes an infinite recursion
Fixed serveral unit tests

Modified: python/branches/trunk-bytearray/Lib/test/buffer_tests.py
==============================================================================
--- python/branches/trunk-bytearray/Lib/test/buffer_tests.py	(original)
+++ python/branches/trunk-bytearray/Lib/test/buffer_tests.py	Sat Mar 22 21:22:19 2008
@@ -172,9 +172,9 @@
 
         self.assertRaises(TypeError, self.marshal(b'hello').expandtabs, 42, 42)
         # This test is only valid when sizeof(int) == sizeof(void*) == 4.
-        if sys.maxsize < (1 << 32) and struct.calcsize('P') == 4:
+        if sys.maxint < (1 << 32) and struct.calcsize('P') == 4:
             self.assertRaises(OverflowError,
-                              self.marshal(b'\ta\n\tb').expandtabs, sys.maxsize)
+                              self.marshal(b'\ta\n\tb').expandtabs, sys.maxint)
 
     def test_title(self):
         self.assertEqual(b' Hello ', self.marshal(b' hello ').title())

Modified: python/branches/trunk-bytearray/Lib/test/test_bytes.py
==============================================================================
--- python/branches/trunk-bytearray/Lib/test/test_bytes.py	(original)
+++ python/branches/trunk-bytearray/Lib/test/test_bytes.py	Sat Mar 22 21:22:19 2008
@@ -36,14 +36,14 @@
         self.assertEqual(len(b), 0)
         self.assertRaises(IndexError, lambda: b[0])
         self.assertRaises(IndexError, lambda: b[1])
-        self.assertRaises(IndexError, lambda: b[sys.maxsize])
-        self.assertRaises(IndexError, lambda: b[sys.maxsize+1])
+        self.assertRaises(IndexError, lambda: b[sys.maxint])
+        self.assertRaises(IndexError, lambda: b[sys.maxint+1])
         self.assertRaises(IndexError, lambda: b[10**100])
         self.assertRaises(IndexError, lambda: b[-1])
         self.assertRaises(IndexError, lambda: b[-2])
-        self.assertRaises(IndexError, lambda: b[-sys.maxsize])
-        self.assertRaises(IndexError, lambda: b[-sys.maxsize-1])
-        self.assertRaises(IndexError, lambda: b[-sys.maxsize-2])
+        self.assertRaises(IndexError, lambda: b[-sys.maxint])
+        self.assertRaises(IndexError, lambda: b[-sys.maxint-1])
+        self.assertRaises(IndexError, lambda: b[-sys.maxint-2])
         self.assertRaises(IndexError, lambda: b[-10**100])
 
     def test_from_list(self):
@@ -83,14 +83,14 @@
 
     def test_constructor_value_errors(self):
         self.assertRaises(ValueError, self.type2test, [-1])
-        self.assertRaises(ValueError, self.type2test, [-sys.maxsize])
-        self.assertRaises(ValueError, self.type2test, [-sys.maxsize-1])
-        self.assertRaises(ValueError, self.type2test, [-sys.maxsize-2])
+        self.assertRaises(ValueError, self.type2test, [-sys.maxint])
+        self.assertRaises(ValueError, self.type2test, [-sys.maxint-1])
+        self.assertRaises(ValueError, self.type2test, [-sys.maxint-2])
         self.assertRaises(ValueError, self.type2test, [-10**100])
         self.assertRaises(ValueError, self.type2test, [256])
         self.assertRaises(ValueError, self.type2test, [257])
-        self.assertRaises(ValueError, self.type2test, [sys.maxsize])
-        self.assertRaises(ValueError, self.type2test, [sys.maxsize+1])
+        self.assertRaises(ValueError, self.type2test, [sys.maxint])
+        self.assertRaises(ValueError, self.type2test, [sys.maxint+1])
         self.assertRaises(ValueError, self.type2test, [10**100])
 
     def test_compare(self):
@@ -210,7 +210,7 @@
             self.assertRaises(TypeError, lambda: 3.14 * b)
             # XXX Shouldn't bytes and bytearray agree on what to raise?
             self.assertRaises((OverflowError, MemoryError),
-                              lambda: b * sys.maxsize)
+                              lambda: b * sys.maxint)
 
     def test_repeat_1char(self):
         self.assertEqual(self.type2test(b'x')*100, self.type2test([ord('x')]*100))
@@ -866,7 +866,7 @@
     def fixtype(self, obj):
         if isinstance(obj, str):
             return obj.encode("utf-8")
-        return super().fixtype(obj)
+        return super(FixedStringTest, self).fixtype(obj)
 
     # Currently the bytes containment testing uses a single integer
     # value. This may not be the final design, but until then the
@@ -964,12 +964,13 @@
 
 def test_main():
     #test.test_support.run_unittest(BytesTest)
-    test.test_support.run_unittest(ByteArrayTest)
     #test.test_support.run_unittest(AssortedBytesTest)
     #test.test_support.run_unittest(BytesAsStringTest)
-    test.test_support.run_unittest(ByteArrayAsStringTest)
-    test.test_support.run_unittest(ByteArraySubclassTest)
-    test.test_support.run_unittest(BytearrayPEP3137Test)
+    test.test_support.run_unittest(
+        ByteArrayTest,
+        ByteArrayAsStringTest,
+        ByteArraySubclassTest,
+        BytearrayPEP3137Test)
 
 if __name__ == "__main__":
     test_main()

Modified: python/branches/trunk-bytearray/Objects/bytesobject.c
==============================================================================
--- python/branches/trunk-bytearray/Objects/bytesobject.c	(original)
+++ python/branches/trunk-bytearray/Objects/bytesobject.c	Sat Mar 22 21:22:19 2008
@@ -34,8 +34,8 @@
 {
     long face_value;
 
-    if (PyLong_Check(arg)) {
-        face_value = PyLong_AsLong(arg);
+    if (PyInt_Check(arg)) {
+        face_value = PyInt_AsLong(arg);
         if (face_value < 0 || face_value >= 256) {
             PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
             return 0;
@@ -350,7 +350,7 @@
         PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
         return NULL;
     }
-    return PyLong_FromLong((unsigned char)(self->ob_bytes[i]));
+    return PyInt_FromLong((unsigned char)(self->ob_bytes[i]));
 }
 
 static PyObject *
@@ -369,7 +369,7 @@
             PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
             return NULL;
         }
-        return PyLong_FromLong((unsigned char)(self->ob_bytes[i]));
+        return PyInt_FromLong((unsigned char)(self->ob_bytes[i]));
     }
     else if (PySlice_Check(item)) {
         Py_ssize_t start, stop, step, slicelength, cur, i;
@@ -1105,7 +1105,7 @@
     Py_ssize_t result = bytes_find_internal(self, args, +1);
     if (result == -2)
         return NULL;
-    return PyLong_FromSsize_t(result);
+    return PyInt_FromSsize_t(result);
 }
 
 PyDoc_STRVAR(count__doc__,
@@ -1133,7 +1133,7 @@
 
     _adjust_indices(&start, &end, PyBytes_GET_SIZE(self));
 
-    count_obj = PyLong_FromSsize_t(
+    count_obj = PyInt_FromSsize_t(
         stringlib_count(str + start, end - start, vsub.buf, vsub.len)
         );
     PyObject_ReleaseBuffer(sub_obj, &vsub);
@@ -1157,7 +1157,7 @@
                         "subsection not found");
         return NULL;
     }
-    return PyLong_FromSsize_t(result);
+    return PyInt_FromSsize_t(result);
 }
 
 
@@ -1176,7 +1176,7 @@
     Py_ssize_t result = bytes_find_internal(self, args, -1);
     if (result == -2)
         return NULL;
-    return PyLong_FromSsize_t(result);
+    return PyInt_FromSsize_t(result);
 }
 
 
@@ -1196,7 +1196,7 @@
                         "subsection not found");
         return NULL;
     }
-    return PyLong_FromSsize_t(result);
+    return PyInt_FromSsize_t(result);
 }
 
 
@@ -2678,7 +2678,7 @@
     if (PyBytes_Resize((PyObject *)self, n - 1) < 0)
         return NULL;
 
-    return PyLong_FromLong(value);
+    return PyInt_FromLong(value);
 }
 
 PyDoc_STRVAR(remove__doc__,
@@ -2865,7 +2865,7 @@
 static PyObject *
 bytes_alloc(PyBytesObject *self)
 {
-    return PyLong_FromSsize_t(self->ob_alloc);
+    return PyInt_FromSsize_t(self->ob_alloc);
 }
 
 PyDoc_STRVAR(join_doc,
@@ -3073,7 +3073,8 @@
     {"endswith", (PyCFunction)bytes_endswith, METH_VARARGS, endswith__doc__},
     {"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS,
      expandtabs__doc__},
-    {"extend", (PyCFunction)bytes_extend, METH_O, extend__doc__},
+    /* XXX extend causes an infinite recursion 
+    {"extend", (PyCFunction)bytes_extend, METH_O, extend__doc__}, */
     {"find", (PyCFunction)bytes_find, METH_VARARGS, find__doc__},
     {"fromhex", (PyCFunction)bytes_fromhex, METH_VARARGS|METH_CLASS,
      fromhex_doc},
@@ -3221,7 +3222,7 @@
     assert(PyBytes_Check(seq));
 
     if (it->it_index < PyBytes_GET_SIZE(seq)) {
-        item = PyLong_FromLong(
+        item = PyInt_FromLong(
             (unsigned char)seq->ob_bytes[it->it_index]);
         if (item != NULL)
             ++it->it_index;
@@ -3239,7 +3240,7 @@
     Py_ssize_t len = 0;
     if (it->it_seq)
         len = PyBytes_GET_SIZE(it->it_seq) - it->it_index;
-    return PyLong_FromSsize_t(len);
+    return PyInt_FromSsize_t(len);
 }
 
 PyDoc_STRVAR(length_hint_doc,


More information about the Python-checkins mailing list