Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / lib / python2.4 / test / test_bsddb185.py
CommitLineData
920dae64
AT
1"""Tests for the bsddb185 module.
2
3The file 185test.db found in Lib/test/ is for testing purposes with this
4testing suite.
5
6"""
7from test.test_support import verbose, run_unittest, findfile
8import unittest
9import bsddb185
10import anydbm
11import whichdb
12import os
13import tempfile
14import shutil
15
16class Bsddb185Tests(unittest.TestCase):
17
18 def test_open_existing_hash(self):
19 # Verify we can open a file known to be a hash v2 file
20 db = bsddb185.hashopen(findfile("185test.db"))
21 self.assertEqual(db["1"], "1")
22 db.close()
23
24 def test_whichdb(self):
25 # Verify that whichdb correctly sniffs the known hash v2 file
26 self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185")
27
28 def test_anydbm_create(self):
29 # Verify that anydbm.open does *not* create a bsddb185 file
30 tmpdir = tempfile.mkdtemp()
31 try:
32 dbfile = os.path.join(tmpdir, "foo.db")
33 anydbm.open(dbfile, "c").close()
34 ftype = whichdb.whichdb(dbfile)
35 self.assertNotEqual(ftype, "bsddb185")
36 finally:
37 shutil.rmtree(tmpdir)
38
39def test_main():
40 run_unittest(Bsddb185Tests)
41
42if __name__ == "__main__":
43 test_main()