[Python-3000-checkins] r45656 - in python/branches/p3yk: Lib/test/test_bytes.py Objects/bytesobject.c

guido.van.rossum python-3000-checkins at python.org
Sun Apr 23 09:43:55 CEST 2006


Author: guido.van.rossum
Date: Sun Apr 23 09:43:54 2006
New Revision: 45656

Modified:
   python/branches/p3yk/Lib/test/test_bytes.py
   python/branches/p3yk/Objects/bytesobject.c
Log:
Fix a leak and a buglet discovered by Thomas.
Get rid of silly lambdas in the unit test suite.
Add a TODO list to the unit test suite (TDD style).


Modified: python/branches/p3yk/Lib/test/test_bytes.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_bytes.py	(original)
+++ python/branches/p3yk/Lib/test/test_bytes.py	Sun Apr 23 09:43:54 2006
@@ -41,28 +41,29 @@
                 return self.i
         b = bytes([C(), C(1), C(254), C(255)])
         self.assertEqual(list(b), [0, 1, 254, 255])
-        self.assertRaises(ValueError, lambda: bytes([C(-1)]))
-        self.assertRaises(ValueError, lambda: bytes([C(256)]))
+        self.assertRaises(ValueError, bytes, [C(-1)])
+        self.assertRaises(ValueError, bytes, [C(256)])
 
     def test_constructor_type_errors(self):
+        self.assertRaises(TypeError, bytes, 0)
         class C:
             pass
-        self.assertRaises(TypeError, lambda: bytes(["0"]))
-        self.assertRaises(TypeError, lambda: bytes([0.0]))
-        self.assertRaises(TypeError, lambda: bytes([None]))
-        self.assertRaises(TypeError, lambda: bytes([C()]))
+        self.assertRaises(TypeError, bytes, ["0"])
+        self.assertRaises(TypeError, bytes, [0.0])
+        self.assertRaises(TypeError, bytes, [None])
+        self.assertRaises(TypeError, bytes, [C()])
 
     def test_constructor_value_errors(self):
-        self.assertRaises(ValueError, lambda: bytes([-1]))
-        self.assertRaises(ValueError, lambda: bytes([-sys.maxint]))
-        self.assertRaises(ValueError, lambda: bytes([-sys.maxint-1]))
-        self.assertRaises(ValueError, lambda: bytes([-sys.maxint-2]))
-        self.assertRaises(ValueError, lambda: bytes([-10**100]))
-        self.assertRaises(ValueError, lambda: bytes([256]))
-        self.assertRaises(ValueError, lambda: bytes([257]))
-        self.assertRaises(ValueError, lambda: bytes([sys.maxint]))
-        self.assertRaises(ValueError, lambda: bytes([sys.maxint+1]))
-        self.assertRaises(ValueError, lambda: bytes([10**100]))
+        self.assertRaises(ValueError, bytes, [-1])
+        self.assertRaises(ValueError, bytes, [-sys.maxint])
+        self.assertRaises(ValueError, bytes, [-sys.maxint-1])
+        self.assertRaises(ValueError, bytes, [-sys.maxint-2])
+        self.assertRaises(ValueError, bytes, [-10**100])
+        self.assertRaises(ValueError, bytes, [256])
+        self.assertRaises(ValueError, bytes, [257])
+        self.assertRaises(ValueError, bytes, [sys.maxint])
+        self.assertRaises(ValueError, bytes, [sys.maxint+1])
+        self.assertRaises(ValueError, bytes, [10**100])
 
     def test_repr(self):
         self.assertEqual(repr(bytes()), "bytes()")
@@ -99,6 +100,37 @@
         self.failUnless(bytes.__doc__ != None)
         self.failUnless(bytes.__doc__.startswith("bytes("))
 
+    # XXX More stuff to test and build (TDD):
+    # constructor from str: bytes(<str>) == bytes(map(ord, <str>))?
+    # encoding constructor: bytes(<unicode>[, <encoding>[, <errors>]])
+    # default encoding Latin-1? (Matching ord)
+    # slicing
+    # extended slicing?
+    # item assignment
+    # slice assignment
+    # extended slice assignment?
+    # __contains__ with simple int arg
+    # __contains__ with another bytes arg?
+    # find/index? (int or bytes arg?)
+    # count? (int arg)
+    # concatenation (+)
+    # repeat?
+    # extend?
+    # append?
+    # insert?
+    # pop?
+    # __reversed__?
+    # reverse? (inplace)
+    # NOT sort!
+    # __iter__? (optimization)
+    # __str__? (could return "".join(map(chr, self))
+    # decode
+    # buffer API
+    # check that regexp searches work
+    # (I suppose re.sub() returns a string)
+    # file.readinto
+    # file.write
+
 
 def test_main():
     test.test_support.run_unittest(BytesTest)

Modified: python/branches/p3yk/Objects/bytesobject.c
==============================================================================
--- python/branches/p3yk/Objects/bytesobject.c	(original)
+++ python/branches/p3yk/Objects/bytesobject.c	Sun Apr 23 09:43:54 2006
@@ -130,7 +130,7 @@
     /* Get the iterator */
     it = PyObject_GetIter(arg);
     if (it == NULL)
-	return 0;
+	return -1;
     iternext = *it->ob_type->tp_iternext;
 
     /* Run the iterator to exhaustion */
@@ -151,6 +151,7 @@
 
 	/* Interpret it as an int (__index__) */
 	value = PyNumber_Index(item);
+	Py_DECREF(item);
 	if (value == -1 && PyErr_Occurred())
 	    goto error;
 


More information about the Python-3000-checkins mailing list