Test cases adapted from the test_bsddb.py module in Python's
from test_all
import verbose
# For Pythons w/distutils pybsddb
from bsddb3
import db
, hashopen
, btopen
, rnopen
from bsddb
import db
, hashopen
, btopen
, rnopen
class CompatibilityTestCase(unittest
.TestCase
):
self
.filename
= tempfile
.mktemp()
self
.do_bthash_test(btopen
, 'btopen')
def test02_hashopen(self
):
self
.do_bthash_test(hashopen
, 'hashopen')
data
= string
.split("The quick brown fox jumped over the lazy dog.")
print "\nTesting: rnopen"
f
= rnopen(self
.filename
, 'c')
for x
in range(len(data
)):
getTest
= (f
[1], f
[2], f
[3])
print '%s %s %s' % getTest
assert getTest
[1] == 'quick', 'data mismatch!'
self
.fail('recno database set_location failed: '+repr(rv
))
f
= rnopen(self
.filename
, 'w')
self
.assertRaises(KeyError, noRec
, f
)
self
.assertRaises(TypeError, badKey
, f
)
f
= hashopen(self
.filename
, 'n')
def do_bthash_test(self
, factory
, what
):
print '\nTesting: ', what
f
= factory(self
.filename
, 'c')
if verbose
: print "truth test: true"
if verbose
: print "truth test: false"
# 'e' intentionally left out
print '%s %s %s' % (f
['a'], f
['b'], f
['c'])
start
= f
.set_location(f
.first()[0])
self
.fail("incorrect first() result: "+repr(start
))
assert rec
== f
.last(), 'Error, last <> last!'
assert f
.has_key('f'), 'Error, missing key!'
# test that set_location() returns the next nearest key, value
# on btree databases and raises KeyError on others.
self
.fail('wrong key,value returned: '+repr(e
))
self
.fail("set_location on non-existant key did not raise KeyError")
if verbose
: print "truth test: true"
if verbose
: print "truth test: false"
self
.fail("Exception expected")
f
= factory(self
.filename
, 'w')
self
.assertRaises(KeyError, noRec
, f
)
self
.assertRaises(TypeError, badKey
, f
)
#----------------------------------------------------------------------
return unittest
.makeSuite(CompatibilityTestCase
)
if __name__
== '__main__':
unittest
.main(defaultTest
='test_suite')