summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd2/history.py5
-rw-r--r--tests/test_history.py21
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