summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2006-04-23 07:43:54 (GMT)
committerGuido van Rossum <guido@python.org>2006-04-23 07:43:54 (GMT)
commite06b6b8ff5a380f5e107f2d28f23853bfe20021e (patch)
tree6e28f5973de58276cd682c76dc997a472e4beb44 /Lib
parent5f6f27de4d9f7cb260e243cf517cec629e54e985 (diff)
downloadcpython-e06b6b8ff5a380f5e107f2d28f23853bfe20021e.zip
cpython-e06b6b8ff5a380f5e107f2d28f23853bfe20021e.tar.gz
cpython-e06b6b8ff5a380f5e107f2d28f23853bfe20021e.tar.bz2
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).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_bytes.py64
1 files changed, 48 insertions, 16 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index fc911ac..1ba5e11 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -41,28 +41,29 @@ class BytesTest(unittest.TestCase):
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 @@ class BytesTest(unittest.TestCase):
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)