GH-46412: More efficient bool() for ndbm/_gdbmmodule (#96692)

This commit is contained in:
Guido van Rossum 2022-09-08 19:32:40 -07:00 committed by GitHub
parent 95d6330a3e
commit df50938f58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 91 additions and 0 deletions

View file

@ -118,6 +118,20 @@ class TestGdbm(unittest.TestCase):
self.assertEqual(str(cm.exception),
"GDBM object has already been closed")
def test_bool_empty(self):
with gdbm.open(filename, 'c') as db:
self.assertFalse(bool(db))
def test_bool_not_empty(self):
with gdbm.open(filename, 'c') as db:
db['a'] = 'b'
self.assertTrue(bool(db))
def test_bool_on_closed_db_raises(self):
with gdbm.open(filename, 'c') as db:
db['a'] = 'b'
self.assertRaises(gdbm.error, bool, db)
def test_bytes(self):
with gdbm.open(filename, 'c') as db:
db[b'bytes key \xbd'] = b'bytes value \xbd'