Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_anydbm.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 | fd7789a1bfcd |
| children | 7caf54ce529e |
| rev | line source |
|---|---|
|
22364
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
2 """Test script for the anydbm module |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
3 based on testdumbdbm.py |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
4 """ |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
5 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
6 import os |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
7 import unittest |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
8 import anydbm |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
9 import glob |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
22364
diff
changeset
|
10 from test import test_support |
|
22364
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
11 |
|
24710
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
12 _fname = test_support.TESTFN |
|
22364
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
13 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
14 def _delete_files(): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
15 # we don't know the precise name the underlying database uses |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
16 # so we use glob to locate all names |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
17 for f in glob.glob(_fname + "*"): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
18 try: |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
19 os.unlink(f) |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
20 except OSError: |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
21 pass |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
22 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
23 class AnyDBMTestCase(unittest.TestCase): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
24 _dict = {'0': '', |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
25 'a': 'Python:', |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
26 'b': 'Programming', |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
27 'c': 'the', |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
28 'd': 'way', |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
29 'f': 'Guido', |
| 45271 | 30 'g': 'intended' |
|
22364
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
31 } |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
32 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
33 def __init__(self, *args): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
34 unittest.TestCase.__init__(self, *args) |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
35 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
36 def test_anydbm_creation(self): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
37 f = anydbm.open(_fname, 'c') |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
38 self.assertEqual(f.keys(), []) |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
39 for key in self._dict: |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
40 f[key] = self._dict[key] |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
41 self.read_helper(f) |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
42 f.close() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
43 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
44 def test_anydbm_modification(self): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
45 self.init_db() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
46 f = anydbm.open(_fname, 'c') |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
47 self._dict['g'] = f['g'] = "indented" |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
48 self.read_helper(f) |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
49 f.close() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
50 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
51 def test_anydbm_read(self): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
52 self.init_db() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
53 f = anydbm.open(_fname, 'r') |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
54 self.read_helper(f) |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
55 f.close() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
56 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
57 def test_anydbm_keys(self): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
58 self.init_db() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
59 f = anydbm.open(_fname, 'r') |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
60 keys = self.keys_helper(f) |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
61 f.close() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
62 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
63 def read_helper(self, f): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
64 keys = self.keys_helper(f) |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
65 for key in self._dict: |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
66 self.assertEqual(self._dict[key], f[key]) |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
67 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
68 def init_db(self): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
69 f = anydbm.open(_fname, 'n') |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
70 for k in self._dict: |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
71 f[k] = self._dict[k] |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
72 f.close() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
73 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
74 def keys_helper(self, f): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
75 keys = f.keys() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
76 keys.sort() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
77 dkeys = self._dict.keys() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
78 dkeys.sort() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
79 self.assertEqual(keys, dkeys) |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
80 return keys |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
81 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
82 def tearDown(self): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
83 _delete_files() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
84 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
85 def setUp(self): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
86 _delete_files() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
87 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
88 def test_main(): |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
89 try: |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
90 test_support.run_unittest(AnyDBMTestCase) |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
91 finally: |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
92 _delete_files() |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
93 |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
94 if __name__ == "__main__": |
|
34cbefd2c3fe
initial test_anydbm module - based on test_dumbdbm.py
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
95 test_main() |
