blob: ceacf4dddc577e123dec03e54c3017e713212477 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
"""Tests for the bsddb185 module.
The file 185test.db found in Lib/test/ is for testing purposes with this
testing suite.
"""
from test.test_support import verbose, run_unittest, findfile
import unittest
import bsddb185
import anydbm
import whichdb
import os
import tempfile
class Bsddb185Tests(unittest.TestCase):
def test_open_existing_hash(self):
# Verify we can open a file known to be a hash v2 file
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
self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185")
def test_anydbm_create(self):
# Verify that anydbm.open does *not* create a bsddb185 file
tmpdir = tempfile.mkdtemp()
try:
try:
dbfile = os.path.join(tmpdir, "foo.db")
anydbm.open(os.path.splitext(dbfile)[0], "c").close()
ftype = whichdb.whichdb(dbfile)
self.assertNotEqual(ftype, "bsddb185")
finally:
os.unlink(dbfile)
finally:
os.rmdir(tmpdir)
def test_main():
run_unittest(Bsddb185Tests)
if __name__ == "__main__":
test_main()
|