Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 1 | """Unit tests for the bytes type.""" |
| 2 | |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 3 | import os |
| 4 | import re |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 5 | import sys |
Guido van Rossum | 0ad0812 | 2007-04-11 04:37:43 +0000 | [diff] [blame] | 6 | import pickle |
| 7 | import cPickle |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 8 | import tempfile |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 9 | import unittest |
| 10 | import test.test_support |
Georg Brandl | c788554 | 2007-03-06 19:16:20 +0000 | [diff] [blame] | 11 | import test.string_tests |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 12 | |
| 13 | |
| 14 | class BytesTest(unittest.TestCase): |
| 15 | |
| 16 | def test_basics(self): |
| 17 | b = bytes() |
| 18 | self.assertEqual(type(b), bytes) |
| 19 | self.assertEqual(b.__class__, bytes) |
| 20 | |
| 21 | def test_empty_sequence(self): |
| 22 | b = bytes() |
| 23 | self.assertEqual(len(b), 0) |
| 24 | self.assertRaises(IndexError, lambda: b[0]) |
| 25 | self.assertRaises(IndexError, lambda: b[1]) |
| 26 | self.assertRaises(IndexError, lambda: b[sys.maxint]) |
| 27 | self.assertRaises(IndexError, lambda: b[sys.maxint+1]) |
| 28 | self.assertRaises(IndexError, lambda: b[10**100]) |
| 29 | self.assertRaises(IndexError, lambda: b[-1]) |
| 30 | self.assertRaises(IndexError, lambda: b[-2]) |
| 31 | self.assertRaises(IndexError, lambda: b[-sys.maxint]) |
| 32 | self.assertRaises(IndexError, lambda: b[-sys.maxint-1]) |
| 33 | self.assertRaises(IndexError, lambda: b[-sys.maxint-2]) |
| 34 | self.assertRaises(IndexError, lambda: b[-10**100]) |
| 35 | |
| 36 | def test_from_list(self): |
| 37 | ints = list(range(256)) |
| 38 | b = bytes(i for i in ints) |
| 39 | self.assertEqual(len(b), 256) |
| 40 | self.assertEqual(list(b), ints) |
| 41 | |
| 42 | def test_from_index(self): |
| 43 | class C: |
| 44 | def __init__(self, i=0): |
| 45 | self.i = i |
| 46 | def __index__(self): |
| 47 | return self.i |
| 48 | b = bytes([C(), C(1), C(254), C(255)]) |
| 49 | self.assertEqual(list(b), [0, 1, 254, 255]) |
Guido van Rossum | e06b6b8 | 2006-04-23 07:43:54 +0000 | [diff] [blame] | 50 | self.assertRaises(ValueError, bytes, [C(-1)]) |
| 51 | self.assertRaises(ValueError, bytes, [C(256)]) |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 52 | |
| 53 | def test_constructor_type_errors(self): |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 54 | self.assertRaises(TypeError, bytes, 0.0) |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 55 | class C: |
| 56 | pass |
Guido van Rossum | e06b6b8 | 2006-04-23 07:43:54 +0000 | [diff] [blame] | 57 | self.assertRaises(TypeError, bytes, ["0"]) |
| 58 | self.assertRaises(TypeError, bytes, [0.0]) |
| 59 | self.assertRaises(TypeError, bytes, [None]) |
| 60 | self.assertRaises(TypeError, bytes, [C()]) |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 61 | |
| 62 | def test_constructor_value_errors(self): |
Guido van Rossum | e06b6b8 | 2006-04-23 07:43:54 +0000 | [diff] [blame] | 63 | self.assertRaises(ValueError, bytes, [-1]) |
| 64 | self.assertRaises(ValueError, bytes, [-sys.maxint]) |
| 65 | self.assertRaises(ValueError, bytes, [-sys.maxint-1]) |
Thomas Wouters | d204a71 | 2006-08-22 13:41:17 +0000 | [diff] [blame] | 66 | self.assertRaises(ValueError, bytes, [-sys.maxint-2]) |
| 67 | self.assertRaises(ValueError, bytes, [-10**100]) |
Guido van Rossum | e06b6b8 | 2006-04-23 07:43:54 +0000 | [diff] [blame] | 68 | self.assertRaises(ValueError, bytes, [256]) |
| 69 | self.assertRaises(ValueError, bytes, [257]) |
| 70 | self.assertRaises(ValueError, bytes, [sys.maxint]) |
Thomas Wouters | d204a71 | 2006-08-22 13:41:17 +0000 | [diff] [blame] | 71 | self.assertRaises(ValueError, bytes, [sys.maxint+1]) |
| 72 | self.assertRaises(ValueError, bytes, [10**100]) |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 73 | |
| 74 | def test_repr(self): |
Georg Brandl | ee91be4 | 2007-02-24 19:41:35 +0000 | [diff] [blame] | 75 | self.assertEqual(repr(bytes()), "b''") |
Guido van Rossum | 57b93ad | 2007-05-08 19:09:34 +0000 | [diff] [blame] | 76 | self.assertEqual(repr(bytes([0])), "b'\\x00'") |
| 77 | self.assertEqual(repr(bytes([0, 1, 254, 255])), |
| 78 | "b'\\x00\\x01\\xfe\\xff'") |
Georg Brandl | ee91be4 | 2007-02-24 19:41:35 +0000 | [diff] [blame] | 79 | self.assertEqual(repr(bytes('abc')), "b'abc'") |
| 80 | self.assertEqual(repr(bytes("'")), "b'\\''") |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 81 | |
| 82 | def test_compare(self): |
| 83 | b1 = bytes([1, 2, 3]) |
| 84 | b2 = bytes([1, 2, 3]) |
| 85 | b3 = bytes([1, 3]) |
| 86 | |
Guido van Rossum | e61fd5b | 2007-07-11 12:20:59 +0000 | [diff] [blame^] | 87 | self.assertEqual(b1, b2) |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 88 | self.failUnless(b2 != b3) |
| 89 | self.failUnless(b1 <= b2) |
| 90 | self.failUnless(b1 <= b3) |
| 91 | self.failUnless(b1 < b3) |
| 92 | self.failUnless(b1 >= b2) |
| 93 | self.failUnless(b3 >= b2) |
| 94 | self.failUnless(b3 > b2) |
| 95 | |
| 96 | self.failIf(b1 != b2) |
| 97 | self.failIf(b2 == b3) |
| 98 | self.failIf(b1 > b2) |
| 99 | self.failIf(b1 > b3) |
| 100 | self.failIf(b1 >= b3) |
| 101 | self.failIf(b1 < b2) |
| 102 | self.failIf(b3 < b2) |
| 103 | self.failIf(b3 <= b2) |
| 104 | |
Guido van Rossum | 343e97f | 2007-04-09 00:43:24 +0000 | [diff] [blame] | 105 | def test_compare_to_str(self): |
Guido van Rossum | 4355a47 | 2007-05-04 05:00:04 +0000 | [diff] [blame] | 106 | self.assertEqual(b"abc" == str8("abc"), True) |
| 107 | self.assertEqual(b"ab" != str8("abc"), True) |
| 108 | self.assertEqual(b"ab" <= str8("abc"), True) |
| 109 | self.assertEqual(b"ab" < str8("abc"), True) |
| 110 | self.assertEqual(b"abc" >= str8("ab"), True) |
| 111 | self.assertEqual(b"abc" > str8("ab"), True) |
Guido van Rossum | 343e97f | 2007-04-09 00:43:24 +0000 | [diff] [blame] | 112 | |
Guido van Rossum | 4355a47 | 2007-05-04 05:00:04 +0000 | [diff] [blame] | 113 | self.assertEqual(b"abc" != str8("abc"), False) |
| 114 | self.assertEqual(b"ab" == str8("abc"), False) |
| 115 | self.assertEqual(b"ab" > str8("abc"), False) |
| 116 | self.assertEqual(b"ab" >= str8("abc"), False) |
| 117 | self.assertEqual(b"abc" < str8("ab"), False) |
| 118 | self.assertEqual(b"abc" <= str8("ab"), False) |
Guido van Rossum | 343e97f | 2007-04-09 00:43:24 +0000 | [diff] [blame] | 119 | |
Guido van Rossum | 4355a47 | 2007-05-04 05:00:04 +0000 | [diff] [blame] | 120 | self.assertEqual(str8("abc") == b"abc", True) |
| 121 | self.assertEqual(str8("ab") != b"abc", True) |
| 122 | self.assertEqual(str8("ab") <= b"abc", True) |
| 123 | self.assertEqual(str8("ab") < b"abc", True) |
| 124 | self.assertEqual(str8("abc") >= b"ab", True) |
| 125 | self.assertEqual(str8("abc") > b"ab", True) |
Guido van Rossum | ebea9be | 2007-04-09 00:49:13 +0000 | [diff] [blame] | 126 | |
Guido van Rossum | 4355a47 | 2007-05-04 05:00:04 +0000 | [diff] [blame] | 127 | self.assertEqual(str8("abc") != b"abc", False) |
| 128 | self.assertEqual(str8("ab") == b"abc", False) |
| 129 | self.assertEqual(str8("ab") > b"abc", False) |
| 130 | self.assertEqual(str8("ab") >= b"abc", False) |
| 131 | self.assertEqual(str8("abc") < b"ab", False) |
| 132 | self.assertEqual(str8("abc") <= b"ab", False) |
Guido van Rossum | ebea9be | 2007-04-09 00:49:13 +0000 | [diff] [blame] | 133 | |
Guido van Rossum | 4355a47 | 2007-05-04 05:00:04 +0000 | [diff] [blame] | 134 | # Bytes should never compare equal to Unicode! |
Guido van Rossum | ebea9be | 2007-04-09 00:49:13 +0000 | [diff] [blame] | 135 | # Test this for all expected byte orders and Unicode character sizes |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 136 | self.assertEqual(b"\0a\0b\0c" == "abc", False) |
| 137 | self.assertEqual(b"\0\0\0a\0\0\0b\0\0\0c" == "abc", False) |
| 138 | self.assertEqual(b"a\0b\0c\0" == "abc", False) |
| 139 | self.assertEqual(b"a\0\0\0b\0\0\0c\0\0\0" == "abc", False) |
Guido van Rossum | ebea9be | 2007-04-09 00:49:13 +0000 | [diff] [blame] | 140 | |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 141 | def test_nohash(self): |
| 142 | self.assertRaises(TypeError, hash, bytes()) |
| 143 | |
| 144 | def test_doc(self): |
| 145 | self.failUnless(bytes.__doc__ != None) |
| 146 | self.failUnless(bytes.__doc__.startswith("bytes(")) |
| 147 | |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 148 | def test_buffer_api(self): |
Guido van Rossum | 75d6f1a | 2007-05-24 17:52:00 +0000 | [diff] [blame] | 149 | short_sample = b"Hello world\n" |
| 150 | sample = short_sample + b"x"*(20 - len(short_sample)) |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 151 | tfn = tempfile.mktemp() |
| 152 | try: |
| 153 | # Prepare |
| 154 | with open(tfn, "wb") as f: |
| 155 | f.write(short_sample) |
| 156 | # Test readinto |
| 157 | with open(tfn, "rb") as f: |
Guido van Rossum | 75d6f1a | 2007-05-24 17:52:00 +0000 | [diff] [blame] | 158 | b = b"x"*20 |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 159 | n = f.readinto(b) |
| 160 | self.assertEqual(n, len(short_sample)) |
Guido van Rossum | c1f779c | 2007-07-03 08:25:58 +0000 | [diff] [blame] | 161 | self.assertEqual(list(b), list(sample)) |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 162 | # Test writing in binary mode |
| 163 | with open(tfn, "wb") as f: |
| 164 | f.write(b) |
| 165 | with open(tfn, "rb") as f: |
| 166 | self.assertEqual(f.read(), sample) |
Guido van Rossum | 13633bb | 2007-04-13 18:42:35 +0000 | [diff] [blame] | 167 | # Text mode is ambiguous; don't test |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 168 | finally: |
| 169 | try: |
| 170 | os.remove(tfn) |
| 171 | except os.error: |
| 172 | pass |
| 173 | |
| 174 | def test_reversed(self): |
Guido van Rossum | c1f779c | 2007-07-03 08:25:58 +0000 | [diff] [blame] | 175 | input = list(map(ord, "Hello")) |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 176 | b = bytes(input) |
| 177 | output = list(reversed(b)) |
| 178 | input.reverse() |
| 179 | self.assertEqual(output, input) |
| 180 | |
Neal Norwitz | 6968b05 | 2007-02-27 19:02:19 +0000 | [diff] [blame] | 181 | def test_reverse(self): |
| 182 | b = b'hello' |
| 183 | self.assertEqual(b.reverse(), None) |
| 184 | self.assertEqual(b, b'olleh') |
| 185 | b = b'hello1' # test even number of items |
| 186 | b.reverse() |
| 187 | self.assertEqual(b, b'1olleh') |
| 188 | b = bytes() |
| 189 | b.reverse() |
| 190 | self.assertFalse(b) |
| 191 | |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 192 | def test_getslice(self): |
| 193 | def by(s): |
| 194 | return bytes(map(ord, s)) |
| 195 | b = by("Hello, world") |
| 196 | |
| 197 | self.assertEqual(b[:5], by("Hello")) |
| 198 | self.assertEqual(b[1:5], by("ello")) |
| 199 | self.assertEqual(b[5:7], by(", ")) |
| 200 | self.assertEqual(b[7:], by("world")) |
| 201 | self.assertEqual(b[7:12], by("world")) |
| 202 | self.assertEqual(b[7:100], by("world")) |
| 203 | |
| 204 | self.assertEqual(b[:-7], by("Hello")) |
| 205 | self.assertEqual(b[-11:-7], by("ello")) |
| 206 | self.assertEqual(b[-7:-5], by(", ")) |
| 207 | self.assertEqual(b[-5:], by("world")) |
| 208 | self.assertEqual(b[-5:12], by("world")) |
| 209 | self.assertEqual(b[-5:100], by("world")) |
| 210 | self.assertEqual(b[-100:5], by("Hello")) |
| 211 | |
Thomas Wouters | 376446d | 2006-12-19 08:30:14 +0000 | [diff] [blame] | 212 | def test_extended_getslice(self): |
| 213 | # Test extended slicing by comparing with list slicing. |
| 214 | L = list(range(255)) |
| 215 | b = bytes(L) |
| 216 | indices = (0, None, 1, 3, 19, 100, -1, -2, -31, -100) |
| 217 | for start in indices: |
| 218 | for stop in indices: |
| 219 | # Skip step 0 (invalid) |
| 220 | for step in indices[1:]: |
| 221 | self.assertEqual(b[start:stop:step], bytes(L[start:stop:step])) |
Guido van Rossum | ad7d8d1 | 2007-04-13 01:39:34 +0000 | [diff] [blame] | 222 | |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 223 | def test_regexps(self): |
| 224 | def by(s): |
| 225 | return bytes(map(ord, s)) |
| 226 | b = by("Hello, world") |
| 227 | self.assertEqual(re.findall(r"\w+", b), [by("Hello"), by("world")]) |
| 228 | |
| 229 | def test_setitem(self): |
| 230 | b = bytes([1, 2, 3]) |
| 231 | b[1] = 100 |
| 232 | self.assertEqual(b, bytes([1, 100, 3])) |
| 233 | b[-1] = 200 |
| 234 | self.assertEqual(b, bytes([1, 100, 200])) |
| 235 | class C: |
| 236 | def __init__(self, i=0): |
| 237 | self.i = i |
| 238 | def __index__(self): |
| 239 | return self.i |
| 240 | b[0] = C(10) |
| 241 | self.assertEqual(b, bytes([10, 100, 200])) |
| 242 | try: |
| 243 | b[3] = 0 |
| 244 | self.fail("Didn't raise IndexError") |
| 245 | except IndexError: |
| 246 | pass |
| 247 | try: |
| 248 | b[-10] = 0 |
| 249 | self.fail("Didn't raise IndexError") |
| 250 | except IndexError: |
| 251 | pass |
| 252 | try: |
| 253 | b[0] = 256 |
| 254 | self.fail("Didn't raise ValueError") |
| 255 | except ValueError: |
| 256 | pass |
| 257 | try: |
| 258 | b[0] = C(-1) |
| 259 | self.fail("Didn't raise ValueError") |
| 260 | except ValueError: |
| 261 | pass |
| 262 | try: |
| 263 | b[0] = None |
| 264 | self.fail("Didn't raise TypeError") |
| 265 | except TypeError: |
| 266 | pass |
| 267 | |
| 268 | def test_delitem(self): |
| 269 | b = bytes(range(10)) |
| 270 | del b[0] |
| 271 | self.assertEqual(b, bytes(range(1, 10))) |
| 272 | del b[-1] |
| 273 | self.assertEqual(b, bytes(range(1, 9))) |
| 274 | del b[4] |
| 275 | self.assertEqual(b, bytes([1, 2, 3, 4, 6, 7, 8])) |
| 276 | |
| 277 | def test_setslice(self): |
| 278 | b = bytes(range(10)) |
| 279 | self.assertEqual(list(b), list(range(10))) |
| 280 | |
| 281 | b[0:5] = bytes([1, 1, 1, 1, 1]) |
| 282 | self.assertEqual(b, bytes([1, 1, 1, 1, 1, 5, 6, 7, 8, 9])) |
| 283 | |
| 284 | del b[0:-5] |
| 285 | self.assertEqual(b, bytes([5, 6, 7, 8, 9])) |
| 286 | |
| 287 | b[0:0] = bytes([0, 1, 2, 3, 4]) |
| 288 | self.assertEqual(b, bytes(range(10))) |
| 289 | |
| 290 | b[-7:-3] = bytes([100, 101]) |
| 291 | self.assertEqual(b, bytes([0, 1, 2, 100, 101, 7, 8, 9])) |
| 292 | |
| 293 | b[3:5] = [3, 4, 5, 6] |
| 294 | self.assertEqual(b, bytes(range(10))) |
Guido van Rossum | ad7d8d1 | 2007-04-13 01:39:34 +0000 | [diff] [blame] | 295 | |
Thomas Wouters | 9a6e62b | 2006-08-23 23:20:29 +0000 | [diff] [blame] | 296 | b[3:0] = [42, 42, 42] |
| 297 | self.assertEqual(b, bytes([0, 1, 2, 42, 42, 42, 3, 4, 5, 6, 7, 8, 9])) |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 298 | |
Thomas Wouters | 376446d | 2006-12-19 08:30:14 +0000 | [diff] [blame] | 299 | def test_extended_set_del_slice(self): |
| 300 | indices = (0, None, 1, 3, 19, 300, -1, -2, -31, -300) |
| 301 | for start in indices: |
| 302 | for stop in indices: |
| 303 | # Skip invalid step 0 |
| 304 | for step in indices[1:]: |
| 305 | L = list(range(255)) |
| 306 | b = bytes(L) |
| 307 | # Make sure we have a slice of exactly the right length, |
| 308 | # but with different data. |
| 309 | data = L[start:stop:step] |
| 310 | data.reverse() |
| 311 | L[start:stop:step] = data |
| 312 | b[start:stop:step] = data |
| 313 | self.assertEquals(b, bytes(L)) |
Guido van Rossum | ad7d8d1 | 2007-04-13 01:39:34 +0000 | [diff] [blame] | 314 | |
Thomas Wouters | 376446d | 2006-12-19 08:30:14 +0000 | [diff] [blame] | 315 | del L[start:stop:step] |
| 316 | del b[start:stop:step] |
| 317 | self.assertEquals(b, bytes(L)) |
| 318 | |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 319 | def test_setslice_trap(self): |
| 320 | # This test verifies that we correctly handle assigning self |
| 321 | # to a slice of self (the old Lambert Meertens trap). |
| 322 | b = bytes(range(256)) |
| 323 | b[8:] = b |
| 324 | self.assertEqual(b, bytes(list(range(8)) + list(range(256)))) |
| 325 | |
| 326 | def test_encoding(self): |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 327 | sample = "Hello world\n\u1234\u5678\u9abc\udef0" |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 328 | for enc in ("utf8", "utf16"): |
| 329 | b = bytes(sample, enc) |
Guido van Rossum | 4355a47 | 2007-05-04 05:00:04 +0000 | [diff] [blame] | 330 | self.assertEqual(b, bytes(sample.encode(enc))) |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 331 | self.assertRaises(UnicodeEncodeError, bytes, sample, "latin1") |
| 332 | b = bytes(sample, "latin1", "ignore") |
| 333 | self.assertEqual(b, bytes(sample[:-4])) |
| 334 | |
| 335 | def test_decode(self): |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 336 | sample = "Hello world\n\u1234\u5678\u9abc\def0\def0" |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 337 | for enc in ("utf8", "utf16"): |
| 338 | b = bytes(sample, enc) |
| 339 | self.assertEqual(b.decode(enc), sample) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 340 | sample = "Hello world\n\x80\x81\xfe\xff" |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 341 | b = bytes(sample, "latin1") |
| 342 | self.assertRaises(UnicodeDecodeError, b.decode, "utf8") |
| 343 | self.assertEqual(b.decode("utf8", "ignore"), "Hello world\n") |
| 344 | |
| 345 | def test_from_buffer(self): |
Guido van Rossum | 4355a47 | 2007-05-04 05:00:04 +0000 | [diff] [blame] | 346 | sample = str8("Hello world\n\x80\x81\xfe\xff") |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 347 | buf = buffer(sample) |
| 348 | b = bytes(buf) |
| 349 | self.assertEqual(b, bytes(map(ord, sample))) |
| 350 | |
| 351 | def test_to_str(self): |
| 352 | sample = "Hello world\n\x80\x81\xfe\xff" |
| 353 | b = bytes(sample) |
| 354 | self.assertEqual(str(b), sample) |
| 355 | |
| 356 | def test_from_int(self): |
| 357 | b = bytes(0) |
| 358 | self.assertEqual(b, bytes()) |
| 359 | b = bytes(10) |
| 360 | self.assertEqual(b, bytes([0]*10)) |
| 361 | b = bytes(10000) |
| 362 | self.assertEqual(b, bytes([0]*10000)) |
| 363 | |
| 364 | def test_concat(self): |
| 365 | b1 = bytes("abc") |
| 366 | b2 = bytes("def") |
| 367 | self.assertEqual(b1 + b2, bytes("abcdef")) |
Guido van Rossum | 4355a47 | 2007-05-04 05:00:04 +0000 | [diff] [blame] | 368 | self.assertEqual(b1 + str8("def"), bytes("abcdef")) |
| 369 | self.assertEqual(str8("def") + b1, bytes("defabc")) |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 370 | self.assertRaises(TypeError, lambda: b1 + "def") |
| 371 | self.assertRaises(TypeError, lambda: "abc" + b2) |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 372 | |
| 373 | def test_repeat(self): |
| 374 | b = bytes("abc") |
| 375 | self.assertEqual(b * 3, bytes("abcabcabc")) |
| 376 | self.assertEqual(b * 0, bytes()) |
| 377 | self.assertEqual(b * -1, bytes()) |
| 378 | self.assertRaises(TypeError, lambda: b * 3.14) |
| 379 | self.assertRaises(TypeError, lambda: 3.14 * b) |
| 380 | self.assertRaises(MemoryError, lambda: b * sys.maxint) |
Guido van Rossum | 13e5721 | 2006-04-27 22:54:26 +0000 | [diff] [blame] | 381 | |
| 382 | def test_repeat_1char(self): |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 383 | self.assertEqual(bytes('x')*100, bytes('x'*100)) |
| 384 | |
Guido van Rossum | 13e5721 | 2006-04-27 22:54:26 +0000 | [diff] [blame] | 385 | def test_iconcat(self): |
| 386 | b = bytes("abc") |
| 387 | b1 = b |
| 388 | b += bytes("def") |
| 389 | self.assertEqual(b, bytes("abcdef")) |
| 390 | self.assertEqual(b, b1) |
| 391 | self.failUnless(b is b1) |
Guido van Rossum | 4355a47 | 2007-05-04 05:00:04 +0000 | [diff] [blame] | 392 | b += str8("xyz") |
Guido van Rossum | ad7d8d1 | 2007-04-13 01:39:34 +0000 | [diff] [blame] | 393 | self.assertEqual(b, b"abcdefxyz") |
| 394 | try: |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 395 | b += "" |
Guido van Rossum | ad7d8d1 | 2007-04-13 01:39:34 +0000 | [diff] [blame] | 396 | except TypeError: |
| 397 | pass |
| 398 | else: |
| 399 | self.fail("bytes += unicode didn't raise TypeError") |
Guido van Rossum | 13e5721 | 2006-04-27 22:54:26 +0000 | [diff] [blame] | 400 | |
| 401 | def test_irepeat(self): |
| 402 | b = bytes("abc") |
| 403 | b1 = b |
| 404 | b *= 3 |
| 405 | self.assertEqual(b, bytes("abcabcabc")) |
| 406 | self.assertEqual(b, b1) |
| 407 | self.failUnless(b is b1) |
| 408 | |
| 409 | def test_irepeat_1char(self): |
| 410 | b = bytes("x") |
| 411 | b1 = b |
| 412 | b *= 100 |
| 413 | self.assertEqual(b, bytes("x"*100)) |
| 414 | self.assertEqual(b, b1) |
| 415 | self.failUnless(b is b1) |
| 416 | |
| 417 | def test_contains(self): |
| 418 | b = bytes("abc") |
| 419 | self.failUnless(ord('a') in b) |
Guido van Rossum | e2a383d | 2007-01-15 16:59:06 +0000 | [diff] [blame] | 420 | self.failUnless(int(ord('a')) in b) |
Guido van Rossum | 13e5721 | 2006-04-27 22:54:26 +0000 | [diff] [blame] | 421 | self.failIf(200 in b) |
Guido van Rossum | e2a383d | 2007-01-15 16:59:06 +0000 | [diff] [blame] | 422 | self.failIf(200 in b) |
Guido van Rossum | 13e5721 | 2006-04-27 22:54:26 +0000 | [diff] [blame] | 423 | self.assertRaises(ValueError, lambda: 300 in b) |
| 424 | self.assertRaises(ValueError, lambda: -1 in b) |
| 425 | self.assertRaises(TypeError, lambda: None in b) |
| 426 | self.assertRaises(TypeError, lambda: float(ord('a')) in b) |
| 427 | self.assertRaises(TypeError, lambda: "a" in b) |
| 428 | self.failUnless(bytes("") in b) |
| 429 | self.failUnless(bytes("a") in b) |
| 430 | self.failUnless(bytes("b") in b) |
| 431 | self.failUnless(bytes("c") in b) |
| 432 | self.failUnless(bytes("ab") in b) |
| 433 | self.failUnless(bytes("bc") in b) |
| 434 | self.failUnless(bytes("abc") in b) |
| 435 | self.failIf(bytes("ac") in b) |
| 436 | self.failIf(bytes("d") in b) |
| 437 | self.failIf(bytes("dab") in b) |
| 438 | self.failIf(bytes("abd") in b) |
| 439 | |
Guido van Rossum | 2018831 | 2006-05-05 15:15:40 +0000 | [diff] [blame] | 440 | def test_alloc(self): |
| 441 | b = bytes() |
| 442 | alloc = b.__alloc__() |
| 443 | self.assert_(alloc >= 0) |
| 444 | seq = [alloc] |
| 445 | for i in range(100): |
| 446 | b += bytes("x") |
| 447 | alloc = b.__alloc__() |
| 448 | self.assert_(alloc >= len(b)) |
| 449 | if alloc not in seq: |
| 450 | seq.append(alloc) |
Guido van Rossum | 08e8b7a | 2006-05-26 19:16:09 +0000 | [diff] [blame] | 451 | #print seq |
Guido van Rossum | 2018831 | 2006-05-05 15:15:40 +0000 | [diff] [blame] | 452 | |
Georg Brandl | 0b9b9e0 | 2007-02-27 08:40:54 +0000 | [diff] [blame] | 453 | def test_fromhex(self): |
| 454 | self.assertRaises(TypeError, bytes.fromhex) |
| 455 | self.assertRaises(TypeError, bytes.fromhex, 1) |
| 456 | self.assertEquals(bytes.fromhex(''), bytes()) |
| 457 | b = bytes([0x1a, 0x2b, 0x30]) |
| 458 | self.assertEquals(bytes.fromhex('1a2B30'), b) |
| 459 | self.assertEquals(bytes.fromhex(' 1A 2B 30 '), b) |
Guido van Rossum | 4355a47 | 2007-05-04 05:00:04 +0000 | [diff] [blame] | 460 | self.assertEquals(bytes.fromhex(buffer(b'')), bytes()) |
| 461 | self.assertEquals(bytes.fromhex(buffer(b'0000')), bytes([0, 0])) |
Georg Brandl | 0b9b9e0 | 2007-02-27 08:40:54 +0000 | [diff] [blame] | 462 | self.assertRaises(ValueError, bytes.fromhex, 'a') |
| 463 | self.assertRaises(ValueError, bytes.fromhex, 'rt') |
| 464 | self.assertRaises(ValueError, bytes.fromhex, '1a b cd') |
| 465 | self.assertRaises(ValueError, bytes.fromhex, '\x00') |
| 466 | self.assertRaises(ValueError, bytes.fromhex, '12 \x00 34') |
| 467 | |
Guido van Rossum | 2018831 | 2006-05-05 15:15:40 +0000 | [diff] [blame] | 468 | def test_join(self): |
Guido van Rossum | cd6ae68 | 2007-05-09 19:52:16 +0000 | [diff] [blame] | 469 | self.assertEqual(b"".join([]), bytes()) |
| 470 | self.assertEqual(b"".join([bytes()]), bytes()) |
Guido van Rossum | 2018831 | 2006-05-05 15:15:40 +0000 | [diff] [blame] | 471 | for part in [("abc",), ("a", "bc"), ("ab", "c"), ("a", "b", "c")]: |
Guido van Rossum | c1f779c | 2007-07-03 08:25:58 +0000 | [diff] [blame] | 472 | lst = list(map(bytes, part)) |
Guido van Rossum | cd6ae68 | 2007-05-09 19:52:16 +0000 | [diff] [blame] | 473 | self.assertEqual(b"".join(lst), bytes("abc")) |
| 474 | self.assertEqual(b"".join(tuple(lst)), bytes("abc")) |
| 475 | self.assertEqual(b"".join(iter(lst)), bytes("abc")) |
| 476 | self.assertEqual(b".".join([b"ab", b"cd"]), b"ab.cd") |
Guido van Rossum | 2018831 | 2006-05-05 15:15:40 +0000 | [diff] [blame] | 477 | # XXX more... |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 478 | |
| 479 | def test_literal(self): |
| 480 | tests = [ |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 481 | (b"Wonderful spam", "Wonderful spam"), |
| 482 | (br"Wonderful spam too", "Wonderful spam too"), |
| 483 | (b"\xaa\x00\000\200", "\xaa\x00\000\200"), |
| 484 | (br"\xaa\x00\000\200", r"\xaa\x00\000\200"), |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 485 | ] |
| 486 | for b, s in tests: |
| 487 | self.assertEqual(b, bytes(s, 'latin-1')) |
| 488 | for c in range(128, 256): |
| 489 | self.assertRaises(SyntaxError, eval, |
| 490 | 'b"%s"' % chr(c)) |
Guido van Rossum | 2018831 | 2006-05-05 15:15:40 +0000 | [diff] [blame] | 491 | |
Neal Norwitz | 6968b05 | 2007-02-27 19:02:19 +0000 | [diff] [blame] | 492 | def test_extend(self): |
| 493 | orig = b'hello' |
| 494 | a = bytes(orig) |
| 495 | a.extend(a) |
| 496 | self.assertEqual(a, orig + orig) |
| 497 | self.assertEqual(a[5:], orig) |
Guido van Rossum | ad7d8d1 | 2007-04-13 01:39:34 +0000 | [diff] [blame] | 498 | |
Neal Norwitz | 6968b05 | 2007-02-27 19:02:19 +0000 | [diff] [blame] | 499 | def test_remove(self): |
| 500 | b = b'hello' |
| 501 | b.remove(ord('l')) |
| 502 | self.assertEqual(b, b'helo') |
| 503 | b.remove(ord('l')) |
| 504 | self.assertEqual(b, b'heo') |
| 505 | self.assertRaises(ValueError, lambda: b.remove(ord('l'))) |
| 506 | self.assertRaises(ValueError, lambda: b.remove(400)) |
| 507 | self.assertRaises(ValueError, lambda: b.remove('e')) |
| 508 | # remove first and last |
| 509 | b.remove(ord('o')) |
| 510 | b.remove(ord('h')) |
| 511 | self.assertEqual(b, b'e') |
| 512 | |
| 513 | def test_pop(self): |
| 514 | b = b'world' |
| 515 | self.assertEqual(b.pop(), ord('d')) |
| 516 | self.assertEqual(b.pop(0), ord('w')) |
| 517 | self.assertEqual(b.pop(-2), ord('r')) |
| 518 | self.assertRaises(IndexError, lambda: b.pop(10)) |
| 519 | self.assertRaises(OverflowError, lambda: bytes().pop()) |
| 520 | |
| 521 | def test_nosort(self): |
| 522 | self.assertRaises(AttributeError, lambda: bytes().sort()) |
| 523 | |
| 524 | def test_index(self): |
| 525 | b = b'parrot' |
| 526 | self.assertEqual(b.index('p'), 0) |
| 527 | self.assertEqual(b.index('rr'), 2) |
| 528 | self.assertEqual(b.index('t'), 5) |
| 529 | self.assertRaises(ValueError, lambda: b.index('w')) |
| 530 | |
| 531 | def test_count(self): |
| 532 | b = b'mississippi' |
| 533 | self.assertEqual(b.count('i'), 4) |
| 534 | self.assertEqual(b.count('ss'), 2) |
| 535 | self.assertEqual(b.count('w'), 0) |
| 536 | |
| 537 | def test_append(self): |
| 538 | b = b'hell' |
| 539 | b.append(ord('o')) |
| 540 | self.assertEqual(b, b'hello') |
| 541 | self.assertEqual(b.append(100), None) |
| 542 | b = bytes() |
| 543 | b.append(ord('A')) |
| 544 | self.assertEqual(len(b), 1) |
| 545 | |
| 546 | def test_insert(self): |
| 547 | b = b'msssspp' |
| 548 | b.insert(1, ord('i')) |
| 549 | b.insert(4, ord('i')) |
| 550 | b.insert(-2, ord('i')) |
| 551 | b.insert(1000, ord('i')) |
| 552 | self.assertEqual(b, b'mississippi') |
| 553 | |
| 554 | def test_startswith(self): |
| 555 | b = b'hello' |
| 556 | self.assertFalse(bytes().startswith("anything")) |
| 557 | self.assertTrue(b.startswith("hello")) |
| 558 | self.assertTrue(b.startswith("hel")) |
| 559 | self.assertTrue(b.startswith("h")) |
| 560 | self.assertFalse(b.startswith("hellow")) |
| 561 | self.assertFalse(b.startswith("ha")) |
| 562 | |
| 563 | def test_endswith(self): |
| 564 | b = b'hello' |
| 565 | self.assertFalse(bytes().endswith("anything")) |
| 566 | self.assertTrue(b.endswith("hello")) |
| 567 | self.assertTrue(b.endswith("llo")) |
| 568 | self.assertTrue(b.endswith("o")) |
| 569 | self.assertFalse(b.endswith("whello")) |
| 570 | self.assertFalse(b.endswith("no")) |
| 571 | |
| 572 | def test_find(self): |
| 573 | b = b'mississippi' |
| 574 | self.assertEqual(b.find('ss'), 2) |
| 575 | self.assertEqual(b.find('ss', 3), 5) |
| 576 | self.assertEqual(b.find('ss', 1, 7), 2) |
| 577 | self.assertEqual(b.find('ss', 1, 3), -1) |
| 578 | self.assertEqual(b.find('w'), -1) |
| 579 | self.assertEqual(b.find('mississippian'), -1) |
| 580 | |
| 581 | def test_rfind(self): |
| 582 | b = b'mississippi' |
| 583 | self.assertEqual(b.rfind('ss'), 5) |
| 584 | self.assertEqual(b.rfind('ss', 3), 5) |
| 585 | self.assertEqual(b.rfind('ss', 0, 6), 2) |
| 586 | self.assertEqual(b.rfind('w'), -1) |
| 587 | self.assertEqual(b.rfind('mississippian'), -1) |
| 588 | |
| 589 | def test_index(self): |
| 590 | b = b'world' |
| 591 | self.assertEqual(b.index('w'), 0) |
| 592 | self.assertEqual(b.index('orl'), 1) |
| 593 | self.assertRaises(ValueError, lambda: b.index('worm')) |
| 594 | self.assertRaises(ValueError, lambda: b.index('ldo')) |
| 595 | |
| 596 | def test_rindex(self): |
| 597 | # XXX could be more rigorous |
| 598 | b = b'world' |
| 599 | self.assertEqual(b.rindex('w'), 0) |
| 600 | self.assertEqual(b.rindex('orl'), 1) |
| 601 | self.assertRaises(ValueError, lambda: b.rindex('worm')) |
| 602 | self.assertRaises(ValueError, lambda: b.rindex('ldo')) |
| 603 | |
| 604 | def test_replace(self): |
| 605 | b = b'mississippi' |
| 606 | self.assertEqual(b.replace('i', 'a'), b'massassappa') |
| 607 | self.assertEqual(b.replace('ss', 'x'), b'mixixippi') |
| 608 | |
| 609 | def test_translate(self): |
| 610 | b = b'hello' |
| 611 | rosetta = bytes(range(0, 256)) |
| 612 | rosetta[ord('o')] = ord('e') |
| 613 | c = b.translate(rosetta, b'l') |
| 614 | self.assertEqual(b, b'hello') |
| 615 | self.assertEqual(c, b'hee') |
| 616 | |
| 617 | def test_split(self): |
| 618 | b = b'mississippi' |
| 619 | self.assertEqual(b.split('i'), [b'm', b'ss', b'ss', b'pp', b'']) |
| 620 | self.assertEqual(b.split('ss'), [b'mi', b'i', b'ippi']) |
| 621 | self.assertEqual(b.split('w'), [b]) |
| 622 | # require an arg (no magic whitespace split) |
| 623 | self.assertRaises(TypeError, lambda: b.split()) |
| 624 | |
| 625 | def test_rsplit(self): |
| 626 | b = b'mississippi' |
| 627 | self.assertEqual(b.rsplit('i'), [b'm', b'ss', b'ss', b'pp', b'']) |
| 628 | self.assertEqual(b.rsplit('ss'), [b'mi', b'i', b'ippi']) |
| 629 | self.assertEqual(b.rsplit('w'), [b]) |
| 630 | # require an arg (no magic whitespace split) |
| 631 | self.assertRaises(TypeError, lambda: b.rsplit()) |
| 632 | |
| 633 | def test_partition(self): |
| 634 | b = b'mississippi' |
| 635 | self.assertEqual(b.partition(b'ss'), (b'mi', b'ss', b'issippi')) |
| 636 | self.assertEqual(b.rpartition(b'w'), (b'', b'', b'mississippi')) |
| 637 | |
| 638 | def test_rpartition(self): |
| 639 | b = b'mississippi' |
| 640 | self.assertEqual(b.rpartition(b'ss'), (b'missi', b'ss', b'ippi')) |
| 641 | self.assertEqual(b.rpartition(b'i'), (b'mississipp', b'i', b'')) |
| 642 | |
Guido van Rossum | 0ad0812 | 2007-04-11 04:37:43 +0000 | [diff] [blame] | 643 | def test_pickling(self): |
| 644 | for pm in pickle, cPickle: |
| 645 | for proto in range(pm.HIGHEST_PROTOCOL): |
| 646 | for b in b"", b"a", b"abc", b"\xffab\x80", b"\0\0\377\0\0": |
| 647 | ps = pm.dumps(b, proto) |
| 648 | q = pm.loads(ps) |
| 649 | self.assertEqual(b, q) |
| 650 | |
Guido van Rossum | ad7d8d1 | 2007-04-13 01:39:34 +0000 | [diff] [blame] | 651 | def test_strip(self): |
| 652 | b = b'mississippi' |
| 653 | self.assertEqual(b.strip(b'i'), b'mississipp') |
| 654 | self.assertEqual(b.strip(b'm'), b'ississippi') |
| 655 | self.assertEqual(b.strip(b'pi'), b'mississ') |
| 656 | self.assertEqual(b.strip(b'im'), b'ssissipp') |
| 657 | self.assertEqual(b.strip(b'pim'), b'ssiss') |
| 658 | |
| 659 | def test_lstrip(self): |
| 660 | b = b'mississippi' |
| 661 | self.assertEqual(b.lstrip(b'i'), b'mississippi') |
| 662 | self.assertEqual(b.lstrip(b'm'), b'ississippi') |
| 663 | self.assertEqual(b.lstrip(b'pi'), b'mississippi') |
| 664 | self.assertEqual(b.lstrip(b'im'), b'ssissippi') |
| 665 | self.assertEqual(b.lstrip(b'pim'), b'ssissippi') |
| 666 | |
| 667 | def test_rstrip(self): |
| 668 | b = b'mississippi' |
| 669 | self.assertEqual(b.rstrip(b'i'), b'mississipp') |
| 670 | self.assertEqual(b.rstrip(b'm'), b'mississippi') |
| 671 | self.assertEqual(b.rstrip(b'pi'), b'mississ') |
| 672 | self.assertEqual(b.rstrip(b'im'), b'mississipp') |
| 673 | self.assertEqual(b.rstrip(b'pim'), b'mississ') |
| 674 | |
Guido van Rossum | f9e91c9 | 2007-05-08 21:05:48 +0000 | [diff] [blame] | 675 | def test_ord(self): |
| 676 | b = b'\0A\x7f\x80\xff' |
| 677 | self.assertEqual([ord(b[i:i+1]) for i in range(len(b))], |
| 678 | [0, 65, 127, 128, 255]) |
| 679 | |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 680 | # Optimizations: |
Guido van Rossum | e06b6b8 | 2006-04-23 07:43:54 +0000 | [diff] [blame] | 681 | # __iter__? (optimization) |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 682 | # __reversed__? (optimization) |
| 683 | |
Guido van Rossum | ad7d8d1 | 2007-04-13 01:39:34 +0000 | [diff] [blame] | 684 | # XXX More string methods? (Those that don't use character properties) |
| 685 | |
Neal Norwitz | 6968b05 | 2007-02-27 19:02:19 +0000 | [diff] [blame] | 686 | # There are tests in string_tests.py that are more |
| 687 | # comprehensive for things like split, partition, etc. |
| 688 | # Unfortunately they are all bundled with tests that |
| 689 | # are not appropriate for bytes |
Guido van Rossum | e06b6b8 | 2006-04-23 07:43:54 +0000 | [diff] [blame] | 690 | |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 691 | |
Georg Brandl | c788554 | 2007-03-06 19:16:20 +0000 | [diff] [blame] | 692 | class BytesAsStringTest(test.string_tests.BaseTest): |
| 693 | type2test = bytes |
| 694 | |
| 695 | def checkequal(self, result, object, methodname, *args): |
| 696 | object = bytes(object) |
| 697 | realresult = getattr(bytes, methodname)(object, *args) |
| 698 | self.assertEqual( |
| 699 | self.fixtype(result), |
| 700 | realresult |
| 701 | ) |
| 702 | |
| 703 | def checkraises(self, exc, object, methodname, *args): |
| 704 | object = bytes(object) |
| 705 | self.assertRaises( |
| 706 | exc, |
| 707 | getattr(bytes, methodname), |
| 708 | object, |
| 709 | *args |
Guido van Rossum | ad7d8d1 | 2007-04-13 01:39:34 +0000 | [diff] [blame] | 710 | ) |
Georg Brandl | c788554 | 2007-03-06 19:16:20 +0000 | [diff] [blame] | 711 | |
| 712 | # Currently the bytes containment testing uses a single integer |
| 713 | # value. This may not be the final design, but until then the |
| 714 | # bytes section with in a bytes containment not valid |
| 715 | def test_contains(self): |
| 716 | pass |
| 717 | def test_find(self): |
| 718 | pass |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 719 | def test_expandtabs(self): |
| 720 | pass |
| 721 | def test_upper(self): |
| 722 | pass |
| 723 | def test_lower(self): |
| 724 | pass |
Georg Brandl | c788554 | 2007-03-06 19:16:20 +0000 | [diff] [blame] | 725 | |
| 726 | |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 727 | def test_main(): |
Thomas Wouters | 5f6f27d | 2006-04-23 00:19:58 +0000 | [diff] [blame] | 728 | test.test_support.run_unittest(BytesTest) |
Georg Brandl | c788554 | 2007-03-06 19:16:20 +0000 | [diff] [blame] | 729 | test.test_support.run_unittest(BytesAsStringTest) |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 730 | |
| 731 | |
| 732 | if __name__ == "__main__": |
Guido van Rossum | 4355a47 | 2007-05-04 05:00:04 +0000 | [diff] [blame] | 733 | ##test_main() |
| 734 | unittest.main() |