summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-03 20:34:44 -0400
committerGitHub <noreply@github.com>2017-07-03 20:34:44 -0400
commite3230e333b6b0cd2b2595cb8ed55da9b5eb70f73 (patch)
treef66f1f2bd5033f9729b9007ec7809deae5d11f78
parent6588289bd9811010f270e4189bee735d0e0a2912 (diff)
parenta609393e50d87ecbc661bddae1127a3145951b78 (diff)
downloadcmd2-git-e3230e333b6b0cd2b2595cb8ed55da9b5eb70f73.tar.gz
Merge pull request #170 from python-cmd2/history_exclusion
Add unit test to verify exclusion of commands from the history
-rw-r--r--tests/test_cmd2.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 68a59c01..e66c7b01 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1187,3 +1187,47 @@ def test_cmdresult(cmdresult_app):
run_cmd(cmdresult_app, 'negative {}'.format(arg))
assert not cmdresult_app._last_result
assert cmdresult_app._last_result == cmd2.CmdResult('', arg)
+
+
+@pytest.fixture
+def abbrev_app():
+ app = cmd2.Cmd()
+ app.abbrev = True
+ app.stdout = StdOut()
+ return app
+
+def test_exclude_from_history(abbrev_app):
+ # Run all variants of run
+ run_cmd(abbrev_app, 'run')
+ run_cmd(abbrev_app, 'ru')
+ run_cmd(abbrev_app, 'r')
+
+ # Mock out the os.system call so we don't actually open an editor
+ m = mock.MagicMock(name='system')
+ os.system = m
+
+ # Run all variants of edit
+ run_cmd(abbrev_app, 'edit')
+ run_cmd(abbrev_app, 'edi')
+ run_cmd(abbrev_app, 'ed')
+
+ # Run all variants of history
+ run_cmd(abbrev_app, 'history')
+ run_cmd(abbrev_app, 'histor')
+ run_cmd(abbrev_app, 'histo')
+ run_cmd(abbrev_app, 'hist')
+ run_cmd(abbrev_app, 'his')
+ run_cmd(abbrev_app, 'hi')
+
+ # Verify that the history is empty
+ out = run_cmd(abbrev_app, 'history')
+ assert out == []
+
+ # Now run a command which isn't excluded from the history
+ run_cmd(abbrev_app, 'help')
+ # And verify we have a history now ...
+ out = run_cmd(abbrev_app, 'history')
+ expected = normalize("""-------------------------[1]
+help""")
+ assert out == expected
+