diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cmd2.py | 38 | ||||
-rw-r--r-- | tests/test_parsing.py | 5 | ||||
-rw-r--r-- | tests/test_transcript.py | 11 |
3 files changed, 13 insertions, 41 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 04498c49..9f0b13ee 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -145,10 +145,7 @@ now: True def test_base_shell(base_app, monkeypatch): m = mock.Mock() - subprocess = 'subprocess' - if six.PY2: - subprocess = 'subprocess32' - monkeypatch.setattr("{}.Popen".format(subprocess), m) + monkeypatch.setattr("{}.Popen".format('subprocess'), m) out = run_cmd(base_app, 'shell echo a') assert out == [] assert m.called @@ -642,15 +639,8 @@ def test_pipe_to_shell_error(base_app, capsys): # Try to pipe command output to a shell command that doesn't exist in order to produce an error run_cmd(base_app, 'help | foobarbaz.this_does_not_exist') out, err = capsys.readouterr() - assert not out - expected_error = 'FileNotFoundError' - if six.PY2: - if sys.platform.startswith('win'): - expected_error = 'WindowsError' - else: - expected_error = 'OSError' assert err.startswith("EXCEPTION of type '{}' occurred with message:".format(expected_error)) @@ -719,8 +709,8 @@ def test_base_colorize(base_app): def _expected_no_editor_error(): expected_exception = 'OSError' - # If using Python 2 or PyPy (either 2 or 3), expect a different exception than with Python 3 - if six.PY2 or hasattr(sys, "pypy_translation_info"): + # If PyPy, expect a different exception than with Python 3 + if hasattr(sys, "pypy_translation_info"): expected_exception = 'EnvironmentError' expected_text = normalize(""" @@ -885,8 +875,7 @@ def test_cmdloop_without_rawinput(): class HookFailureApp(cmd2.Cmd): def __init__(self, *args, **kwargs): - # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x - cmd2.Cmd.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) def postparsing_precmd(self, statement): """Simulate precmd hook failure.""" @@ -910,8 +899,7 @@ def test_precmd_hook_failure(hook_failure): class SayApp(cmd2.Cmd): def __init__(self, *args, **kwargs): - # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x - cmd2.Cmd.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) def do_say(self, arg): self.poutput(arg) @@ -953,8 +941,7 @@ def test_interrupt_noquit(say_app): class ShellApp(cmd2.Cmd): def __init__(self, *args, **kwargs): - # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x - cmd2.Cmd.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) self.default_to_shell = True @pytest.fixture @@ -1020,8 +1007,7 @@ def test_ansi_prompt_escaped(): class HelpApp(cmd2.Cmd): """Class for testing custom help_* methods which override docstring help.""" def __init__(self, *args, **kwargs): - # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x - cmd2.Cmd.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) def do_squat(self, arg): """This docstring help will never be shown because the help_squat method overrides it.""" @@ -1077,8 +1063,7 @@ def test_help_overridden_method(help_app): class HelpCategoriesApp(cmd2.Cmd): """Class for testing custom help_* methods which override docstring help.""" def __init__(self, *args, **kwargs): - # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x - cmd2.Cmd.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) @cmd2.with_category('Some Category') def do_diddly(self, arg): @@ -1342,9 +1327,7 @@ def test_which_editor_bad(): class MultilineApp(cmd2.Cmd): def __init__(self, *args, **kwargs): self.multilineCommands = ['orate'] - - # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x - cmd2.Cmd.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) orate_parser = argparse.ArgumentParser() orate_parser.add_argument('-s', '--shout', action="store_true", help="N00B EMULATION MODE") @@ -1395,8 +1378,7 @@ def test_clipboard_failure(capsys): class CmdResultApp(cmd2.Cmd): def __init__(self, *args, **kwargs): - # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x - cmd2.Cmd.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) def do_affirmative(self, arg): self._last_result = cmd2.CmdResult(arg) diff --git a/tests/test_parsing.py b/tests/test_parsing.py index ba5126f6..e2367a37 100644 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -299,22 +299,18 @@ def test_parse_multiline_ignores_terminators_in_comments(parser): assert results.terminator[0] == '\n' assert results.terminator[1] == '\n' -# Unicode support is only present in cmd2 for Python 3 -@pytest.mark.skipif(sys.version_info < (3,0), reason="cmd2 unicode support requires python3") def test_parse_command_with_unicode_args(parser): line = 'drink café' results = parser.parseString(line) assert results.command == 'drink' assert results.args == 'café' -@pytest.mark.skipif(sys.version_info < (3, 0), reason="cmd2 unicode support requires python3") def test_parse_unicode_command(parser): line = 'café au lait' results = parser.parseString(line) assert results.command == 'café' assert results.args == 'au lait' -@pytest.mark.skipif(sys.version_info < (3,0), reason="cmd2 unicode support requires python3") def test_parse_redirect_to_unicode_filename(parser): line = 'dir home > café' results = parser.parseString(line) @@ -323,7 +319,6 @@ def test_parse_redirect_to_unicode_filename(parser): assert results.output == '>' assert results.outputTo == 'café' -@pytest.mark.skipif(sys.version_info < (3,0), reason="cmd2 unicode support requires python3") def test_parse_input_redirect_from_unicode_filename(input_parser): line = '< café' results = input_parser.parseString(line) diff --git a/tests/test_transcript.py b/tests/test_transcript.py index a579b04a..311a3f42 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -33,8 +33,7 @@ class CmdLineApp(Cmd): # Add stuff to settable and/or shortcuts before calling base class initializer self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed' - # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x - Cmd.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) self.intro = 'This is an intro banner ...' # Configure how arguments are parsed for commands using decorators @@ -267,12 +266,8 @@ def test_transcript(request, capsys, filename, feedback_to_output): expected_start = ".\n----------------------------------------------------------------------\nRan 1 test in" expected_end = "s\n\nOK\n" out, err = capsys.readouterr() - if six.PY3: - assert err.startswith(expected_start) - assert err.endswith(expected_end) - else: - assert err == '' - assert out == '' + assert err.startswith(expected_start) + assert err.endswith(expected_end) @pytest.mark.parametrize('expected, transformed', [ |