annotate Lib/test/test_whichdb.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 1d84bf5f9478
children 30086aa33123 7caf54ce529e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24488
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
1 #! /usr/bin/env python
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
2 """Test script for the whichdb module
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
3 based on test_anydbm.py
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
4 """
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
5
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
6 import os
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
7 import test.test_support
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
8 import unittest
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
9 import whichdb
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
10 import anydbm
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
11 import glob
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
12
24710
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24674
diff changeset
13 _fname = test.test_support.TESTFN
24488
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
14
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
15 def _delete_files():
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
16 # we don't know the precise name the underlying database uses
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
17 # so we use glob to locate all names
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
18 for f in glob.glob(_fname + "*"):
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
19 try:
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
20 os.unlink(f)
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
21 except OSError:
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
22 pass
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
23
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
24 class WhichDBTestCase(unittest.TestCase):
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
25 # Actual test methods are added to namespace
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
26 # after class definition.
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
27 def __init__(self, *args):
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
28 unittest.TestCase.__init__(self, *args)
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
29
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
30 def tearDown(self):
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
31 _delete_files()
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
32
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
33 def setUp(self):
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
34 _delete_files()
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
35
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
36 for name in anydbm._names:
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
37 # we define a new test method for each
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
38 # candidate database module.
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
39 try:
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
40 mod = __import__(name)
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
41 except ImportError:
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
42 continue
24674
3269bdd65988 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 24488
diff changeset
43
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24710
diff changeset
44 def test_whichdb_name(self, name=name, mod=mod):
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24710
diff changeset
45 # Check whether whichdb correctly guesses module name
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24710
diff changeset
46 # for databases opened with module mod.
29461
8b1766c8ad3b Treat empty dat/dir pairs as dumbdbm. Fixes #744687.
Martin v. Löwis <martin@v.loewis.de>
parents: 24964
diff changeset
47 # Try with empty files first
24488
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
48 f = mod.open(_fname, 'c')
29461
8b1766c8ad3b Treat empty dat/dir pairs as dumbdbm. Fixes #744687.
Martin v. Löwis <martin@v.loewis.de>
parents: 24964
diff changeset
49 f.close()
8b1766c8ad3b Treat empty dat/dir pairs as dumbdbm. Fixes #744687.
Martin v. Löwis <martin@v.loewis.de>
parents: 24964
diff changeset
50 self.assertEqual(name, whichdb.whichdb(_fname))
8b1766c8ad3b Treat empty dat/dir pairs as dumbdbm. Fixes #744687.
Martin v. Löwis <martin@v.loewis.de>
parents: 24964
diff changeset
51 # Now add a key
8b1766c8ad3b Treat empty dat/dir pairs as dumbdbm. Fixes #744687.
Martin v. Löwis <martin@v.loewis.de>
parents: 24964
diff changeset
52 f = mod.open(_fname, 'w')
24488
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
53 f["1"] = "1"
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
54 f.close()
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
55 self.assertEqual(name, whichdb.whichdb(_fname))
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
56 setattr(WhichDBTestCase,"test_whichdb_%s" % name, test_whichdb_name)
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
57
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
58 def test_main():
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
59 try:
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
60 test.test_support.run_unittest(WhichDBTestCase)
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
61 finally:
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
62 _delete_files()
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
63
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
64 if __name__ == "__main__":
df0628662b48 regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
65 test_main()