summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_deque.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2005-03-22 22:43:28 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2005-03-22 22:43:28 (GMT)
commit09a3f2cc2f700be154ab489b6243b92b7331ff62 (patch)
tree5ab11394b6b32cca7b6cfad4bd9540c009fa70b1 /Lib/test/test_deque.py
parent24ff83d5f3f2afdfd22c1e5081ede2860a30ce0c (diff)
downloadcpython-09a3f2cc2f700be154ab489b6243b92b7331ff62.zip
cpython-09a3f2cc2f700be154ab489b6243b92b7331ff62.tar.gz
cpython-09a3f2cc2f700be154ab489b6243b92b7331ff62.tar.bz2
Add tests for tuple, list and UserList that initialize the object from
various iterables. (Copied from test_deque.py as suggested by Jim Jewett in SF bug #1166274)
Diffstat (limited to 'Lib/test/test_deque.py')
-rw-r--r--Lib/test/test_deque.py90
1 files changed, 7 insertions, 83 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index 61919cb..a562922 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -1,6 +1,6 @@
from collections import deque
import unittest
-from test import test_support
+from test import test_support, seq_tests
from weakref import proxy
import copy
import cPickle as pickle
@@ -378,93 +378,17 @@ class TestBasic(unittest.TestCase):
d.append(1)
gc.collect()
-def R(seqn):
- 'Regular generator'
- for i in seqn:
- yield i
-
-class G:
- 'Sequence using __getitem__'
- def __init__(self, seqn):
- self.seqn = seqn
- def __getitem__(self, i):
- return self.seqn[i]
-
-class I:
- 'Sequence using iterator protocol'
- def __init__(self, seqn):
- self.seqn = seqn
- self.i = 0
- def __iter__(self):
- return self
- def next(self):
- if self.i >= len(self.seqn): raise StopIteration
- v = self.seqn[self.i]
- self.i += 1
- return v
-
-class Ig:
- 'Sequence using iterator protocol defined with a generator'
- def __init__(self, seqn):
- self.seqn = seqn
- self.i = 0
- def __iter__(self):
- for val in self.seqn:
- yield val
-
-class X:
- 'Missing __getitem__ and __iter__'
- def __init__(self, seqn):
- self.seqn = seqn
- self.i = 0
- def next(self):
- if self.i >= len(self.seqn): raise StopIteration
- v = self.seqn[self.i]
- self.i += 1
- return v
-
-class N:
- 'Iterator missing next()'
- def __init__(self, seqn):
- self.seqn = seqn
- self.i = 0
- def __iter__(self):
- return self
-
-class E:
- 'Test propagation of exceptions'
- def __init__(self, seqn):
- self.seqn = seqn
- self.i = 0
- def __iter__(self):
- return self
- def next(self):
- 3 // 0
-
-class S:
- 'Test immediate stop'
- def __init__(self, seqn):
- pass
- def __iter__(self):
- return self
- def next(self):
- raise StopIteration
-
-from itertools import chain, imap
-def L(seqn):
- 'Test multiple tiers of iterators'
- return chain(imap(lambda x:x, R(Ig(G(seqn)))))
-
-
class TestVariousIteratorArgs(unittest.TestCase):
def test_constructor(self):
for s in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5)):
- for g in (G, I, Ig, S, L, R):
+ for g in (seq_tests.Sequence, seq_tests.IterFunc,
+ seq_tests.IterGen, seq_tests.IterFuncStop,
+ seq_tests.itermulti, seq_tests.iterfunc):
self.assertEqual(list(deque(g(s))), list(g(s)))
- self.assertRaises(TypeError, deque, X(s))
- self.assertRaises(TypeError, deque, N(s))
- self.assertRaises(ZeroDivisionError, deque, E(s))
+ self.assertRaises(TypeError, deque, seq_tests.IterNextOnly(s))
+ self.assertRaises(TypeError, deque, seq_tests.IterNoNext(s))
+ self.assertRaises(ZeroDivisionError, deque, seq_tests.IterGenExc(s))
def test_iter_with_altered_data(self):
d = deque('abcdefg')