Skip to content

Commit

Permalink
'update' method
Browse files Browse the repository at this point in the history
  • Loading branch information
mgax committed Oct 2, 2012
1 parent df3618a commit 16047df
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests.py
Expand Up @@ -7,8 +7,7 @@ class KV(object):
def __init__(self, **kwargs):
self._db = sqlite3.connect(':memory:')
self._execute('CREATE TABLE data (key TEXT PRIMARY KEY, value TEXT)')
for k in kwargs:
self[k] = kwargs[k]
self.update(kwargs)

def _execute(self, *args):
return self._db.cursor().execute(*args)
Expand Down Expand Up @@ -48,6 +47,10 @@ def __delitem__(self, key):
else:
raise KeyError

def update(self, items):
for k in items:
self[k] = items[k]


class KVTest(unittest.TestCase):

Expand Down Expand Up @@ -99,6 +102,11 @@ def test_constructor_kwargs_retrieved_via_getitem(self):
kv = KV(a='b')
self.assertEqual(kv['a'], 'b')

def test_udpate_with_dictionary_items_retrieved_via_getitem(self):
kv = KV()
kv.update({'a': 'b'})
self.assertEqual(kv['a'], 'b')

def test_delete_missing_item_raises_key_error(self):
kv = KV()
with self.assertRaises(KeyError):
Expand Down

0 comments on commit 16047df

Please sign in to comment.