Back to index

python3.2  3.2.2
Public Member Functions | Static Private Attributes
test.test_dbm_dumb.DumbDBMTestCase Class Reference

List of all members.

Public Member Functions

def __init__
def test_dumbdbm_creation
def test_dumbdbm_creation_mode
def test_close_twice
def test_dumbdbm_modification
def test_dumbdbm_read
def test_dumbdbm_keys
def test_write_contains
def test_write_write_read
def test_str_read
def test_str_write_contains
def test_line_endings
def read_helper
def init_db
def keys_helper
def test_random
def tearDown
def setUp

Static Private Attributes

dictionary _dict

Detailed Description

Definition at line 21 of file test_dbm_dumb.py.


Constructor & Destructor Documentation

def test.test_dbm_dumb.DumbDBMTestCase.__init__ (   self,
  args 
)

Definition at line 32 of file test_dbm_dumb.py.

00032 
00033     def __init__(self, *args):
00034         unittest.TestCase.__init__(self, *args)

Here is the caller graph for this function:


Member Function Documentation

Definition at line 154 of file test_dbm_dumb.py.

00154 
00155     def init_db(self):
00156         f = dumbdbm.open(_fname, 'w')
00157         for k in self._dict:
00158             f[k] = self._dict[k]
00159         f.close()

Here is the caller graph for this function:

Definition at line 160 of file test_dbm_dumb.py.

00160 
00161     def keys_helper(self, f):
00162         keys = sorted(f.keys())
00163         dkeys = sorted(self._dict.keys())
00164         self.assertEqual(keys, dkeys)
00165         return keys

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 149 of file test_dbm_dumb.py.

00149 
00150     def read_helper(self, f):
00151         keys = self.keys_helper(f)
00152         for key in self._dict:
00153             self.assertEqual(self._dict[key], f[key])

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 195 of file test_dbm_dumb.py.

00195 
00196     def setUp(self):
00197         _delete_files()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 192 of file test_dbm_dumb.py.

00192 
00193     def tearDown(self):
00194         _delete_files()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 67 of file test_dbm_dumb.py.

00067 
00068     def test_close_twice(self):
00069         f = dumbdbm.open(_fname)
00070         f[b'a'] = b'b'
00071         self.assertEqual(f[b'a'], b'b')
00072         f.close()
00073         f.close()

Here is the call graph for this function:

Definition at line 35 of file test_dbm_dumb.py.

00035 
00036     def test_dumbdbm_creation(self):
00037         f = dumbdbm.open(_fname, 'c')
00038         self.assertEqual(list(f.keys()), [])
00039         for key in self._dict:
00040             f[key] = self._dict[key]
00041         self.read_helper(f)
00042         f.close()

Here is the call graph for this function:

Definition at line 43 of file test_dbm_dumb.py.

00043 
00044     def test_dumbdbm_creation_mode(self):
00045         # On platforms without chmod, don't do anything.
00046         if not (hasattr(os, 'chmod') and hasattr(os, 'umask')):
00047             return
00048 
00049         try:
00050             old_umask = os.umask(0o002)
00051             f = dumbdbm.open(_fname, 'c', 0o637)
00052             f.close()
00053         finally:
00054             os.umask(old_umask)
00055 
00056         expected_mode = 0o635
00057         if os.name != 'posix':
00058             # Windows only supports setting the read-only attribute.
00059             # This shouldn't fail, but doesn't work like Unix either.
00060             expected_mode = 0o666
00061 
00062         import stat
00063         st = os.stat(_fname + '.dat')
00064         self.assertEqual(stat.S_IMODE(st.st_mode), expected_mode)
00065         st = os.stat(_fname + '.dir')
00066         self.assertEqual(stat.S_IMODE(st.st_mode), expected_mode)

Here is the call graph for this function:

Definition at line 87 of file test_dbm_dumb.py.

00087 
00088     def test_dumbdbm_keys(self):
00089         self.init_db()
00090         f = dumbdbm.open(_fname)
00091         keys = self.keys_helper(f)
00092         f.close()

Here is the call graph for this function:

Definition at line 74 of file test_dbm_dumb.py.

00074 
00075     def test_dumbdbm_modification(self):
00076         self.init_db()
00077         f = dumbdbm.open(_fname, 'w')
00078         self._dict[b'g'] = f[b'g'] = b"indented"
00079         self.read_helper(f)
00080         f.close()

