Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_dbm_gnu.TestGdbm Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_key_methods
def test_error_conditions
def test_flags
def test_reorganize

Public Attributes

 g

Detailed Description

Definition at line 10 of file test_dbm_gnu.py.


Member Function Documentation

Definition at line 11 of file test_dbm_gnu.py.

00011 
00012     def setUp(self):
00013         self.g = None

Here is the caller graph for this function:

Definition at line 14 of file test_dbm_gnu.py.

00014 
00015     def tearDown(self):
00016         if self.g is not None:
00017             self.g.close()
00018         unlink(filename)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 40 of file test_dbm_gnu.py.

00040 
00041     def test_error_conditions(self):
00042         # Try to open a non-existent database.
00043         unlink(filename)
00044         self.assertRaises(gdbm.error, gdbm.open, filename, 'r')
00045         # Try to access a closed database.
00046         self.g = gdbm.open(filename, 'c')
00047         self.g.close()
00048         self.assertRaises(gdbm.error, lambda: self.g['a'])
00049         # try pass an invalid open flag
00050         self.assertRaises(gdbm.error, lambda: gdbm.open(filename, 'rx').close())

Here is the call graph for this function:

Definition at line 51 of file test_dbm_gnu.py.

00051 
00052     def test_flags(self):
00053         # Test the flag parameter open() by trying all supported flag modes.
00054         all = set(gdbm.open_flags)
00055         # Test standard flags (presumably "crwn").
00056         modes = all - set('fsu')
00057         for mode in modes:
00058             self.g = gdbm.open(filename, mode)
00059             self.g.close()
00060 
00061         # Test additional flags (presumably "fsu").
00062         flags = all - set('crwn')
00063         for mode in modes:
00064             for flag in flags:
00065                 self.g = gdbm.open(filename, mode + flag)
00066                 self.g.close()

Here is the call graph for this function:

Definition at line 19 of file test_dbm_gnu.py.

00019 
00020     def test_key_methods(self):
00021         self.g = gdbm.open(filename, 'c')
00022         self.assertEqual(self.g.keys(), [])
00023         self.g['a'] = 'b'
00024         self.g['12345678910'] = '019237410982340912840198242'
00025         self.g[b'bytes'] = b'data'
00026         key_set = set(self.g.keys())
00027         self.assertEqual(key_set, set([b'a', b'bytes', b'12345678910']))
00028         self.assertIn(b'a', self.g)
00029         self.assertEqual(self.g[b'bytes'], b'data')
00030         key = self.g.firstkey()
00031         while key:
00032             self.assertIn(key, key_set)
00033             key_set.remove(key)
00034             key = self.g.nextkey(key)
00035         self.assertRaises(KeyError, lambda: self.g['xxx'])
00036         # get() and setdefault() work as in the dict interface
00037         self.assertEqual(self.g.get(b'xxx', b'foo'), b'foo')
00038         self.assertEqual(self.g.setdefault(b'xxx', b'foo'), b'foo')
00039         self.assertEqual(self.g[b'xxx'], b'foo')

Here is the call graph for this function:

Definition at line 67 of file test_dbm_gnu.py.

00067 
00068     def test_reorganize(self):
00069         self.g = gdbm.open(filename, 'c')
00070         size0 = os.path.getsize(filename)
00071 
00072         self.g['x'] = 'x' * 10000
00073         size1 = os.path.getsize(filename)
00074         self.assertTrue(size0 < size1)
00075 
00076         del self.g['x']
00077         # 'size' is supposed to be the same even after deleting an entry.
00078         self.assertEqual(os.path.getsize(filename), size1)
00079 
00080         self.g.reorganize()
00081         size2 = os.path.getsize(filename)
00082         self.assertTrue(size1 > size2 >= size0)
00083 

Here is the call graph for this function:


Member Data Documentation

Definition at line 12 of file test_dbm_gnu.py.


The documentation for this class was generated from the following file: