Improve test coverage.
This commit is contained in:
parent
f751fa6195
commit
5ea7e31076
|
@ -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])
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue