summaryrefslogtreecommitdiff
path: root/tests/test_history.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2019-03-09 23:19:16 -0700
committerkotfu <kotfu@kotfu.net>2019-03-09 23:19:16 -0700
commitdfe5864fb2ca9334bb1b6e729ec31f5f5890f1cb (patch)
treee9a07f64e94f7e7638af61cab03e1ac3075acb77 /tests/test_history.py
parentd8ef258758be7ca690c591a762cbed7ee4c5a838 (diff)
downloadcmd2-git-dfe5864fb2ca9334bb1b6e729ec31f5f5890f1cb.tar.gz
Clean up history command
Diffstat (limited to 'tests/test_history.py')
-rw-r--r--tests/test_history.py58
1 files changed, 35 insertions, 23 deletions
diff --git a/tests/test_history.py b/tests/test_history.py
index e354a711..1554df5e 100644
--- a/tests/test_history.py
+++ b/tests/test_history.py
@@ -63,16 +63,28 @@ def hist():
return h
def test_history_class_span(hist):
- h = hist
- assert h == ['first', 'second', 'third', 'fourth']
- assert h.span('-2..') == ['third', 'fourth']
- assert h.span('2..3') == ['second', 'third'] # Inclusive of end
- assert h.span('3') == ['third']
- assert h.span(':') == h
- assert h.span('2..') == ['second', 'third', 'fourth']
- assert h.span('-1') == ['fourth']
- assert h.span('-2..-3') == ['third', 'second']
- assert h.span('*') == h
+ for tryit in ['*', ':', '-', 'all', 'ALL']:
+ assert hist.span(tryit) == hist
+
+ assert hist.span('3') == ['third']
+ assert hist.span('-1') == ['fourth']
+
+ assert hist.span('2..') == ['second', 'third', 'fourth']
+ assert hist.span('2:') == ['second', 'third', 'fourth']
+
+ assert hist.span('-2..') == ['third', 'fourth']
+ assert hist.span('-2:') == ['third', 'fourth']
+
+ assert hist.span('1..3') == ['first', 'second', 'third']
+ assert hist.span('1:3') == ['first', 'second', 'third']
+
+ assert hist.span(':-2') == ['first', 'second']
+ assert hist.span('..-2') == ['first', 'second']
+
+ value_errors = ['fred', 'fred:joe', 'a..b', '2 ..', '1 : 3', '-2..-3' ]
+ for tryit in value_errors:
+ with pytest.raises(ValueError):
+ hist.span(tryit)
def test_history_class_get(hist):
assert hist.get('1') == 'first'
@@ -101,10 +113,12 @@ def test_history_class_get(hist):
hist.get(None)
def test_history_str_search(hist):
- assert hist.get('ir') == ['first', 'third']
+ assert hist.str_search('ir') == ['first', 'third']
+ assert hist.str_search('rth') == ['fourth']
def test_history_regex_search(hist):
- assert hist.get('/i.*d/') == ['third']
+ assert hist.regex_search('/i.*d/') == ['third']
+ assert hist.regex_search('s[a-z]+ond') == ['second']
def test_base_history(base_app):
run_cmd(base_app, 'help')
@@ -222,11 +236,9 @@ def test_history_with_span_index_error(base_app):
run_cmd(base_app, 'help')
run_cmd(base_app, 'help history')
run_cmd(base_app, '!ls -hal :')
- out = run_cmd(base_app, 'history "hal :"')
- expected = normalize("""
- 3 !ls -hal :
-""")
- assert out == expected
+ with pytest.raises(ValueError):
+ _, err = run_cmd(base_app, 'history "hal :"')
+ assert "ValueError" in err
def test_history_output_file(base_app):
run_cmd(base_app, 'help')
@@ -380,8 +392,8 @@ def test_existing_history_file(hist_file, capsys):
pass
# Create a new cmd2 app
- app = cmd2.Cmd(persistent_history_file=hist_file)
- out, err = capsys.readouterr()
+ cmd2.Cmd(persistent_history_file=hist_file)
+ _, err = capsys.readouterr()
# Make sure there were no errors
assert err == ''
@@ -403,8 +415,8 @@ def test_new_history_file(hist_file, capsys):
pass
# Create a new cmd2 app
- app = cmd2.Cmd(persistent_history_file=hist_file)
- out, err = capsys.readouterr()
+ cmd2.Cmd(persistent_history_file=hist_file)
+ _, err = capsys.readouterr()
# Make sure there were no errors
assert err == ''
@@ -420,8 +432,8 @@ def test_bad_history_file_path(capsys, request):
test_dir = os.path.dirname(request.module.__file__)
# Create a new cmd2 app
- app = cmd2.Cmd(persistent_history_file=test_dir)
- out, err = capsys.readouterr()
+ cmd2.Cmd(persistent_history_file=test_dir)
+ _, err = capsys.readouterr()
if sys.platform == 'win32':
# pyreadline masks the read exception. Therefore the bad path error occurs when trying to write the file.