diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-05-25 17:49:20 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-05-25 17:49:20 -0400 |
commit | 1fe024f33574af02c93d4df0eb0ddb88e690305a (patch) | |
tree | f7a86354c3f94ea1c3549974c48b7e0ab9d01aa9 | |
parent | 2c96da06b2009760bebc20bec1980bf34df93d86 (diff) | |
download | cmd2-git-1fe024f33574af02c93d4df0eb0ddb88e690305a.tar.gz |
Refactored implementation of HistoryItem.__str__ and added an explicit HistoryItem unit test
-rw-r--r-- | cmd2/history.py | 5 | ||||
-rw-r--r-- | tests/test_history.py | 21 |
2 files changed, 16 insertions, 10 deletions
diff --git a/cmd2/history.py b/cmd2/history.py index 6bec5316..ae2e85ad 100644 --- a/cmd2/history.py +++ b/cmd2/history.py @@ -24,10 +24,7 @@ class HistoryItem(): def __str__(self): """A convenient human readable representation of the history item""" - if self.statement: - return self.statement.raw - else: - return '' + return self.statement.raw @property def raw(self) -> str: diff --git a/tests/test_history.py b/tests/test_history.py index 3a52bda9..11133456 100644 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -5,8 +5,6 @@ Test history functions of cmd2 """ import tempfile import os -import pickle -import sys import pytest @@ -18,6 +16,8 @@ except ImportError: import cmd2 from .conftest import run_cmd, normalize, HELP_HISTORY +from cmd2.parsing import Statement +from cmd2.history import HistoryItem def test_base_help_history(base_app): @@ -50,17 +50,26 @@ def test_exclude_from_history(base_app, monkeypatch): expected = normalize(""" 1 help""") assert out == expected - @pytest.fixture def hist(): - from cmd2.parsing import Statement - from cmd2.cmd2 import History, HistoryItem + from cmd2.history import History h = History([HistoryItem(Statement('', raw='first'), 1), HistoryItem(Statement('', raw='second'), 2), HistoryItem(Statement('', raw='third'), 3), - HistoryItem(Statement('', raw='fourth'),4)]) + HistoryItem(Statement('', raw='fourth'), 4)]) return h +def test_history_item(): + raw = 'help' + stmt = Statement('', raw=raw) + index = 1 + hi = HistoryItem(stmt, index) + assert hi.statement == stmt + assert hi.idx == index + assert hi.statement.raw == raw + assert str(hi) == raw + + def test_history_class_span(hist): for tryit in ['*', ':', '-', 'all', 'ALL']: assert hist.span(tryit) == hist |