mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Improve test coverage.
This commit is contained in:
parent
bcab2b25f9
commit
ff5dc0ee77
2 changed files with 45 additions and 0 deletions
|
@ -145,6 +145,35 @@ class TestReversed(unittest.TestCase):
|
||||||
# This is an implementation detail, not an interface requirement
|
# This is an implementation detail, not an interface requirement
|
||||||
for s in ('hello', tuple('hello'), list('hello'), xrange(5)):
|
for s in ('hello', tuple('hello'), list('hello'), xrange(5)):
|
||||||
self.assertEqual(len(reversed(s)), len(s))
|
self.assertEqual(len(reversed(s)), len(s))
|
||||||
|
r = reversed(s)
|
||||||
|
list(r)
|
||||||
|
self.assertEqual(len(r), 0)
|
||||||
|
class SeqWithWeirdLen:
|
||||||
|
called = False
|
||||||
|
def __len__(self):
|
||||||
|
if not self.called:
|
||||||
|
self.called = True
|
||||||
|
return 10
|
||||||
|
raise ZeroDivisionError
|
||||||
|
def __getitem__(self, index):
|
||||||
|
return index
|
||||||
|
r = reversed(SeqWithWeirdLen())
|
||||||
|
self.assertRaises(ZeroDivisionError, len, r)
|
||||||
|
|
||||||
|
|
||||||
|
def test_gc(self):
|
||||||
|
class Seq:
|
||||||
|
def __len__(self):
|
||||||
|
return 10
|
||||||
|
def __getitem__(self, index):
|
||||||
|
return index
|
||||||
|
s = Seq()
|
||||||
|
r = reversed(s)
|
||||||
|
s.r = r
|
||||||
|
|
||||||
|
def test_args(self):
|
||||||
|
self.assertRaises(TypeError, reversed)
|
||||||
|
self.assertRaises(TypeError, reversed, [], 'extra')
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def test_main(verbose=None):
|
||||||
testclasses = (EnumerateTestCase, SubclassTestCase, TestEmpty, TestBig,
|
testclasses = (EnumerateTestCase, SubclassTestCase, TestEmpty, TestBig,
|
||||||
|
|
|
@ -420,6 +420,14 @@ class TestGC(unittest.TestCase):
|
||||||
a = []
|
a = []
|
||||||
self.makecycle(cycle([a]*2), a)
|
self.makecycle(cycle([a]*2), a)
|
||||||
|
|
||||||
|
def test_dropwhile(self):
|
||||||
|
a = []
|
||||||
|
self.makecycle(dropwhile(bool, [0, a, a]), a)
|
||||||
|
|
||||||
|
def test_groupby(self):
|
||||||
|
a = []
|
||||||
|
self.makecycle(groupby([a]*2, lambda x:x), a)
|
||||||
|
|
||||||
def test_ifilter(self):
|
def test_ifilter(self):
|
||||||
a = []
|
a = []
|
||||||
self.makecycle(ifilter(lambda x:True, [a]*2), a)
|
self.makecycle(ifilter(lambda x:True, [a]*2), a)
|
||||||
|
@ -440,10 +448,18 @@ class TestGC(unittest.TestCase):
|
||||||
a = []
|
a = []
|
||||||
self.makecycle(islice([a]*2, None), a)
|
self.makecycle(islice([a]*2, None), a)
|
||||||
|
|
||||||
|
def test_repeat(self):
|
||||||
|
a = []
|
||||||
|
self.makecycle(repeat(a), a)
|
||||||
|
|
||||||
def test_starmap(self):
|
def test_starmap(self):
|
||||||
a = []
|
a = []
|
||||||
self.makecycle(starmap(lambda *t: t, [(a,a)]*2), a)
|
self.makecycle(starmap(lambda *t: t, [(a,a)]*2), a)
|
||||||
|
|
||||||
|
def test_takewhile(self):
|
||||||
|
a = []
|
||||||
|
self.makecycle(takewhile(bool, [1, 0, a, a]), a)
|
||||||
|
|
||||||
def R(seqn):
|
def R(seqn):
|
||||||
'Regular generator'
|
'Regular generator'
|
||||||
for i in seqn:
|
for i in seqn:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue