diff options
| author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-02-16 00:05:06 -0500 |
|---|---|---|
| committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-02-16 00:05:06 -0500 |
| commit | d55a618999194ca2076d75a5568184bf9efd3789 (patch) | |
| tree | 50825ff1c06f29c4463258bda89ab35a29d40429 /tests/test_cmd2.py | |
| parent | 9b8bc42a7a6f04d8e83830ba4f87ffe3aa010eb4 (diff) | |
| download | cmd2-git-d55a618999194ca2076d75a5568184bf9efd3789.tar.gz | |
Added member boolean flag to disable output redirection and piping.
This addresses Issue #15.
Also added a unit test for this new feature and display of it's status in the cmdenvironment command.
Diffstat (limited to 'tests/test_cmd2.py')
| -rw-r--r-- | tests/test_cmd2.py | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 39669397..18995db5 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -198,17 +198,19 @@ def test_base_cmdenvironment(base_app): out = run_cmd(base_app, 'cmdenvironment') expected = normalize(""" - Commands are not case-sensitive. + Commands are case-sensitive: False Commands may be terminated with: [';'] + Command-line arguments allowed: True + Output redirection and pipes allowed: True """) - assert out[:2] == expected[:2] - assert out[2].strip().startswith('Settable parameters: ') + assert out[:4] == expected[:4] + assert out[4].strip().startswith('Settable parameters: ') # Settable parameters can be listed in any order, so need to validate carefully using unordered sets settable_params = {'continuation_prompt', 'default_file_name', 'prompt', 'abbrev', 'quiet', 'case_insensitive', 'colors', 'echo', 'timing', 'editor', 'feedback_to_output', 'debug', 'autorun_on_edit', 'locals_in_py'} - out_params = set(out[2].split("Settable parameters: ")[1].split()) + out_params = set(out[4].split("Settable parameters: ")[1].split()) assert settable_params == out_params @@ -330,6 +332,21 @@ def test_output_redirection(base_app): os.remove(filename) +def test_allow_redirection(base_app): + # Set allow_redirection to False + base_app.allow_redirection = False + + filename = 'test_allow_redirect.txt' + + # Verify output wasn't redirected + out = run_cmd(base_app, 'help > {}'.format(filename)) + expected = normalize(BASE_HELP) + assert out == expected + + # Verify that no file got created + assert not os.path.exists(filename) + + @pytest.mark.skipif(sys.platform.startswith('linux') and getpass.getuser() == 'travis', reason="Unit test passes on Ubuntu 16.04 and Debian 8.7, but fails on TravisCI Linux containers") def test_input_redirection(base_app, request): |
