summaryrefslogtreecommitdiff
path: root/tests/test_cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-03-16 18:58:19 -0400
committerGitHub <noreply@github.com>2018-03-16 18:58:19 -0400
commit70b340da1ea080e42ec91d0d37a8c266d095df94 (patch)
treeba5666ae95ea8bb2376a61cf42f13fa71cf83b27 /tests/test_cmd2.py
parent3abfbf6c994f5a7e4aa918fc9fff10da99cf6f25 (diff)
parent9465ff2abd51bafa4c8928b19ed58140721fe567 (diff)
downloadcmd2-git-70b340da1ea080e42ec91d0d37a8c266d095df94.tar.gz
Merge pull request #314 from python-cmd2/alias
Alias
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r--tests/test_cmd2.py46
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index fd37e25e..d69bf343 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1044,7 +1044,8 @@ def test_custom_help_menu(help_app):
expected = normalize("""
Documented commands (type help <topic>):
========================================
-edit help history load py pyscript quit set shell shortcuts squat
+alias help load pyscript set shortcuts unalias
+edit history py quit shell squat
Undocumented commands:
======================
@@ -1541,3 +1542,46 @@ def test_poutput_none(base_app):
out = base_app.stdout.buffer
expected = ''
assert out == expected
+
+
+def test_alias(base_app, capsys):
+ # Create the alias
+ out = run_cmd(base_app, 'alias fake pyscript')
+ assert out == normalize("Alias created")
+
+ # Use the alias
+ run_cmd(base_app, 'fake')
+ out, err = capsys.readouterr()
+ assert "pyscript command requires at least 1 argument" in err
+
+ # See a list of aliases
+ out = run_cmd(base_app, 'alias')
+ assert out == normalize('alias fake pyscript')
+
+def test_alias_with_cmd_name(base_app, capsys):
+ run_cmd(base_app, 'alias help eos')
+ out, err = capsys.readouterr()
+ assert "cannot match an existing command" in err
+
+def test_alias_with_invalid_name(base_app, capsys):
+ run_cmd(base_app, 'alias @ help')
+ out, err = capsys.readouterr()
+ assert "can only contain the following characters" in err
+
+
+def test_unalias(base_app):
+ # Create an alias
+ run_cmd(base_app, 'alias fake pyscript')
+
+ # Remove the alias
+ out = run_cmd(base_app, 'unalias fake')
+ assert out == normalize("Alias 'fake' cleared")
+
+def test_unalias_all(base_app):
+ out = run_cmd(base_app, 'unalias -a')
+ assert out == normalize("All aliases cleared")
+
+def test_unalias_non_existing(base_app, capsys):
+ run_cmd(base_app, 'unalias fake')
+ out, err = capsys.readouterr()
+ assert "does not exist" in err