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" |
Skip Montanaro | 46f4e79 | 2003-05-06 20:36:57 +0000 | [diff] [blame] | 13 | db = bsddb185.hashopen(findfile("185test.db")) |
| 14 | self.assertEqual(db["1"], "1") |
| 15 | db.close() |
| 16 | |
| 17 | def test_whichdb(self): |
| 18 | "verify that whichdb correctly sniffs the known hash v2 file" |
| 19 | self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185") |
| 20 | |
| 21 | def test_anydbm_create(self): |
| 22 | "verify that anydbm.open does *not* create a bsddb185 file" |
| 23 | tmpdir = tempfile.mkdtemp() |
| 24 | try: |
| 25 | try: |
| 26 | dbfile = os.path.join(tmpdir, "foo.db") |
| 27 | anydbm.open(dbfile, "c").close() |
| 28 | ftype = whichdb.whichdb(findfile("foo.db")) |
| 29 | self.assertNotEqual(ftype, "bsddb185") |
| 30 | finally: |
| 31 | os.unlink(dbfile) |
| 32 | finally: |
| 33 | os.rmdir(tmpdir) |
| 34 | |
| 35 | def test_main(): |
| 36 | run_unittest(Bsddb185Tests) |
| 37 | |
| 38 | if __name__ == "__main__": |
| 39 | test_main() |