Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_whichdb.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | b36cb4602e21 |
| children |
| 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 glob |
|
df0628662b48
regression test for the whichdb module
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:
24674
diff
changeset
|
12 _fname = test.test_support.TESTFN |
|
24488
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
13 |
|
63531
30086aa33123
Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
45468
diff
changeset
|
14 # Silence Py3k warning |
|
30086aa33123
Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
45468
diff
changeset
|
15 anydbm = test.test_support.import_module('anydbm', deprecated=True) |
|
30086aa33123
Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
45468
diff
changeset
|
16 |
|
24488
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
17 def _delete_files(): |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
18 # 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
|
19 # so we use glob to locate all names |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
20 for f in glob.glob(_fname + "*"): |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
21 try: |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
22 os.unlink(f) |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
23 except OSError: |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
24 pass |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
25 |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
26 class WhichDBTestCase(unittest.TestCase): |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
27 # Actual test methods are added to namespace |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
28 # after class definition. |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
29 def __init__(self, *args): |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
30 unittest.TestCase.__init__(self, *args) |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
31 |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
32 def tearDown(self): |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
33 _delete_files() |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
34 |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
35 def setUp(self): |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
36 _delete_files() |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
37 |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
38 for name in anydbm._names: |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
39 # we define a new test method for each |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
40 # candidate database module. |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
41 try: |
|
63531
30086aa33123
Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
45468
diff
changeset
|
42 # Silence Py3k warning |
|
30086aa33123
Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
45468
diff
changeset
|
43 mod = test.test_support.import_module(name, deprecated=True) |
|
58580
bfc13ce62fab
#7092: silence py3k warnings for deprecated modules
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
44 except unittest.SkipTest: |
|
24488
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
45 continue |
|
24674
3269bdd65988
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
24488
diff
changeset
|
46 |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24710
diff
changeset
|
47 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
|
48 # 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
|
49 # 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
|
50 # Try with empty files first |
|
24488
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
51 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
|
52 f.close() |
|
8b1766c8ad3b
Treat empty dat/dir pairs as dumbdbm. Fixes #744687.
Martin v. Löwis <martin@v.loewis.de>
parents:
24964
diff
changeset
|
53 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
|
54 # 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
|
55 f = mod.open(_fname, 'w') |
|
24488
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
56 f["1"] = "1" |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
57 f.close() |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
58 self.assertEqual(name, whichdb.whichdb(_fname)) |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
59 setattr(WhichDBTestCase,"test_whichdb_%s" % name, test_whichdb_name) |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
60 |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
61 def test_main(): |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
62 try: |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
63 test.test_support.run_unittest(WhichDBTestCase) |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
64 finally: |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
65 _delete_files() |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
66 |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
67 if __name__ == "__main__": |
|
df0628662b48
regression test for the whichdb module
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
68 test_main() |
