blob: ceacf4dddc577e123dec03e54c3017e713212477 [file] [log] [blame]
Brett Cannon065f7b82003-05-13 06:42:59 +00001"""Tests for the bsddb185 module.
Skip Montanaro46f4e792003-05-06 20:36:57 +00002
Brett Cannon065f7b82003-05-13 06:42:59 +00003The file 185test.db found in Lib/test/ is for testing purposes with this
4testing suite.
5
6"""
Skip Montanaro46f4e792003-05-06 20:36:57 +00007from test.test_support import verbose, run_unittest, findfile
8import unittest
9import bsddb185
10import anydbm
11import whichdb
12import os
13import tempfile
14
15class Bsddb185Tests(unittest.TestCase):
Brett Cannon065f7b82003-05-13 06:42:59 +000016
Skip Montanaro46f4e792003-05-06 20:36:57 +000017 def test_open_existing_hash(self):
Brett Cannon065f7b82003-05-13 06:42:59 +000018 # Verify we can open a file known to be a hash v2 file
Skip Montanaro46f4e792003-05-06 20:36:57 +000019 db = bsddb185.hashopen(findfile("185test.db"))
20 self.assertEqual(db["1"], "1")
21 db.close()
22
23 def test_whichdb(self):
Brett Cannon065f7b82003-05-13 06:42:59 +000024 # Verify that whichdb correctly sniffs the known hash v2 file
Skip Montanaro46f4e792003-05-06 20:36:57 +000025 self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185")
26
27 def test_anydbm_create(self):
Brett Cannon065f7b82003-05-13 06:42:59 +000028 # Verify that anydbm.open does *not* create a bsddb185 file
Skip Montanaro46f4e792003-05-06 20:36:57 +000029 tmpdir = tempfile.mkdtemp()
30 try:
31 try:
32 dbfile = os.path.join(tmpdir, "foo.db")
Brett Cannon065f7b82003-05-13 06:42:59 +000033 anydbm.open(os.path.splitext(dbfile)[0], "c").close()
34 ftype = whichdb.whichdb(dbfile)
Skip Montanaro46f4e792003-05-06 20:36:57 +000035 self.assertNotEqual(ftype, "bsddb185")
36 finally:
37 os.unlink(dbfile)
38 finally:
39 os.rmdir(tmpdir)
40
41def test_main():
42 run_unittest(Bsddb185Tests)
43
44if __name__ == "__main__":
45 test_main()