blob: 48a07641a759f30f0f3fdc77cc7d966636e5a760 [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"
13 # do we need to worry about big vs little endian?
14 db = bsddb185.hashopen(findfile("185test.db"))
15 self.assertEqual(db["1"], "1")
16 db.close()
17
18 def test_whichdb(self):
19 "verify that whichdb correctly sniffs the known hash v2 file"
20 self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185")
21
22 def test_anydbm_create(self):
23 "verify that anydbm.open does *not* create a bsddb185 file"
24 tmpdir = tempfile.mkdtemp()
25 try:
26 try:
27 dbfile = os.path.join(tmpdir, "foo.db")
28 anydbm.open(dbfile, "c").close()
29 ftype = whichdb.whichdb(findfile("foo.db"))
30 self.assertNotEqual(ftype, "bsddb185")
31 finally:
32 os.unlink(dbfile)
33 finally:
34 os.rmdir(tmpdir)
35
36def test_main():
37 run_unittest(Bsddb185Tests)
38
39if __name__ == "__main__":
40 test_main()