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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 6 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/test/test_crypt.py ('k') | Lib/test/test_dbm.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 from test import support 1 from test import support
2 gdbm = support.import_module("dbm.gnu") #skip if not supported 2 gdbm = support.import_module("dbm.gnu") #skip if not supported
3 import unittest 3 import unittest
4 import os 4 import os
5 from test.support import verbose, TESTFN, unlink 5 from test.support import verbose, TESTFN, unlink
6 6
7 7
8 filename = TESTFN 8 filename = TESTFN
9 9
10 class TestGdbm(unittest.TestCase): 10 class TestGdbm(unittest.TestCase):
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 for flag in flags: 64 for flag in flags:
65 self.g = gdbm.open(filename, mode + flag) 65 self.g = gdbm.open(filename, mode + flag)
66 self.g.close() 66 self.g.close()
67 67
68 def test_reorganize(self): 68 def test_reorganize(self):
69 self.g = gdbm.open(filename, 'c') 69 self.g = gdbm.open(filename, 'c')
70 size0 = os.path.getsize(filename) 70 size0 = os.path.getsize(filename)
71 71
72 self.g['x'] = 'x' * 10000 72 self.g['x'] = 'x' * 10000
73 size1 = os.path.getsize(filename) 73 size1 = os.path.getsize(filename)
74 self.assertTrue(size0 < size1) 74 self.assertLess(size0, size1)
75 75
76 del self.g['x'] 76 del self.g['x']
77 # 'size' is supposed to be the same even after deleting an entry. 77 # 'size' is supposed to be the same even after deleting an entry.
78 self.assertEqual(os.path.getsize(filename), size1) 78 self.assertEqual(os.path.getsize(filename), size1)
79 79
80 self.g.reorganize() 80 self.g.reorganize()
81 size2 = os.path.getsize(filename) 81 size2 = os.path.getsize(filename)
82 self.assertTrue(size1 > size2 >= size0) 82 self.assertTrue(size1 > size2 >= size0)
83 83
84 def test_context_manager(self): 84 def test_context_manager(self):
85 with gdbm.open(filename, 'c') as db: 85 with gdbm.open(filename, 'c') as db:
86 db["gdbm context manager"] = "context manager" 86 db["gdbm context manager"] = "context manager"
87 87
88 with gdbm.open(filename, 'r') as db: 88 with gdbm.open(filename, 'r') as db:
89 self.assertEqual(list(db.keys()), [b"gdbm context manager"]) 89 self.assertEqual(list(db.keys()), [b"gdbm context manager"])
90 90
91 with self.assertRaises(gdbm.error) as cm: 91 with self.assertRaises(gdbm.error) as cm:
92 db.keys() 92 db.keys()
93 self.assertEqual(str(cm.exception), 93 self.assertEqual(str(cm.exception),
94 "GDBM object has already been closed") 94 "GDBM object has already been closed")
95 95
96 if __name__ == '__main__': 96 if __name__ == '__main__':
97 unittest.main() 97 unittest.main()
OLDNEW
« no previous file with comments | « Lib/test/test_crypt.py ('k') | Lib/test/test_dbm.py » ('j') | no next file with comments »

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