diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-03-16 17:47:01 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-03-16 17:47:01 -0400 |
commit | fd9657d651ccdd7d42730489fe32448a90992ef6 (patch) | |
tree | 90e0373930d5e41718289b007a03eb6097bebfe3 /tests/test_cmd2.py | |
parent | c4c1f441c11df9b0045918b3003b07b71e9ee3fd (diff) | |
download | cmd2-git-fd9657d651ccdd7d42730489fe32448a90992ef6.tar.gz |
Added unit tests for alias, unalias, and basic_complete
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r-- | tests/test_cmd2.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 50b34949..d69bf343 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -1542,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 |