mirror of
https://github.com/python/cpython.git
synced 2025-10-31 21:51:50 +00:00
bsddb 4.1.6:
* Extended DB & DBEnv set_get_returns_none functionality to take a "level" instead of a boolean flag. The boolean 0 and 1 values still have the same effect. A value of 2 extends the "return None instead of raising an exception" behaviour to the DBCursor set methods. This will become the default behaviour in pybsddb 4.2. * Fixed a typo in DBCursor.join_item method that made it crash instead of returning a value. Obviously nobody uses it. Wrote a test case for join and join_item.
This commit is contained in:
parent
bea57c6c35
commit
455d46f0d9
6 changed files with 284 additions and 51 deletions
|
|
@ -282,11 +282,11 @@ def test02_DictionaryMethods(self):
|
|||
|
||||
#----------------------------------------
|
||||
|
||||
def test03_SimpleCursorStuff(self):
|
||||
def test03_SimpleCursorStuff(self, get_raises_error=0, set_raises_error=1):
|
||||
if verbose:
|
||||
print '\n', '-=' * 30
|
||||
print "Running %s.test03_SimpleCursorStuff..." % \
|
||||
self.__class__.__name__
|
||||
print "Running %s.test03_SimpleCursorStuff (get_error %s, set_error %s)..." % \
|
||||
(self.__class__.__name__, get_raises_error, set_raises_error)
|
||||
|
||||
if self.env and self.dbopenflags & db.DB_AUTO_COMMIT:
|
||||
txn = self.env.txn_begin()
|
||||
|
|
@ -300,7 +300,15 @@ def test03_SimpleCursorStuff(self):
|
|||
count = count + 1
|
||||
if verbose and count % 100 == 0:
|
||||
print rec
|
||||
rec = c.next()
|
||||
try:
|
||||
rec = c.next()
|
||||
except db.DBNotFoundError, val:
|
||||
if get_raises_error:
|
||||
assert val[0] == db.DB_NOTFOUND
|
||||
if verbose: print val
|
||||
rec = None
|
||||
else:
|
||||
self.fail("unexpected DBNotFoundError")
|
||||
|
||||
assert count == 1000
|
||||
|
||||
|
|
@ -311,7 +319,15 @@ def test03_SimpleCursorStuff(self):
|
|||
count = count + 1
|
||||
if verbose and count % 100 == 0:
|
||||
print rec
|
||||
rec = c.prev()
|
||||
try:
|
||||
rec = c.prev()
|
||||
except db.DBNotFoundError, val:
|
||||
if get_raises_error:
|
||||
assert val[0] == db.DB_NOTFOUND
|
||||
if verbose: print val
|
||||
rec = None
|
||||
else:
|
||||
self.fail("unexpected DBNotFoundError")
|
||||
|
||||
assert count == 1000
|
||||
|
||||
|
|
@ -322,23 +338,29 @@ def test03_SimpleCursorStuff(self):
|
|||
assert rec[1] == self.makeData('0505')
|
||||
|
||||
try:
|
||||
c.set('bad key')
|
||||
n = c.set('bad key')
|
||||
except db.DBNotFoundError, val:
|
||||
assert val[0] == db.DB_NOTFOUND
|
||||
if verbose: print val
|
||||
else:
|
||||
self.fail("expected exception")
|
||||
if set_raises_error:
|
||||
self.fail("expected exception")
|
||||
if n != None:
|
||||
self.fail("expected None: "+`n`)
|
||||
|
||||
rec = c.get_both('0404', self.makeData('0404'))
|
||||
assert rec == ('0404', self.makeData('0404'))
|
||||
|
||||
try:
|
||||
c.get_both('0404', 'bad data')
|
||||
n = c.get_both('0404', 'bad data')
|
||||
except db.DBNotFoundError, val:
|
||||
assert val[0] == db.DB_NOTFOUND
|
||||
if verbose: print val
|
||||
else:
|
||||
self.fail("expected exception")
|
||||
if get_raises_error:
|
||||
self.fail("expected exception")
|
||||
if n != None:
|
||||
self.fail("expected None: "+`n`)
|
||||
|
||||
if self.d.get_type() == db.DB_BTREE:
|
||||
rec = c.set_range('011')
|
||||
|
|
@ -414,6 +436,29 @@ def test03_SimpleCursorStuff(self):
|
|||
# SF pybsddb bug id 667343
|
||||
del oldcursor
|
||||
|
||||
def test03b_SimpleCursorWithoutGetReturnsNone0(self):
|
||||
# same test but raise exceptions instead of returning None
|
||||
if verbose:
|
||||
print '\n', '-=' * 30
|
||||
print "Running %s.test03b_SimpleCursorStuffWithoutGetReturnsNone..." % \
|
||||
self.__class__.__name__
|
||||
|
||||
old = self.d.set_get_returns_none(0)
|
||||
assert old == 1
|
||||
self.test03_SimpleCursorStuff(get_raises_error=1, set_raises_error=1)
|
||||
|
||||
def test03c_SimpleCursorGetReturnsNone2(self):
|
||||
# same test but raise exceptions instead of returning None
|
||||
if verbose:
|
||||
print '\n', '-=' * 30
|
||||
print "Running %s.test03c_SimpleCursorStuffWithoutSetReturnsNone..." % \
|
||||
self.__class__.__name__
|
||||
|
||||
old = self.d.set_get_returns_none(2)
|
||||
assert old == 1
|
||||
old = self.d.set_get_returns_none(2)
|
||||
assert old == 2
|
||||
self.test03_SimpleCursorStuff(get_raises_error=0, set_raises_error=0)
|
||||
|
||||
#----------------------------------------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue