Skip to content

Commit

Permalink
Merge pull request #14 from ericdill/repr
Browse files Browse the repository at this point in the history
Implement repr for History object
  • Loading branch information
danielballan committed Aug 3, 2015
2 parents 9dc8b5c + 52adb87 commit fb3be17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions history.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def __init__(self, fname):
for k in self._keys:
self._cache[k] = self.past(k)

def __repr__(self):
return repr(dict(self))

def __getitem__(self, key):
if key == self.RESERVED_KEY_KEY:
raise ValueError("can not get internal keys through []")
Expand Down
11 changes: 11 additions & 0 deletions test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def test_del():
assert_equal(h['a'], 789)
assert_equal(h.past('a', 0), 789)


def test_no_key_in_del():
h.clear()
with assert_raises(KeyError):
Expand All @@ -114,3 +115,13 @@ def test_protected_key():
History.RESERVED_KEY_KEY)
assert_raises(ValueError, h.__setitem__,
History.RESERVED_KEY_KEY, 'aardvark')


def test_repr():
h.clear()
kvpairs = (('foo', 'bar'), ('spam', 'spam spam spam'))
dct = {}
for k, v in kvpairs:
dct[k] = v
h[k] = v
assert_equal(repr(h), repr(dct))

0 comments on commit fb3be17

Please sign in to comment.