annotate Lib/test/test_bsddb.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 7641a3f0b2ec
children 6768b2350c57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4977
9b1694390820 Test script for the bsddb C extension module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
1 #! /usr/bin/env python
30423
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
2 """Test script for the bsddb C module by Roger E. Masse
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
3 Adapted to unittest format and expanded scope by Raymond Hettinger
4977
9b1694390820 Test script for the bsddb C extension module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
4 """
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
5 import os, sys
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
6 import copy
52555
7641a3f0b2ec A few more test skips via import_module, and change import_module to
R. David Murray <rdmurray@bitdance.com>
parents: 47257
diff changeset
7 import unittest
7641a3f0b2ec A few more test skips via import_module, and change import_module to
R. David Murray <rdmurray@bitdance.com>
parents: 47257
diff changeset
8 from test import test_support
7641a3f0b2ec A few more test skips via import_module, and change import_module to
R. David Murray <rdmurray@bitdance.com>
parents: 47257
diff changeset
9
7641a3f0b2ec A few more test skips via import_module, and change import_module to
R. David Murray <rdmurray@bitdance.com>
parents: 47257
diff changeset
10 # Skip test if _bsddb wasn't built.
7641a3f0b2ec A few more test skips via import_module, and change import_module to
R. David Murray <rdmurray@bitdance.com>
parents: 47257
diff changeset
11 test_support.import_module('_bsddb')
7641a3f0b2ec A few more test skips via import_module, and change import_module to
R. David Murray <rdmurray@bitdance.com>
parents: 47257
diff changeset
12
4977
9b1694390820 Test script for the bsddb C extension module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
13 import bsddb
21287
d51f2158fa79 Move import dbhash out of test_sundry and into test_bsddb,
Guido van Rossum <guido@python.org>
parents: 17123
diff changeset
14 import dbhash # Just so we know it's imported
52555
7641a3f0b2ec A few more test skips via import_module, and change import_module to
R. David Murray <rdmurray@bitdance.com>
parents: 47257
diff changeset
15
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 10457
diff changeset
16
30423
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
17 class TestBSDDB(unittest.TestCase):
37644
c6e11f804d00 Closes bug #1149413
Gregory P. Smith <greg@mad-scientist.com>
parents: 30848
diff changeset
18 openflag = 'c'
4977
9b1694390820 Test script for the bsddb C extension module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
19
30423
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
20 def setUp(self):
37645
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
21 self.f = self.openmethod[0](self.fname, self.openflag, cachesize=32768)
30423
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
22 self.d = dict(q='Guido', w='van', e='Rossum', r='invented', t='Python', y='')
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
23 for k, v in self.d.iteritems():
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
24 self.f[k] = v
4977
9b1694390820 Test script for the bsddb C extension module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
25
30423
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
26 def tearDown(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
27 self.f.sync()
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
28 self.f.close()
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
29 if self.fname is None:
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
30 return
23233
40a188055369 SF patch [ 545523 ] patch for 514433 bsddb.dbopen (NULL)
Anthony Baxter <anthonybaxter@gmail.com>
parents: 21287
diff changeset
31 try:
30423
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
32 os.remove(self.fname)
23233
40a188055369 SF patch [ 545523 ] patch for 514433 bsddb.dbopen (NULL)
Anthony Baxter <anthonybaxter@gmail.com>
parents: 21287
diff changeset
33 except os.error:
40a188055369 SF patch [ 545523 ] patch for 514433 bsddb.dbopen (NULL)
Anthony Baxter <anthonybaxter@gmail.com>
parents: 21287
diff changeset
34 pass
4977
9b1694390820 Test script for the bsddb C extension module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
35
30423
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
36 def test_getitem(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
37 for k, v in self.d.iteritems():
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
38 self.assertEqual(self.f[k], v)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
39
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
40 def test_len(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
41 self.assertEqual(len(self.f), len(self.d))
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
42
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
43 def test_change(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
44 self.f['r'] = 'discovered'
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
45 self.assertEqual(self.f['r'], 'discovered')
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
46 self.assert_('r' in self.f.keys())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
47 self.assert_('discovered' in self.f.values())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
48
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
49 def test_close_and_reopen(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
50 if self.fname is None:
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
51 # if we're using an in-memory only db, we can't reopen it
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
52 # so finish here.
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
53 return
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
54 self.f.close()
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
55 self.f = self.openmethod[0](self.fname, 'w')
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
56 for k, v in self.d.iteritems():
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
57 self.assertEqual(self.f[k], v)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
58
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
59 def assertSetEquals(self, seqn1, seqn2):
39108
008941521805 Remove usage of sets module (patch #1500609).
Georg Brandl <georg@python.org>
parents: 37645
diff changeset
60 self.assertEqual(set(seqn1), set(seqn2))
30423
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
61
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
62 def test_mapping_iteration_methods(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
63 f = self.f
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
64 d = self.d
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
65 self.assertSetEquals(d, f)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
66 self.assertSetEquals(d.keys(), f.keys())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
67 self.assertSetEquals(d.values(), f.values())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
68 self.assertSetEquals(d.items(), f.items())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
69 self.assertSetEquals(d.iterkeys(), f.iterkeys())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
70 self.assertSetEquals(d.itervalues(), f.itervalues())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
71 self.assertSetEquals(d.iteritems(), f.iteritems())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
72
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
73 def test_iter_while_modifying_values(self):
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
74 di = iter(self.d)
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
75 while 1:
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
76 try:
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
77 key = di.next()
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
78 self.d[key] = 'modified '+key
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
79 except StopIteration:
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
80 break
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
81
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
82 # it should behave the same as a dict. modifying values
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
83 # of existing keys should not break iteration. (adding
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
84 # or removing keys should)
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
85 loops_left = len(self.f)
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
86 fi = iter(self.f)
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
87 while 1:
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
88 try:
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
89 key = fi.next()
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
90 self.f[key] = 'modified '+key
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
91 loops_left -= 1
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
92 except StopIteration:
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
93 break
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
94 self.assertEqual(loops_left, 0)
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
95
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
96 self.test_mapping_iteration_methods()
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
97
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
98 def test_iter_abort_on_changed_size(self):
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
99 def DictIterAbort():
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
100 di = iter(self.d)
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
101 while 1:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
102 try:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
103 di.next()
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
104 self.d['newkey'] = 'SPAM'
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
105 except StopIteration:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
106 break
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
107 self.assertRaises(RuntimeError, DictIterAbort)
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
108
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
109 def DbIterAbort():
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
110 fi = iter(self.f)
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
111 while 1:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
112 try:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
113 fi.next()
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
114 self.f['newkey'] = 'SPAM'
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
115 except StopIteration:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
116 break
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
117 self.assertRaises(RuntimeError, DbIterAbort)
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
118
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
119 def test_iteritems_abort_on_changed_size(self):
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
120 def DictIteritemsAbort():
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
121 di = self.d.iteritems()
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
122 while 1:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
123 try:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
124 di.next()
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
125 self.d['newkey'] = 'SPAM'
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
126 except StopIteration:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
127 break
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
128 self.assertRaises(RuntimeError, DictIteritemsAbort)
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
129
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
130 def DbIteritemsAbort():
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
131 fi = self.f.iteritems()
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
132 while 1:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
133 try:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
134 key, value = fi.next()
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
135 del self.f[key]
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
136 except StopIteration:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
137 break
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
138 self.assertRaises(RuntimeError, DbIteritemsAbort)
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
139
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
140 def test_iteritems_while_modifying_values(self):
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
141 di = self.d.iteritems()
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
142 while 1:
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
143 try:
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
144 k, v = di.next()
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
145 self.d[k] = 'modified '+v
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
146 except StopIteration:
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
147 break
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
148
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
149 # it should behave the same as a dict. modifying values
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
150 # of existing keys should not break iteration. (adding
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
151 # or removing keys should)
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
152 loops_left = len(self.f)
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
153 fi = self.f.iteritems()
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
154 while 1:
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
155 try:
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
156 k, v = fi.next()
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
157 self.f[k] = 'modified '+v
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
158 loops_left -= 1
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
159 except StopIteration:
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
160 break
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
161 self.assertEqual(loops_left, 0)
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
162
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
163 self.test_mapping_iteration_methods()
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
164
30423
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
165 def test_first_next_looping(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
166 items = [self.f.first()]
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
167 for i in xrange(1, len(self.f)):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
168 items.append(self.f.next())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
169 self.assertSetEquals(items, self.d.items())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
170
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
171 def test_previous_last_looping(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
172 items = [self.f.last()]
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
173 for i in xrange(1, len(self.f)):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
174 items.append(self.f.previous())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
175 self.assertSetEquals(items, self.d.items())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
176
42767
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
177 def test_first_while_deleting(self):
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
178 # Test for bug 1725856
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
179 self.assert_(len(self.d) >= 2, "test requires >=2 items")
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
180 for _ in self.d:
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
181 key = self.f.first()[0]
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
182 del self.f[key]
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
183 self.assertEqual([], self.f.items(), "expected empty db after test")
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
184
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
185 def test_last_while_deleting(self):
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
186 # Test for bug 1725856's evil twin
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
187 self.assert_(len(self.d) >= 2, "test requires >=2 items")
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
188 for _ in self.d:
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
189 key = self.f.last()[0]
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
190 del self.f[key]
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
191 self.assertEqual([], self.f.items(), "expected empty db after test")
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 40891
diff changeset
192
30423
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
193 def test_set_location(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
194 self.assertEqual(self.f.set_location('e'), ('e', self.d['e']))
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
195
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
196 def test_contains(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
197 for k in self.d:
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
198 self.assert_(k in self.f)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
199 self.assert_('not here' not in self.f)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
200
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
201 def test_has_key(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
202 for k in self.d:
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
203 self.assert_(self.f.has_key(k))
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
204 self.assert_(not self.f.has_key('not here'))
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
205
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
206 def test_clear(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
207 self.f.clear()
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
208 self.assertEqual(len(self.f), 0)
4977
9b1694390820 Test script for the bsddb C extension module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
209
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
210 def test__no_deadlock_first(self, debug=0):
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
211 # do this so that testers can see what function we're in in
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
212 # verbose mode when we deadlock.
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
213 sys.stdout.flush()
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
214
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
215 # in pybsddb's _DBWithCursor this causes an internal DBCursor
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
216 # object is created. Other test_ methods in this class could
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
217 # inadvertently cause the deadlock but an explicit test is needed.
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
218 if debug: print "A"
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
219 k,v = self.f.first()
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
220 if debug: print "B", k
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
221 self.f[k] = "deadlock. do not pass go. do not collect $200."
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
222 if debug: print "C"
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
223 # if the bsddb implementation leaves the DBCursor open during
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
224 # the database write and locking+threading support is enabled
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
225 # the cursor's read lock will deadlock the write lock request..
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
226
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
227 # test the iterator interface
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
228 if True:
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
229 if debug: print "D"
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
230 i = self.f.iteritems()
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
231 k,v = i.next()
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
232 if debug: print "E"
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
233 self.f[k] = "please don't deadlock"
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
234 if debug: print "F"
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
235 while 1:
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
236 try:
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
237 k,v = i.next()
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
238 except StopIteration:
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
239 break
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
240 if debug: print "F2"
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
241
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
242 i = iter(self.f)
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
243 if debug: print "G"
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
244 while i:
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
245 try:
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
246 if debug: print "H"
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
247 k = i.next()
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
248 if debug: print "I"
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
249 self.f[k] = "deadlocks-r-us"
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
250 if debug: print "J"
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
251 except StopIteration:
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
252 i = None
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
253 if debug: print "K"
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
254
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
255 # test the legacy cursor interface mixed with writes
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
256 self.assert_(self.f.first()[0] in self.d)
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
257 k = self.f.next()[0]
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
258 self.assert_(k in self.d)
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
259 self.f[k] = "be gone with ye deadlocks"
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
260 self.assert_(self.f[k], "be gone with ye deadlocks")
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30423
diff changeset
261
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
262 def test_for_cursor_memleak(self):
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 42767
diff changeset
263 # do the bsddb._DBWithCursor iterator internals leak cursors?
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
264 nc1 = len(self.f._cursor_refs)
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
265 # create iterator
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
266 i = self.f.iteritems()
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
267 nc2 = len(self.f._cursor_refs)
40891
f3a59acca51f Fix typo in comment
Neal Norwitz <nnorwitz@gmail.com>
parents: 39108
diff changeset
268 # use the iterator (should run to the first yield, creating the cursor)
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
269 k, v = i.next()
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
270 nc3 = len(self.f._cursor_refs)
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
271 # destroy the iterator; this should cause the weakref callback
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
272 # to remove the cursor object from self.f._cursor_refs
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
273 del i
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
274 nc4 = len(self.f._cursor_refs)
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
275
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
276 self.assertEqual(nc1, nc2)
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
277 self.assertEqual(nc1, nc4)
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
278 self.assert_(nc3 == nc1+1)
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
279
30423
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
280 def test_popitem(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
281 k, v = self.f.popitem()
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
282 self.assert_(k in self.d)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
283 self.assert_(v in self.d.values())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
284 self.assert_(k not in self.f)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
285 self.assertEqual(len(self.d)-1, len(self.f))
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
286
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
287 def test_pop(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
288 k = 'w'
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
289 v = self.f.pop(k)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
290 self.assertEqual(v, self.d[k])
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
291 self.assert_(k not in self.f)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
292 self.assert_(v not in self.f.values())
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
293 self.assertEqual(len(self.d)-1, len(self.f))
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
294
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
295 def test_get(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
296 self.assertEqual(self.f.get('NotHere'), None)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
297 self.assertEqual(self.f.get('NotHere', 'Default'), 'Default')
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
298 self.assertEqual(self.f.get('q', 'Default'), self.d['q'])
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
299
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
300 def test_setdefault(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
301 self.assertEqual(self.f.setdefault('new', 'dog'), 'dog')
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
302 self.assertEqual(self.f.setdefault('r', 'cat'), self.d['r'])
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
303
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
304 def test_update(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
305 new = dict(y='life', u='of', i='brian')
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
306 self.f.update(new)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
307 self.d.update(new)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
308 for k, v in self.d.iteritems():
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
309 self.assertEqual(self.f[k], v)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
310
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
311 def test_keyordering(self):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
312 if self.openmethod[0] is not bsddb.btopen:
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
313 return
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
314 keys = self.d.keys()
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
315 keys.sort()
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
316 self.assertEqual(self.f.first()[0], keys[0])
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
317 self.assertEqual(self.f.next()[0], keys[1])
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
318 self.assertEqual(self.f.last()[0], keys[-1])
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
319 self.assertEqual(self.f.previous()[0], keys[-2])
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
320 self.assertEqual(list(self.f), keys)
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
321
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
322 class TestBTree(TestBSDDB):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
323 fname = test_support.TESTFN
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
324 openmethod = [bsddb.btopen]
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
325
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
326 class TestBTree_InMemory(TestBSDDB):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
327 fname = None
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
328 openmethod = [bsddb.btopen]
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
329
37644
c6e11f804d00 Closes bug #1149413
Gregory P. Smith <greg@mad-scientist.com>
parents: 30848
diff changeset
330 class TestBTree_InMemory_Truncate(TestBSDDB):
c6e11f804d00 Closes bug #1149413
Gregory P. Smith <greg@mad-scientist.com>
parents: 30848
diff changeset
331 fname = None
c6e11f804d00 Closes bug #1149413
Gregory P. Smith <greg@mad-scientist.com>
parents: 30848
diff changeset
332 openflag = 'n'
c6e11f804d00 Closes bug #1149413
Gregory P. Smith <greg@mad-scientist.com>
parents: 30848
diff changeset
333 openmethod = [bsddb.btopen]
c6e11f804d00 Closes bug #1149413
Gregory P. Smith <greg@mad-scientist.com>
parents: 30848
diff changeset
334
30423
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
335 class TestHashTable(TestBSDDB):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
336 fname = test_support.TESTFN
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
337 openmethod = [bsddb.hashopen]
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
338
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
339 class TestHashTable_InMemory(TestBSDDB):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
340 fname = None
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
341 openmethod = [bsddb.hashopen]
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
342
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
343 ## # (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
344 ## # appears broken... at least on
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
345 ## # Solaris Intel - rmasse 1/97
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
346
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
347 def test_main(verbose=None):
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
348 test_support.run_unittest(
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
349 TestBTree,
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
350 TestHashTable,
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
351 TestBTree_InMemory,
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
352 TestHashTable_InMemory,
37644
c6e11f804d00 Closes bug #1149413
Gregory P. Smith <greg@mad-scientist.com>
parents: 30848
diff changeset
353 TestBTree_InMemory_Truncate,
30423
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
354 )
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
355
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
356 if __name__ == "__main__":
7433e7c9e2ca * Converted test to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
357 test_main(verbose=True)