2002-08-02 14:10:10 -03:00
|
|
|
#! /usr/bin/env python
|
|
|
|
"""Test script for the whichdb module
|
|
|
|
based on test_anydbm.py
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import test.test_support
|
|
|
|
import unittest
|
|
|
|
import whichdb
|
|
|
|
import anydbm
|
|
|
|
import tempfile
|
|
|
|
import glob
|
2007-08-24 18:59:45 -03:00
|
|
|
from test.test_anydbm import delete_files, dbm_iterator
|
2002-08-02 14:10:10 -03:00
|
|
|
|
2002-08-09 13:38:32 -03:00
|
|
|
_fname = test.test_support.TESTFN
|
2002-08-02 14:10:10 -03:00
|
|
|
|
|
|
|
class WhichDBTestCase(unittest.TestCase):
|
|
|
|
# Actual test methods are added to namespace
|
|
|
|
# after class definition.
|
|
|
|
def __init__(self, *args):
|
|
|
|
unittest.TestCase.__init__(self, *args)
|
|
|
|
|
2007-08-24 18:59:45 -03:00
|
|
|
def test_whichdb(self):
|
|
|
|
for module in dbm_iterator():
|
|
|
|
# Check whether whichdb correctly guesses module name
|
|
|
|
# for databases opened with "module" module.
|
|
|
|
# Try with empty files first
|
|
|
|
name = module.__name__
|
|
|
|
if name == 'dumbdbm':
|
|
|
|
continue # whichdb can't support dumbdbm
|
2007-08-25 15:00:36 -03:00
|
|
|
test.test_support.unlink(_fname)
|
2007-08-24 18:59:45 -03:00
|
|
|
f = module.open(_fname, 'c')
|
|
|
|
f.close()
|
|
|
|
self.assertEqual(name, whichdb.whichdb(_fname))
|
|
|
|
# Now add a key
|
|
|
|
f = module.open(_fname, 'w')
|
|
|
|
f[b"1"] = b"1"
|
|
|
|
# and test that we can find it
|
2007-08-24 19:14:21 -03:00
|
|
|
self.assertTrue(b"1" in f)
|
2007-08-24 18:59:45 -03:00
|
|
|
# and read it
|
2007-08-24 19:14:21 -03:00
|
|
|
self.assertTrue(f[b"1"] == b"1")
|
2007-08-24 18:59:45 -03:00
|
|
|
f.close()
|
|
|
|
self.assertEqual(name, whichdb.whichdb(_fname))
|
|
|
|
|
2002-08-02 14:10:10 -03:00
|
|
|
def tearDown(self):
|
2007-08-24 18:59:45 -03:00
|
|
|
delete_files()
|
2002-08-02 14:10:10 -03:00
|
|
|
|
|
|
|
def setUp(self):
|
2007-08-24 18:59:45 -03:00
|
|
|
delete_files()
|
2002-08-08 17:19:19 -03:00
|
|
|
|
2002-08-02 14:10:10 -03:00
|
|
|
|
|
|
|
def test_main():
|
|
|
|
try:
|
|
|
|
test.test_support.run_unittest(WhichDBTestCase)
|
|
|
|
finally:
|
2007-08-24 18:59:45 -03:00
|
|
|
delete_files()
|
2002-08-02 14:10:10 -03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_main()
|