Skip to content

Commit

Permalink
fix: make behaviour of _history_item_to_string consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
KristianJensen committed Feb 19, 2016
1 parent 26b81fe commit 6d7b1e6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cameo/util.py
Expand Up @@ -287,14 +287,14 @@ def _history_item_to_str(item):
info += datetime.fromtimestamp(entry['unix_epoch']).strftime('%Y-%m-%d %H:%M:%S') + '\n'
undo_entry = entry['undo']
try:
elements = undo_entry.func, undo_entry.args, undo_entry.keywords # partial
elements = undo_entry.func, undo_entry.args, undo_entry.keywords or {} # partial (if .keywords is None print {} instead)
info += 'undo: ' + ' '.join([str(elem) for elem in elements]) + '\n'
except AttributeError: # normal python function
info += 'undo: ' + undo_entry.__name__ + '\n'

redo_entry = entry['redo']
try:
elements = redo_entry.func, redo_entry.args, redo_entry.keywords # partial
elements = redo_entry.func, redo_entry.args, redo_entry.keywords or {} # partial
info += 'redo: ' + ' '.join([str(elem) for elem in elements]) + '\n'
except AttributeError:
info += 'redo: ' + redo_entry.__name__ + '\n'
Expand Down
11 changes: 2 additions & 9 deletions tests/test_util.py
Expand Up @@ -44,15 +44,8 @@ def normal_function():

partial_function = partial(str, 1)
self.tm(do=normal_function, undo=partial_function)
if six.PY2:
self.assertEqual(self.tm.__str__().split('\n')[2:-1],
["undo: <type 'str'> (1,) None", 'redo: normal_function'])
elif sys.version_info.major == 3 and sys.version_info.minor == 4 and sys.version_info.micro == 3: # special exception for travis-ci
self.assertEqual(self.tm.__str__().split('\n')[2:-1],
["undo: <type 'str'> (1,) None", 'redo: normal_function'])
elif six.PY3:
self.assertEqual(self.tm.__str__().split('\n')[2:-1],
["undo: <class 'str'> (1,) {}", 'redo: normal_function'])
self.assertEqual(self.tm.__str__().split('\n')[2:-1],
["undo: <class 'str'> (1,) {}", 'redo: normal_function'])

def test_with_statement(self):
l = [1, 2, 3, 4]
Expand Down

0 comments on commit 6d7b1e6

Please sign in to comment.