diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2002-11-19 17:47:07 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2002-11-19 17:47:07 (GMT) |
commit | 1c6b1a2b4ea38955a3f0514f4709bafd0be96c5e (patch) | |
tree | 1d75385f12cdeda7369e5a2428d33649e6b70380 /Lib/bsddb/test/test_get_none.py | |
parent | a406b58619e3fd8fb26ced18ac64b475a48648d2 (diff) | |
download | cpython-1c6b1a2b4ea38955a3f0514f4709bafd0be96c5e.zip cpython-1c6b1a2b4ea38955a3f0514f4709bafd0be96c5e.tar.gz cpython-1c6b1a2b4ea38955a3f0514f4709bafd0be96c5e.tar.bz2 |
Importing test suite from bsddb3 3.4.0 (with modifications).
Diffstat (limited to 'Lib/bsddb/test/test_get_none.py')
-rw-r--r-- | Lib/bsddb/test/test_get_none.py | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/Lib/bsddb/test/test_get_none.py b/Lib/bsddb/test/test_get_none.py new file mode 100644 index 0000000..0e1fa93 --- /dev/null +++ b/Lib/bsddb/test/test_get_none.py @@ -0,0 +1,98 @@ +""" +TestCases for checking set_get_returns_none. +""" + +import sys, os, string +import tempfile +from pprint import pprint +import unittest + +from bsddb import db + +from test.test_support import verbose + + +#---------------------------------------------------------------------- + +class GetReturnsNoneTestCase(unittest.TestCase): + def setUp(self): + self.filename = tempfile.mktemp() + + def tearDown(self): + try: + os.remove(self.filename) + except os.error: + pass + + + def test01_get_returns_none(self): + d = db.DB() + d.open(self.filename, db.DB_BTREE, db.DB_CREATE) + d.set_get_returns_none(1) + + for x in string.letters: + d.put(x, x * 40) + + data = d.get('bad key') + assert data == None + + data = d.get('a') + assert data == 'a'*40 + + count = 0 + c = d.cursor() + rec = c.first() + while rec: + count = count + 1 + rec = c.next() + + assert rec == None + assert count == 52 + + c.close() + d.close() + + + def test02_get_raises_exception(self): + d = db.DB() + d.open(self.filename, db.DB_BTREE, db.DB_CREATE) + d.set_get_returns_none(0) + + for x in string.letters: + d.put(x, x * 40) + + self.assertRaises(db.DBNotFoundError, d.get, 'bad key') + self.assertRaises(KeyError, d.get, 'bad key') + + data = d.get('a') + assert data == 'a'*40 + + count = 0 + exceptionHappened = 0 + c = d.cursor() + rec = c.first() + while rec: + count = count + 1 + try: + rec = c.next() + except db.DBNotFoundError: # end of the records + exceptionHappened = 1 + break + + assert rec != None + assert exceptionHappened + assert count == 52 + + c.close() + d.close() + +#---------------------------------------------------------------------- + +def suite(): + return unittest.makeSuite(GetReturnsNoneTestCase) + + +if __name__ == '__main__': + unittest.main( defaultTest='suite' ) + + |