blob: c7eac3f2cc61797fa8251a4196051a7e5f9061fb [file] [log] [blame]
Skip Montanaro46f4e792003-05-06 20:36:57 +00001
2from test.test_support import verbose, run_unittest, findfile
3import unittest
4import bsddb185
5import anydbm
6import whichdb
7import os
8import tempfile
9
10class Bsddb185Tests(unittest.TestCase):
11 def test_open_existing_hash(self):
12 "verify we can open a file known to be a hash v2 file"
Skip Montanaro46f4e792003-05-06 20:36:57 +000013 db = bsddb185.hashopen(findfile("185test.db"))
14 self.assertEqual(db["1"], "1")
15 db.close()
16
17 def test_whichdb(self):
18 "verify that whichdb correctly sniffs the known hash v2 file"
19 self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185")
20
21 def test_anydbm_create(self):
22 "verify that anydbm.open does *not* create a bsddb185 file"
23 tmpdir = tempfile.mkdtemp()
24 try:
25 try:
26 dbfile = os.path.join(tmpdir, "foo.db")
27 anydbm.open(dbfile, "c").close()
28 ftype = whichdb.whichdb(findfile("foo.db"))
29 self.assertNotEqual(ftype, "bsddb185")
30 finally:
31 os.unlink(dbfile)
32 finally:
33 os.rmdir(tmpdir)
34
35def test_main():
36 run_unittest(Bsddb185Tests)
37
38if __name__ == "__main__":
39 test_main()