bpo-33106: change dbm key deletion error for readonly file from KeyError to dbm.error (#6295)

This commit is contained in:
Xiang Zhang 2018-12-12 20:46:55 +08:00 committed by GitHub
parent 5a718e918d
commit 4fb0b8bc25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 57 additions and 9 deletions

View file

@ -131,6 +131,17 @@ class TestGdbm(unittest.TestCase):
self.assertEqual(db['Unicode key \U0001f40d'],
'Unicode value \U0001f40d'.encode())
def test_write_readonly_file(self):
with gdbm.open(filename, 'c') as db:
db[b'bytes key'] = b'bytes value'
with gdbm.open(filename, 'r') as db:
with self.assertRaises(gdbm.error):
del db[b'not exist key']
with self.assertRaises(gdbm.error):
del db[b'bytes key']
with self.assertRaises(gdbm.error):
db[b'not exist key'] = b'not exist value'
@unittest.skipUnless(TESTFN_NONASCII,
'requires OS support of non-ASCII encodings')
def test_nonascii_filename(self):