Here is the call graph for this function:

Definition at line 81 of file test_dbm_dumb.py.

00081 
00082     def test_dumbdbm_read(self):
00083         self.init_db()
00084         f = dumbdbm.open(_fname, 'r')
00085         self.read_helper(f)
00086         f.close()

Here is the call graph for this function:

Definition at line 126 of file test_dbm_dumb.py.

00126 
00127     def test_line_endings(self):
00128         # test for bug #1172763: dumbdbm would die if the line endings
00129         # weren't what was expected.
00130         f = dumbdbm.open(_fname)
00131         f[b'1'] = b'hello'
00132         f[b'2'] = b'hello2'
00133         f.close()
00134 
00135         # Mangle the file by changing the line separator to Windows or Unix
00136         with io.open(_fname + '.dir', 'rb') as file:
00137             data = file.read()
00138         if os.linesep == '\n':
00139             data = data.replace(b'\n', b'\r\n')
00140         else:
00141             data = data.replace(b'\r\n', b'\n')
00142         with io.open(_fname + '.dir', 'wb') as file:
00143             file.write(data)
00144 
00145         f = dumbdbm.open(_fname)
00146         self.assertEqual(f[b'1'], b'hello')
00147         self.assertEqual(f[b'2'], b'hello2')
00148 

Here is the call graph for this function:

Definition at line 168 of file test_dbm_dumb.py.

00168 
00169     def test_random(self):
00170         import random
00171         d = {}  # mirror the database
00172         for dummy in range(5):
00173             f = dumbdbm.open(_fname)
00174             for dummy in range(100):
00175                 k = random.choice('abcdefghijklm')
00176                 if random.random() < 0.2:
00177                     if k in d:
00178                         del d[k]
00179                         del f[k]
00180                 else:
00181                     v = random.choice((b'a', b'b', b'c')) * random.randrange(10000)
00182                     d[k] = v
00183                     f[k] = v
00184                     self.assertEqual(f[k], v)
00185             f.close()
00186 
00187             f = dumbdbm.open(_fname)
00188             expected = sorted((k.encode("latin-1"), v) for k, v in d.items())
00189             got = sorted(f.items())
00190             self.assertEqual(expected, got)
00191             f.close()

Here is the call graph for this function:

Definition at line 109 of file test_dbm_dumb.py.

00109 
00110     def test_str_read(self):
00111         self.init_db()
00112         f = dumbdbm.open(_fname, 'r')
00113         self.assertEqual(f['\u00fc'], self._dict['\u00fc'.encode('utf-8')])

Here is the call graph for this function:

Definition at line 114 of file test_dbm_dumb.py.

00114 
00115     def test_str_write_contains(self):
00116         self.init_db()
00117         f = dumbdbm.open(_fname)
00118         f['\u00fc'] = b'!'
00119         f['1'] = 'a'
00120         f.close()
00121         f = dumbdbm.open(_fname, 'r')
00122         self.assertIn('\u00fc', f)
00123         self.assertEqual(f['\u00fc'.encode('utf-8')],
00124                          self._dict['\u00fc'.encode('utf-8')])
00125         self.assertEqual(f[b'1'], b'a')

Here is the call graph for this function:

Definition at line 93 of file test_dbm_dumb.py.

00093 
00094     def test_write_contains(self):
00095         f = dumbdbm.open(_fname)
00096         f[b'1'] = b'hello'
00097         self.assertIn(b'1', f)
00098         f.close()

Here is the call graph for this function:

Definition at line 99 of file test_dbm_dumb.py.

00099 
00100     def test_write_write_read(self):
00101         # test for bug #482460
00102         f = dumbdbm.open(_fname)
00103         f[b'1'] = b'hello'
00104         f[b'1'] = b'hello2'
00105         f.close()
00106         f = dumbdbm.open(_fname)
00107         self.assertEqual(f[b'1'], b'hello2')
00108         f.close()

Here is the call graph for this function:


Member Data Documentation

Initial value:
{b'0': b'',
             b'a': b'Python:',
             b'b': b'Programming',
             b'c': b'the',
             b'd': b'way',
             b'f': b'Guido',
             b'g': b'intended',
             '\u00fc'.encode('utf-8') : b'!',
             }

Definition at line 22 of file test_dbm_dumb.py.


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