diff --git a/pickledb.py b/pickledb.py index 6110e18..b527b49 100644 --- a/pickledb.py +++ b/pickledb.py @@ -74,7 +74,11 @@ def rem(self, key): del self.db[key] self._dumpdb(self.fsave) return True - + + def has(self, key): + '''Returns True if key exists; False otherwise''' + return self.db.has_key(key) + def lcreate(self, name): '''Create a list''' self.db[name] = [] diff --git a/tests.py b/tests.py index ddf6392..d17788c 100644 --- a/tests.py +++ b/tests.py @@ -42,6 +42,12 @@ def testRemoveString(self): c = self.db.get('var') self.assertTrue(a == b and b != c and c == None) + def testHas(self): + a = self.teststring + self.db.set('var', a) + self.assertTrue(self.db.has('var')) + self.db.rem('var') + self.assertFalse(self.db.has('var')) if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main()