symbian-qemu-0.9.1-12/python-2.6.1/Lib/test/test_dbm.py
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 from test import test_support
       
     2 import unittest
       
     3 import dbm
       
     4 
       
     5 class DbmTestCase(unittest.TestCase):
       
     6 
       
     7     def setUp(self):
       
     8         self.filename = test_support.TESTFN
       
     9         self.d = dbm.open(self.filename, 'c')
       
    10         self.d.close()
       
    11 
       
    12     def tearDown(self):
       
    13         for suffix in ['', '.pag', '.dir', '.db']:
       
    14             test_support.unlink(self.filename + suffix)
       
    15 
       
    16     def test_keys(self):
       
    17         self.d = dbm.open(self.filename, 'c')
       
    18         self.assertEqual(self.d.keys(), [])
       
    19         a = [('a', 'b'), ('12345678910', '019237410982340912840198242')]
       
    20         for k, v in a:
       
    21             self.d[k] = v
       
    22         self.assertEqual(sorted(self.d.keys()), sorted(k for (k, v) in a))
       
    23         for k, v in a:
       
    24             self.assert_(k in self.d)
       
    25             self.assertEqual(self.d[k], v)
       
    26         self.assert_('xxx' not in self.d)
       
    27         self.assertRaises(KeyError, lambda: self.d['xxx'])
       
    28         self.d.close()
       
    29 
       
    30     def test_modes(self):
       
    31         for mode in ['r', 'rw', 'w', 'n']:
       
    32             try:
       
    33                 self.d = dbm.open(self.filename, mode)
       
    34                 self.d.close()
       
    35             except dbm.error:
       
    36                 self.fail()
       
    37 
       
    38 def test_main():
       
    39     test_support.run_unittest(DbmTestCase)
       
    40 
       
    41 if __name__ == '__main__':
       
    42     test_main()