blob: 98102c1457992dcaac64ecaaa5678be6ca60d6df [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"""
Brett Cannon768d44f2008-05-10 02:47:54 +00007from test.test_support import run_unittest, findfile, import_module
Skip Montanaro46f4e792003-05-06 20:36:57 +00008import unittest
Brett Cannon768d44f2008-05-10 02:47:54 +00009bsddb185 = import_module('bsddb185', deprecated=True)
Skip Montanaro46f4e792003-05-06 20:36:57 +000010import anydbm
11import whichdb
12import os
13import tempfile
Skip Montanaroab0053a2003-05-17 02:54:11 +000014import shutil
Skip Montanaro46f4e792003-05-06 20:36:57 +000015
16class Bsddb185Tests(unittest.TestCase):
Brett Cannon065f7b82003-05-13 06:42:59 +000017
Skip Montanaro46f4e792003-05-06 20:36:57 +000018 def test_open_existing_hash(self):
Brett Cannon065f7b82003-05-13 06:42:59 +000019 # Verify we can open a file known to be a hash v2 file
Skip Montanaro46f4e792003-05-06 20:36:57 +000020 db = bsddb185.hashopen(findfile("185test.db"))
21 self.assertEqual(db["1"], "1")
22 db.close()
23
24 def test_whichdb(self):
Brett Cannon065f7b82003-05-13 06:42:59 +000025 # Verify that whichdb correctly sniffs the known hash v2 file
Skip Montanaro46f4e792003-05-06 20:36:57 +000026 self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185")
27
28 def test_anydbm_create(self):
Brett Cannon065f7b82003-05-13 06:42:59 +000029 # Verify that anydbm.open does *not* create a bsddb185 file
Skip Montanaro46f4e792003-05-06 20:36:57 +000030 tmpdir = tempfile.mkdtemp()
31 try:
Skip Montanaroab0053a2003-05-17 02:54:11 +000032 dbfile = os.path.join(tmpdir, "foo.db")
33 anydbm.open(dbfile, "c").close()
34 ftype = whichdb.whichdb(dbfile)
35 self.assertNotEqual(ftype, "bsddb185")
Skip Montanaro46f4e792003-05-06 20:36:57 +000036 finally:
Skip Montanaroab0053a2003-05-17 02:54:11 +000037 shutil.rmtree(tmpdir)
Skip Montanaro46f4e792003-05-06 20:36:57 +000038
39def test_main():
40 run_unittest(Bsddb185Tests)
41
42if __name__ == "__main__":
43 test_main()