Mercurial > cpython-lru_cache-weakref
annotate Lib/bsddb/test/test_dbobj.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 | 81a1a1545172 |
| children | af498ab2afb4 |
| rev | line source |
|---|---|
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1 |
|
45468
1d84bf5f9478
Patch #2167 from calvin: Remove unused imports
Christian Heimes <christian@cheimes.de>
parents:
40554
diff
changeset
|
2 import os, string |
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
3 import unittest |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
4 |
|
48910
81a1a1545172
Update bsddb code to version 4.7.3pre2. This code should
Jesus Cea <jcea@jcea.es>
parents:
46984
diff
changeset
|
5 from test_all import db, dbobj, test_support, get_new_environment_path, \ |
|
81a1a1545172
Update bsddb code to version 4.7.3pre2. This code should
Jesus Cea <jcea@jcea.es>
parents:
46984
diff
changeset
|
6 get_new_database_path |
|
45617
5ccb6eb202ff
Modify import of test_support so that the code can also be used with a
Gregory P. Smith <greg@mad-scientist.com>
parents:
45506
diff
changeset
|
7 |
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
8 #---------------------------------------------------------------------- |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
9 |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
10 class dbobjTestCase(unittest.TestCase): |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
11 """Verify that dbobj.DB and dbobj.DBEnv work properly""" |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
12 db_name = 'test-dbobj.db' |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
13 |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
14 def setUp(self): |
|
46984
e4e3b3eba226
Testsuite for bsddb module, version 4.6.4
Jesus Cea <jcea@jcea.es>
parents:
45617
diff
changeset
|
15 self.homeDir = get_new_environment_path() |
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
16 |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
17 def tearDown(self): |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
18 if hasattr(self, 'db'): |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
19 del self.db |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
20 if hasattr(self, 'env'): |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
21 del self.env |
|
45506
55eefb43ef6f
Create a db_home directory with a unique name so multiple users can
Neal Norwitz <nnorwitz@gmail.com>
parents:
45468
diff
changeset
|
22 test_support.rmtree(self.homeDir) |
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
23 |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
24 def test01_both(self): |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
25 class TestDBEnv(dbobj.DBEnv): pass |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
26 class TestDB(dbobj.DB): |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
27 def put(self, key, *args, **kwargs): |
|
48910
81a1a1545172
Update bsddb code to version 4.7.3pre2. This code should
Jesus Cea <jcea@jcea.es>
parents:
46984
diff
changeset
|
28 key = key.upper() |
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
29 # call our parent classes put method with an upper case key |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
30 return apply(dbobj.DB.put, (self, key) + args, kwargs) |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
31 self.env = TestDBEnv() |
|
26878
c249607ef535
Port BerkeleyDB 4.1 support from the pybsddb project. bsddb is now at
Barry Warsaw <barry@python.org>
parents:
26387
diff
changeset
|
32 self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL) |
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
33 self.db = TestDB(self.env) |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
34 self.db.open(self.db_name, db.DB_HASH, db.DB_CREATE) |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
35 self.db.put('spam', 'eggs') |
|
46984
e4e3b3eba226
Testsuite for bsddb module, version 4.6.4
Jesus Cea <jcea@jcea.es>
parents:
45617
diff
changeset
|
36 self.assertEqual(self.db.get('spam'), None, |
|
e4e3b3eba226
Testsuite for bsddb module, version 4.6.4
Jesus Cea <jcea@jcea.es>
parents:
45617
diff
changeset
|
37 "overridden dbobj.DB.put() method failed [1]") |
|
e4e3b3eba226
Testsuite for bsddb module, version 4.6.4
Jesus Cea <jcea@jcea.es>
parents:
45617
diff
changeset
|
38 self.assertEqual(self.db.get('SPAM'), 'eggs', |
|
e4e3b3eba226
Testsuite for bsddb module, version 4.6.4
Jesus Cea <jcea@jcea.es>
parents:
45617
diff
changeset
|
39 "overridden dbobj.DB.put() method failed [2]") |
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
40 self.db.close() |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
41 self.env.close() |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
42 |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
43 def test02_dbobj_dict_interface(self): |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
44 self.env = dbobj.DBEnv() |
|
26878
c249607ef535
Port BerkeleyDB 4.1 support from the pybsddb project. bsddb is now at
Barry Warsaw <barry@python.org>
parents:
26387
diff
changeset
|
45 self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL) |
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
46 self.db = dbobj.DB(self.env) |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
47 self.db.open(self.db_name+'02', db.DB_HASH, db.DB_CREATE) |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
48 # __setitem__ |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
49 self.db['spam'] = 'eggs' |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
50 # __len__ |
|
46984
e4e3b3eba226
Testsuite for bsddb module, version 4.6.4
Jesus Cea <jcea@jcea.es>
parents:
45617
diff
changeset
|
51 self.assertEqual(len(self.db), 1) |
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
52 # __getitem__ |
|
46984
e4e3b3eba226
Testsuite for bsddb module, version 4.6.4
Jesus Cea <jcea@jcea.es>
parents:
45617
diff
changeset
|
53 self.assertEqual(self.db['spam'], 'eggs') |
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
54 # __del__ |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
55 del self.db['spam'] |
|
46984
e4e3b3eba226
Testsuite for bsddb module, version 4.6.4
Jesus Cea <jcea@jcea.es>
parents:
45617
diff
changeset
|
56 self.assertEqual(self.db.get('spam'), None, "dbobj __del__ failed") |
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
57 self.db.close() |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
58 self.env.close() |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
59 |
|
40373
99cb38351ffc
Bug #1599782: Fix segfault on bsddb.db.DB().type().
Neal Norwitz <nnorwitz@gmail.com>
parents:
30475
diff
changeset
|
60 def test03_dbobj_type_before_open(self): |
|
40376
61b069b84d0a
Oops, convert tabs to spaces
Neal Norwitz <nnorwitz@gmail.com>
parents:
40373
diff
changeset
|
61 # Ensure this doesn't cause a segfault. |
|
61b069b84d0a
Oops, convert tabs to spaces
Neal Norwitz <nnorwitz@gmail.com>
parents:
40373
diff
changeset
|
62 self.assertRaises(db.DBInvalidArgError, db.DB().type) |
|
40373
99cb38351ffc
Bug #1599782: Fix segfault on bsddb.db.DB().type().
Neal Norwitz <nnorwitz@gmail.com>
parents:
30475
diff
changeset
|
63 |
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
64 #---------------------------------------------------------------------- |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
65 |
|
26878
c249607ef535
Port BerkeleyDB 4.1 support from the pybsddb project. bsddb is now at
Barry Warsaw <barry@python.org>
parents:
26387
diff
changeset
|
66 def test_suite(): |
|
26288
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
67 return unittest.makeSuite(dbobjTestCase) |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
68 |
|
b0b608598170
Importing test suite from bsddb3 3.4.0 (with modifications).
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
69 if __name__ == '__main__': |
|
26878
c249607ef535
Port BerkeleyDB 4.1 support from the pybsddb project. bsddb is now at
Barry Warsaw <barry@python.org>
parents:
26387
diff
changeset
|
70 unittest.main(defaultTest='test_suite') |
