Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Side by Side Diff: Lib/test/test_dbm_dumb.py

Issue 19385: dbm.dumb should be consistent when the database is closed
Patch Set: Created 6 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/dbm/dumb.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #! /usr/bin/env python3 1 #! /usr/bin/env python3
2 """Test script for the dumbdbm module 2 """Test script for the dumbdbm module
3 Original by Roger E. Masse 3 Original by Roger E. Masse
4 """ 4 """
5 5
6 import io 6 import io
7 import os 7 import os
8 import unittest 8 import unittest
9 import dbm.dumb as dumbdbm 9 import dbm.dumb as dumbdbm
10 from test import support 10 from test import support
11 import operator
12 from functools import partial
11 13
12 _fname = support.TESTFN 14 _fname = support.TESTFN
13 15
14 def _delete_files(): 16 def _delete_files():
15 for ext in [".dir", ".dat", ".bak"]: 17 for ext in [".dir", ".dat", ".bak"]:
16 try: 18 try:
17 os.unlink(_fname + ext) 19 os.unlink(_fname + ext)
18 except OSError: 20 except OSError:
19 pass 21 pass
20 22
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 d[k] = v 180 d[k] = v
179 f[k] = v 181 f[k] = v
180 self.assertEqual(f[k], v) 182 self.assertEqual(f[k], v)
181 f.close() 183 f.close()
182 184
183 f = dumbdbm.open(_fname) 185 f = dumbdbm.open(_fname)
184 expected = sorted((k.encode("latin-1"), v) for k, v in d.items()) 186 expected = sorted((k.encode("latin-1"), v) for k, v in d.items())
185 got = sorted(f.items()) 187 got = sorted(f.items())
186 self.assertEqual(expected, got) 188 self.assertEqual(expected, got)
187 f.close() 189 f.close()
190
191 def test_check_closed(self):
192 f = dumbdbm.open(_fname, 'c')
193 f.close()
194
195 for meth in (partial(operator.delitem, f),
196 partial(operator.setitem, f, 'b'),
197 partial(operator.getitem, f),
198 partial(operator.contains, f)):
199 with self.assertRaises(dumbdbm.error) as cm:
200 meth('test')
201 self.assertEqual(str(cm.exception),
202 "DBM object has already been closed")
vajrasky 2013/11/01 16:22:32 It needs one more space. " in "DBM should be under
203
204 for meth in (operator.methodcaller('keys'),
205 operator.methodcaller('iterkeys'),
206 operator.methodcaller('items'),
207 len):
208 with self.assertRaises(dumbdbm.error) as cm:
209 meth(f)
210 self.assertEqual(str(cm.exception),
211 "DBM object has already been closed")
vajrasky 2013/11/01 16:22:32 It needs one more space. " in "DBM should be under
188 212
189 def tearDown(self): 213 def tearDown(self):
190 _delete_files() 214 _delete_files()
191 215
192 def setUp(self): 216 def setUp(self):
193 _delete_files() 217 _delete_files()
194 218
195 219
196 if __name__ == "__main__": 220 if __name__ == "__main__":
197 unittest.main() 221 unittest.main()
OLDNEW
« no previous file with comments | « Lib/dbm/dumb.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+