diff options
author | Raymond Hettinger <python@rcn.com> | 2004-07-09 04:10:20 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-07-09 04:10:20 (GMT) |
commit | a435c53e133546adb4a7d13a73f9b688bf1a6078 (patch) | |
tree | 588fbfb2a1aaa1a6c64309ecb25d229148b3576b /Lib | |
parent | 2b2795ac6d20ad9171eb083a9e3bcf8eeaa4a889 (diff) | |
download | cpython-a435c53e133546adb4a7d13a73f9b688bf1a6078.zip cpython-a435c53e133546adb4a7d13a73f9b688bf1a6078.tar.gz cpython-a435c53e133546adb4a7d13a73f9b688bf1a6078.tar.bz2 |
* balance the left/right search for getitem.
* use assertions instead of tests after internal calls that can't fail.
* expand test coverage
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_deque.py | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index 13800ea..dc0cc6f 100644 --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -6,9 +6,14 @@ import copy import cPickle as pickle from cStringIO import StringIO import random +import os BIG = 100000 +def fail(): + raise SyntaxError + yield 1 + class TestBasic(unittest.TestCase): def test_basics(self): @@ -58,6 +63,10 @@ class TestBasic(unittest.TestCase): self.assertRaises(TypeError, d.extendleft, 1) d.extendleft('bcd') self.assertEqual(list(d), list(reversed('abcd'))) + d = deque() + d.extendleft(range(1000)) + self.assertEqual(list(d), list(reversed(range(1000)))) + self.assertRaises(SyntaxError, d.extendleft, fail()) def test_getitem(self): n = 200 @@ -151,6 +160,13 @@ class TestBasic(unittest.TestCase): dr() self.assertEqual(tuple(d), tuple(e)) + self.assertRaises(TypeError, d.rotate, 'x') # Wrong arg type + self.assertRaises(TypeError, d.rotate, 1, 10) # Too many args + + d = deque() + d.rotate() # rotate an empty deque + self.assertEqual(d, deque()) + def test_len(self): d = deque('ab') self.assertEqual(len(d), 2) @@ -178,6 +194,8 @@ class TestBasic(unittest.TestCase): d.clear() self.assertEqual(len(d), 0) self.assertEqual(list(d), []) + d.clear() # clear an emtpy deque + self.assertEqual(list(d), []) def test_repr(self): d = deque(xrange(200)) @@ -189,10 +207,19 @@ class TestBasic(unittest.TestCase): def test_print(self): d = deque(xrange(200)) d.append(d) - f = StringIO() - print >> f, d, - self.assertEqual(f.getvalue(), repr(d)) - f.close() + try: + fo = open(test_support.TESTFN, "wb") + print >> fo, d, + fo.close() + fo = open(test_support.TESTFN, "rb") + self.assertEqual(fo.read(), repr(d)) + finally: + fo.close() + os.remove(test_support.TESTFN) + + def test_init(self): + self.assertRaises(TypeError, deque, 'abc', 2); + self.assertRaises(TypeError, deque, 1); def test_hash(self): self.assertRaises(TypeError, hash, deque('abc')) |