]>
Commit | Line | Data |
---|---|---|
4710c53d | 1 | """Tests for the bsddb185 module.\r |
2 | \r | |
3 | The file 185test.db found in Lib/test/ is for testing purposes with this\r | |
4 | testing suite.\r | |
5 | \r | |
6 | """\r | |
7 | from test.test_support import run_unittest, findfile, import_module\r | |
8 | import unittest\r | |
9 | bsddb185 = import_module('bsddb185', deprecated=True)\r | |
10 | import anydbm\r | |
11 | import whichdb\r | |
12 | import os\r | |
13 | import tempfile\r | |
14 | import shutil\r | |
15 | \r | |
16 | class Bsddb185Tests(unittest.TestCase):\r | |
17 | \r | |
18 | def test_open_existing_hash(self):\r | |
19 | # Verify we can open a file known to be a hash v2 file\r | |
20 | db = bsddb185.hashopen(findfile("185test.db"))\r | |
21 | self.assertEqual(db["1"], "1")\r | |
22 | db.close()\r | |
23 | \r | |
24 | def test_whichdb(self):\r | |
25 | # Verify that whichdb correctly sniffs the known hash v2 file\r | |
26 | self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185")\r | |
27 | \r | |
28 | def test_anydbm_create(self):\r | |
29 | # Verify that anydbm.open does *not* create a bsddb185 file\r | |
30 | tmpdir = tempfile.mkdtemp()\r | |
31 | try:\r | |
32 | dbfile = os.path.join(tmpdir, "foo.db")\r | |
33 | anydbm.open(dbfile, "c").close()\r | |
34 | ftype = whichdb.whichdb(dbfile)\r | |
35 | self.assertNotEqual(ftype, "bsddb185")\r | |
36 | finally:\r | |
37 | shutil.rmtree(tmpdir)\r | |
38 | \r | |
39 | def test_main():\r | |
40 | run_unittest(Bsddb185Tests)\r | |
41 | \r | |
42 | if __name__ == "__main__":\r | |
43 | test_main()\r |