test_bsddb185.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """Tests for the bsddb185 module.
  2. The file 185test.db found in Lib/test/ is for testing purposes with this
  3. testing suite.
  4. """
  5. from test.test_support import run_unittest, findfile, import_module
  6. import unittest
  7. bsddb185 = import_module('bsddb185', deprecated=True)
  8. import anydbm
  9. import whichdb
  10. import os
  11. import tempfile
  12. import shutil
  13. class Bsddb185Tests(unittest.TestCase):
  14. def test_open_existing_hash(self):
  15. # Verify we can open a file known to be a hash v2 file
  16. db = bsddb185.hashopen(findfile("185test.db"))
  17. self.assertEqual(db["1"], "1")
  18. db.close()
  19. def test_whichdb(self):
  20. # Verify that whichdb correctly sniffs the known hash v2 file
  21. self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185")
  22. def test_anydbm_create(self):
  23. # Verify that anydbm.open does *not* create a bsddb185 file
  24. tmpdir = tempfile.mkdtemp()
  25. try:
  26. dbfile = os.path.join(tmpdir, "foo.db")
  27. anydbm.open(dbfile, "c").close()
  28. ftype = whichdb.whichdb(dbfile)
  29. self.assertNotEqual(ftype, "bsddb185")
  30. finally:
  31. shutil.rmtree(tmpdir)
  32. def test_main():
  33. run_unittest(Bsddb185Tests)
  34. if __name__ == "__main__":
  35. test_main()