0001 """Tests for the bsddb185 module. 0002 0003 The file 185test.db found in Lib/test/ is for testing purposes with this 0004 testing suite. 0005 0006 """ 0007 from test.test_support import verbose, run_unittest, findfile 0008 import unittest 0009 import bsddb185 0010 import anydbm 0011 import whichdb 0012 import os 0013 import tempfile 0014 import shutil 0015 0016 class Bsddb185Tests(unittest.TestCase): 0017 0018 def test_open_existing_hash(self): 0019 # Verify we can open a file known to be a hash v2 file 0020 db = bsddb185.hashopen(findfile("185test.db")) 0021 self.assertEqual(db["1"], "1") 0022 db.close() 0023 0024 def test_whichdb(self): 0025 # Verify that whichdb correctly sniffs the known hash v2 file 0026 self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185") 0027 0028 def test_anydbm_create(self): 0029 # Verify that anydbm.open does *not* create a bsddb185 file 0030 tmpdir = tempfile.mkdtemp() 0031 try: 0032 dbfile = os.path.join(tmpdir, "foo.db") 0033 anydbm.open(dbfile, "c").close() 0034 ftype = whichdb.whichdb(dbfile) 0035 self.assertNotEqual(ftype, "bsddb185") 0036 finally: 0037 shutil.rmtree(tmpdir) 0038 0039 def test_main(): 0040 run_unittest(Bsddb185Tests) 0041 0042 if __name__ == "__main__": 0043 test_main() 0044
Generated by PyXR 0.9.4