cpython/Lib/test/test_bsddb185.py

44 lines
1.2 KiB
Python
Raw Normal View History

"""Tests for the bsddb185 module.
2003-05-06 17:36:57 -03:00
The file 185test.db found in Lib/test/ is for testing purposes with this
testing suite.
"""
from test.test_support import run_unittest, findfile
2003-05-06 17:36:57 -03:00
import unittest
import bsddb185
import anydbm
import whichdb
import os
import tempfile
2003-05-16 23:54:11 -03:00
import shutil
2003-05-06 17:36:57 -03:00
class Bsddb185Tests(unittest.TestCase):
2003-05-06 17:36:57 -03:00
def test_open_existing_hash(self):
# Verify we can open a file known to be a hash v2 file
2003-05-06 17:36:57 -03:00
db = bsddb185.hashopen(findfile("185test.db"))
self.assertEqual(db["1"], "1")
db.close()
def test_whichdb(self):
# Verify that whichdb correctly sniffs the known hash v2 file
2003-05-06 17:36:57 -03:00
self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185")
def test_anydbm_create(self):
# Verify that anydbm.open does *not* create a bsddb185 file
2003-05-06 17:36:57 -03:00
tmpdir = tempfile.mkdtemp()
try:
2003-05-16 23:54:11 -03:00
dbfile = os.path.join(tmpdir, "foo.db")
anydbm.open(dbfile, "c").close()
ftype = whichdb.whichdb(dbfile)
self.assertNotEqual(ftype, "bsddb185")
2003-05-06 17:36:57 -03:00
finally:
2003-05-16 23:54:11 -03:00
shutil.rmtree(tmpdir)
2003-05-06 17:36:57 -03:00
def test_main():
run_unittest(Bsddb185Tests)
if __name__ == "__main__":
test_main()