diff options
Diffstat (limited to 'python/test/test_recno.py')
-rw-r--r-- | python/test/test_recno.py | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/python/test/test_recno.py b/python/test/test_recno.py index ccd2d753a..bd62cfad5 100644 --- a/python/test/test_recno.py +++ b/python/test/test_recno.py @@ -1,15 +1,19 @@ -""" -TestCases for exercising a Recno DB. +"""TestCases for exercising a Recno DB. """ -import sys, os, string +import os +import sys +import errno import tempfile from pprint import pprint import unittest +from test_all import verbose + from rpmdb import db -from test_all import verbose +letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + #---------------------------------------------------------------------- @@ -20,16 +24,14 @@ class SimpleRecnoTestCase(unittest.TestCase): def tearDown(self): try: os.remove(self.filename) - except os.error: - pass - - + except OSError, e: + if e.errno <> errno.EEXIST: raise def test01_basic(self): d = db.DB() d.open(self.filename, db.DB_RECNO, db.DB_CREATE) - for x in string.letters: + for x in letters: recno = d.append(x * 60) assert type(recno) == type(0) assert recno >= 1 @@ -75,7 +77,6 @@ class SimpleRecnoTestCase(unittest.TestCase): assert type(keys[0]) == type(123) assert len(keys) == len(d) - items = d.items() if verbose: pprint(items) @@ -162,24 +163,26 @@ class SimpleRecnoTestCase(unittest.TestCase): c.close() d.close() - def test02_WithSource(self): """ - A Recno file that is given a "backing source file" is essentially a simple ASCII - file. Normally each record is delimited by \n and so is just a line in the file, - but you can set a different record delimiter if needed. + A Recno file that is given a "backing source file" is essentially a + simple ASCII file. Normally each record is delimited by \n and so is + just a line in the file, but you can set a different record delimiter + if needed. """ - source = os.path.join(os.path.dirname(sys.argv[0]), 'db_home/test_recno.txt') + source = os.path.join(os.path.dirname(sys.argv[0]), + 'db_home/test_recno.txt') f = open(source, 'w') # create the file f.close() d = db.DB() - d.set_re_delim(0x0A) # This is the default value, just checking if both int + # This is the default value, just checking if both int + d.set_re_delim(0x0A) d.set_re_delim('\n') # and char can be used... d.set_re_source(source) d.open(self.filename, db.DB_RECNO, db.DB_CREATE) - data = string.split("The quick brown fox jumped over the lazy dog") + data = "The quick brown fox jumped over the lazy dog".split() for datum in data: d.append(datum) d.sync() @@ -187,13 +190,13 @@ class SimpleRecnoTestCase(unittest.TestCase): # get the text from the backing source text = open(source, 'r').read() - text = string.strip(text) + text = text.strip() if verbose: print text print data - print string.split(text, '\n') + print text.split('\n') - assert string.split(text, '\n') == data + assert text.split('\n') == data # open as a DB again d = db.DB() @@ -207,13 +210,13 @@ class SimpleRecnoTestCase(unittest.TestCase): d.close() text = open(source, 'r').read() - text = string.strip(text) + text = text.strip() if verbose: print text - print string.split(text, '\n') - - assert string.split(text, '\n') == string.split("The quick reddish-brown fox jumped over the comatose dog") + print text.split('\n') + assert text.split('\n') == \ + "The quick reddish-brown fox jumped over the comatose dog".split() def test03_FixedLength(self): d = db.DB() @@ -222,7 +225,7 @@ class SimpleRecnoTestCase(unittest.TestCase): d.set_re_pad(45) # ...test both int and char d.open(self.filename, db.DB_RECNO, db.DB_CREATE) - for x in string.letters: + for x in letters: d.append(x * 35) # These will be padded d.append('.' * 40) # this one will be exact @@ -245,14 +248,13 @@ class SimpleRecnoTestCase(unittest.TestCase): c.close() d.close() + #---------------------------------------------------------------------- -def suite(): +def test_suite(): return unittest.makeSuite(SimpleRecnoTestCase) if __name__ == '__main__': - unittest.main( defaultTest='suite' ) - - + unittest.main(defaultTest='test_suite') |