diff options
author | Dong-hee Na <donghee.na@python.org> | 2023-07-23 22:51:12 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-23 13:51:12 +0000 |
commit | b273837fea129df8477da557ad3cb23a0ed12c20 (patch) | |
tree | b633c744e9f4711edefef7ab56a12aa6ce57483f /Lib/test/test_dbm_gnu.py | |
parent | e59da0c4f283b966ccb175fb94460f58211a9704 (diff) | |
download | cpython-b273837fea129df8477da557ad3cb23a0ed12c20.tar.gz cpython-b273837fea129df8477da557ad3cb23a0ed12c20.zip |
gh-107122: Add clear method to dbm.gdbm.module (gh-107127)
Diffstat (limited to 'Lib/test/test_dbm_gnu.py')
-rw-r--r-- | Lib/test/test_dbm_gnu.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_dbm_gnu.py b/Lib/test/test_dbm_gnu.py index 73602cab518..e20addf1f04 100644 --- a/Lib/test/test_dbm_gnu.py +++ b/Lib/test/test_dbm_gnu.py @@ -192,6 +192,20 @@ class TestGdbm(unittest.TestCase): def test_open_with_pathlib_bytes_path(self): gdbm.open(FakePath(os.fsencode(filename)), "c").close() + def test_clear(self): + kvs = [('foo', 'bar'), ('1234', '5678')] + with gdbm.open(filename, 'c') as db: + for k, v in kvs: + db[k] = v + self.assertIn(k, db) + self.assertEqual(len(db), len(kvs)) + + db.clear() + for k, v in kvs: + self.assertNotIn(k, db) + self.assertEqual(len(db), 0) + + if __name__ == '__main__': unittest.main() |