Skip Montanaro | 46f4e79 | 2003-05-06 20:36:57 +0000 | [diff] [blame^] | 1 | |
| 2 | from test.test_support import verbose, run_unittest, findfile |
| 3 | import unittest |
| 4 | import bsddb185 |
| 5 | import anydbm |
| 6 | import whichdb |
| 7 | import os |
| 8 | import tempfile |
| 9 | |
| 10 | class Bsddb185Tests(unittest.TestCase): |
| 11 | def test_open_existing_hash(self): |
| 12 | "verify we can open a file known to be a hash v2 file" |
| 13 | # do we need to worry about big vs little endian? |
| 14 | db = bsddb185.hashopen(findfile("185test.db")) |
| 15 | self.assertEqual(db["1"], "1") |
| 16 | db.close() |
| 17 | |
| 18 | def test_whichdb(self): |
| 19 | "verify that whichdb correctly sniffs the known hash v2 file" |
| 20 | self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185") |
| 21 | |
| 22 | def test_anydbm_create(self): |
| 23 | "verify that anydbm.open does *not* create a bsddb185 file" |
| 24 | tmpdir = tempfile.mkdtemp() |
| 25 | try: |
| 26 | try: |
| 27 | dbfile = os.path.join(tmpdir, "foo.db") |
| 28 | anydbm.open(dbfile, "c").close() |
| 29 | ftype = whichdb.whichdb(findfile("foo.db")) |
| 30 | self.assertNotEqual(ftype, "bsddb185") |
| 31 | finally: |
| 32 | os.unlink(dbfile) |
| 33 | finally: |
| 34 | os.rmdir(tmpdir) |
| 35 | |
| 36 | def test_main(): |
| 37 | run_unittest(Bsddb185Tests) |
| 38 | |
| 39 | if __name__ == "__main__": |
| 40 | test_main() |