summaryrefslogtreecommitdiffstats
path: root/Lib/bsddb/test/test_get_none.py
diff options
context:
space:
mode:
authorJesus Cea <jcea@jcea.es>2008-08-31 14:12:11 (GMT)
committerJesus Cea <jcea@jcea.es>2008-08-31 14:12:11 (GMT)
commit6ba3329c274e2c7876c61f2e98d4592310d26bae (patch)
tree6bb346e892269279fa2011c3e4bd4648b273a7ae /Lib/bsddb/test/test_get_none.py
parent73c96dbf34c70bbf1ef807b98d51cf9c0e9dc042 (diff)
downloadcpython-6ba3329c274e2c7876c61f2e98d4592310d26bae.zip
cpython-6ba3329c274e2c7876c61f2e98d4592310d26bae.tar.gz
cpython-6ba3329c274e2c7876c61f2e98d4592310d26bae.tar.bz2
bsddb code updated to version 4.7.3pre2. This code is the same than
Python 2.6 one, since the intention is to keep an unified 2.x/3.x codebase. The Python code is automatically translated using "2to3". Please, do not update this code in Python 3.0 by hand. Update the 2.6 one and then do "2to3".
Diffstat (limited to 'Lib/bsddb/test/test_get_none.py')
-rw-r--r--Lib/bsddb/test/test_get_none.py47
1 files changed, 20 insertions, 27 deletions
diff --git a/Lib/bsddb/test/test_get_none.py b/Lib/bsddb/test/test_get_none.py
index 02840e6..abf2421 100644
--- a/Lib/bsddb/test/test_get_none.py
+++ b/Lib/bsddb/test/test_get_none.py
@@ -2,22 +2,17 @@
TestCases for checking set_get_returns_none.
"""
-import sys, os, string
-import tempfile
-from pprint import pprint
+import os, string
import unittest
-from bsddb import db
+from .test_all import db, verbose, get_new_database_path
-from bsddb.test.test_all import verbose
-
-letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
#----------------------------------------------------------------------
class GetReturnsNoneTestCase(unittest.TestCase):
def setUp(self):
- self.filename = tempfile.mktemp()
+ self.filename = get_new_database_path()
def tearDown(self):
try:
@@ -31,25 +26,24 @@ class GetReturnsNoneTestCase(unittest.TestCase):
d.open(self.filename, db.DB_BTREE, db.DB_CREATE)
d.set_get_returns_none(1)
- for x in letters:
- x = x.encode("ascii")
+ for x in string.letters:
d.put(x, x * 40)
- data = d.get(b'bad key')
- assert data == None
+ data = d.get('bad key')
+ self.assertEqual(data, None)
- data = d.get(b'a')
- assert data == b'a'*40
+ data = d.get(string.letters[0])
+ self.assertEqual(data, string.letters[0]*40)
count = 0
c = d.cursor()
rec = c.first()
while rec:
count = count + 1
- rec = c.next()
+ rec = next(c)
- assert rec == None
- assert count == 52
+ self.assertEqual(rec, None)
+ self.assertEqual(count, len(string.letters))
c.close()
d.close()
@@ -60,15 +54,14 @@ class GetReturnsNoneTestCase(unittest.TestCase):
d.open(self.filename, db.DB_BTREE, db.DB_CREATE)
d.set_get_returns_none(0)
- for x in letters:
- x = x.encode("ascii")
+ for x in string.letters:
d.put(x, x * 40)
- self.assertRaises(db.DBNotFoundError, d.get, b'bad key')
- self.assertRaises(KeyError, d.get, b'bad key')
+ self.assertRaises(db.DBNotFoundError, d.get, 'bad key')
+ self.assertRaises(KeyError, d.get, 'bad key')
- data = d.get(b'a')
- assert data == b'a'*40
+ data = d.get(string.letters[0])
+ self.assertEqual(data, string.letters[0]*40)
count = 0
exceptionHappened = 0
@@ -77,14 +70,14 @@ class GetReturnsNoneTestCase(unittest.TestCase):
while rec:
count = count + 1
try:
- rec = c.next()
+ rec = next(c)
except db.DBNotFoundError: # end of the records
exceptionHappened = 1
break
- assert rec != None
- assert exceptionHappened
- assert count == 52
+ self.assertNotEqual(rec, None)
+ self.assert_(exceptionHappened)
+ self.assertEqual(count, len(string.letters))
c.close()
d.close()