diff options
-rw-r--r-- | Lib/test/list_tests.py | 33 | ||||
-rw-r--r-- | Lib/test/seq_tests.py | 35 | ||||
-rw-r--r-- | Lib/test/test_builtin.py | 3 | ||||
-rw-r--r-- | Lib/test/test_genexps.py | 1 | ||||
-rw-r--r-- | Lib/test/test_tuple.py | 11 |
5 files changed, 49 insertions, 34 deletions
diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py index 3780b86..e616c79 100644 --- a/Lib/test/list_tests.py +++ b/Lib/test/list_tests.py @@ -29,14 +29,6 @@ class CommonTest(seq_tests.CommonTest): self.assertNotEqual(id(a), id(b)) self.assertEqual(a, b) - def test_mul(self): - for m in xrange(4): - s = tuple(range(m)) - for n in xrange(-3, 5): - self.assertEqual(self.type2test(s*n), self.type2test(s)*n) - self.assertEqual(self.type2test(s)*(-4), self.type2test([])) - self.assertEqual(id(s), id(s*1)) - def test_repr(self): l0 = [] l2 = [0, 1, 2] @@ -70,31 +62,6 @@ class CommonTest(seq_tests.CommonTest): fo.close() os.remove(test_support.TESTFN) - def test_getitem(self): - a = self.type2test([10, 11]) - self.assertEqual(a[0], 10) - self.assertEqual(a[1], 11) - self.assertEqual(a[-2], 10) - self.assertEqual(a[-1], 11) - self.assertRaises(IndexError, a.__getitem__, -3) - self.assertRaises(IndexError, a.__getitem__, 3) - - def test_subscript(self): - a = self.type2test([10, 11]) - self.assertEqual(a.__getitem__(0L), 10) - self.assertEqual(a.__getitem__(1L), 11) - self.assertEqual(a.__getitem__(-2L), 10) - self.assertEqual(a.__getitem__(-1L), 11) - self.assertRaises(IndexError, a.__getitem__, -3) - self.assertRaises(IndexError, a.__getitem__, 3) - self.assertEqual(a.__getitem__(slice(0,1)), self.type2test([10])) - self.assertEqual(a.__getitem__(slice(1,2)), self.type2test([11])) - self.assertEqual(a.__getitem__(slice(0,2)), self.type2test([10, 11])) - self.assertEqual(a.__getitem__(slice(0,3)), self.type2test([10, 11])) - self.assertEqual(a.__getitem__(slice(3,5)), self.type2test([])) - self.assertRaises(ValueError, a.__getitem__, slice(0, 10, 0)) - self.assertRaises(TypeError, a.__getitem__, 'x') - def test_set_subscript(self): a = self.type2test(range(20)) self.assertRaises(ValueError, a.__setitem__, slice(0, 10, 0), [1,2,3]) diff --git a/Lib/test/seq_tests.py b/Lib/test/seq_tests.py index f702b09..aeb15c0 100644 --- a/Lib/test/seq_tests.py +++ b/Lib/test/seq_tests.py @@ -48,10 +48,13 @@ class CommonTest(unittest.TestCase): u = self.type2test([0, 1, 2, 3, 4]) for i in xrange(len(u)): self.assertEqual(u[i], i) + self.assertEqual(u[long(i)], i) for i in xrange(-len(u), -1): self.assertEqual(u[i], len(u)+i) + self.assertEqual(u[long(i)], len(u)+i) self.assertRaises(IndexError, u.__getitem__, -len(u)-1) self.assertRaises(IndexError, u.__getitem__, len(u)) + self.assertRaises(ValueError, u.__getitem__, slice(0,10,0)) u = self.type2test() self.assertRaises(IndexError, u.__getitem__, 0) @@ -59,6 +62,14 @@ class CommonTest(unittest.TestCase): self.assertRaises(TypeError, u.__getitem__) + a = self.type2test([10, 11]) + self.assertEqual(a[0], 10) + self.assertEqual(a[1], 11) + self.assertEqual(a[-2], 10) + self.assertEqual(a[-1], 11) + self.assertRaises(IndexError, a.__getitem__, -3) + self.assertRaises(IndexError, a.__getitem__, 3) + def test_getslice(self): l = [0, 1, 2, 3, 4] u = self.type2test(l) @@ -169,3 +180,27 @@ class CommonTest(unittest.TestCase): def __getitem__(self, key): return str(key) + '!!!' self.assertEqual(iter(T((1,2))).next(), 1) + + def test_repeat(self): + for m in xrange(4): + s = tuple(range(m)) + for n in xrange(-3, 5): + self.assertEqual(self.type2test(s*n), self.type2test(s)*n) + self.assertEqual(self.type2test(s)*(-4), self.type2test([])) + self.assertEqual(id(s), id(s*1)) + + def test_subscript(self): + a = self.type2test([10, 11]) + self.assertEqual(a.__getitem__(0L), 10) + self.assertEqual(a.__getitem__(1L), 11) + self.assertEqual(a.__getitem__(-2L), 10) + self.assertEqual(a.__getitem__(-1L), 11) + self.assertRaises(IndexError, a.__getitem__, -3) + self.assertRaises(IndexError, a.__getitem__, 3) + self.assertEqual(a.__getitem__(slice(0,1)), self.type2test([10])) + self.assertEqual(a.__getitem__(slice(1,2)), self.type2test([11])) + self.assertEqual(a.__getitem__(slice(0,2)), self.type2test([10, 11])) + self.assertEqual(a.__getitem__(slice(0,3)), self.type2test([10, 11])) + self.assertEqual(a.__getitem__(slice(3,5)), self.type2test([])) + self.assertRaises(ValueError, a.__getitem__, slice(0, 10, 0)) + self.assertRaises(TypeError, a.__getitem__, 'x') diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 9f90925..f023b11 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -229,6 +229,9 @@ class BuiltinTest(unittest.TestCase): self.assertEqual(divmod(12L, -7), (-2L, -2)) self.assertEqual(divmod(-12L, -7), (1L, -5)) + self.assertEqual(divmod(-sys.maxint-1, -1), + (sys.maxint+1, 0)) + self.assert_(not fcmp(divmod(3.25, 1.0), (3.0, 0.25))) self.assert_(not fcmp(divmod(-3.25, 1.0), (-4.0, 0.75))) self.assert_(not fcmp(divmod(3.25, -1.0), (-4.0, -0.75))) diff --git a/Lib/test/test_genexps.py b/Lib/test/test_genexps.py index c529e75..ca5dd7d 100644 --- a/Lib/test/test_genexps.py +++ b/Lib/test/test_genexps.py @@ -121,7 +121,6 @@ Verify re-use of tuples (a side benefit of using genexps over listcomps) 0 - ########### Tests borrowed from or inspired by test_generators.py ############ Make a generator that acts like range() diff --git a/Lib/test/test_tuple.py b/Lib/test/test_tuple.py index 33a6edd..dddb03e 100644 --- a/Lib/test/test_tuple.py +++ b/Lib/test/test_tuple.py @@ -65,6 +65,17 @@ class TupleTest(seq_tests.CommonTest): collisions = len(inps) - len(set(map(hash, inps))) self.assert_(collisions <= 15) + def test_repr(self): + l0 = tuple() + l2 = (0, 1, 2) + a0 = self.type2test(l0) + a2 = self.type2test(l2) + + self.assertEqual(str(a0), repr(l0)) + self.assertEqual(str(a2), repr(l2)) + self.assertEqual(repr(a0), "()") + self.assertEqual(repr(a2), "(0, 1, 2)") + def test_main(): test_support.run_unittest(TupleTest) |