Walter Dörwald | 1dde95d | 2003-12-08 11:38:45 +0000 | [diff] [blame^] | 1 | import unittest |
| 2 | from test import test_support, seq_tests |
| 3 | |
| 4 | class TupleTest(seq_tests.CommonTest): |
| 5 | type2test = tuple |
| 6 | |
| 7 | def test_constructors(self): |
| 8 | super(TupleTest, self).test_len() |
| 9 | # calling built-in types without argument must return empty |
| 10 | self.assertEqual(tuple(), ()) |
| 11 | |
| 12 | def test_truth(self): |
| 13 | super(TupleTest, self).test_truth() |
| 14 | self.assert_(not ()) |
| 15 | self.assert_((42, )) |
| 16 | |
| 17 | def test_len(self): |
| 18 | super(TupleTest, self).test_len() |
| 19 | self.assertEqual(len(()), 0) |
| 20 | self.assertEqual(len((0,)), 1) |
| 21 | self.assertEqual(len((0, 1, 2)), 3) |
| 22 | |
| 23 | def test_iadd(self): |
| 24 | super(TupleTest, self).test_iadd() |
| 25 | u = (0, 1) |
| 26 | u2 = u |
| 27 | u += (2, 3) |
| 28 | self.assert_(u is not u2) |
| 29 | |
| 30 | def test_imul(self): |
| 31 | super(TupleTest, self).test_imul() |
| 32 | u = (0, 1) |
| 33 | u2 = u |
| 34 | u *= 3 |
| 35 | self.assert_(u is not u2) |
| 36 | |
| 37 | def test_tupleresizebug(self): |
| 38 | # Check that a specific bug in _PyTuple_Resize() is squashed. |
| 39 | def f(): |
| 40 | for i in range(1000): |
| 41 | yield i |
| 42 | self.assertEqual(list(tuple(f())), range(1000)) |
| 43 | |
| 44 | |
| 45 | def test_main(): |
| 46 | test_support.run_unittest(TupleTest) |
| 47 | |
| 48 | if __name__=="__main__": |
| 49 | test_main() |