diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-03-16 20:09:04 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-03-16 20:09:04 -0400 |
commit | d590116b0a9efdb874713a0755cc362bd898112a (patch) | |
tree | bca90446f696fca6734ed991b96018c0c129c586 /tests | |
parent | 7dfd95cdeae12d8b8d788769df98945fd3f2f422 (diff) | |
download | cmd2-git-d590116b0a9efdb874713a0755cc362bd898112a.tar.gz |
Fix unit tests and example
functools.partialmethod() was added in Python 3.4, so it can't be used in Python 2.7.
- Modified the code to skip trying to use it for Python 2.7
- Skip the two unit tests which test its usage on Python 2.7
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_argparse.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/tests/test_argparse.py b/tests/test_argparse.py index 2c2c2a5a..fb8836f3 100644 --- a/tests/test_argparse.py +++ b/tests/test_argparse.py @@ -6,9 +6,12 @@ import argparse import functools import pytest import readline +import sys import cmd2 import mock +import six + from conftest import run_cmd, StdOut @@ -224,8 +227,10 @@ class SubcommandApp(cmd2.Cmd): # No subcommand was provided, so as called self.do_help('base') - # This makes sure correct tab completion functions are called based on the selected subcommand - complete_base = functools.partialmethod(cmd2.Cmd.cmd_with_subs_completer, base='base') + # functools.partialmethod was added in Python 3.4 + if six.PY3: + # This makes sure correct tab completion functions are called based on the selected subcommand + complete_base = functools.partialmethod(cmd2.Cmd.cmd_with_subs_completer, base='base') @pytest.fixture def subcommand_app(): @@ -268,7 +273,8 @@ def test_subcommand_invalid_help(subcommand_app): assert out[0].startswith('usage: base') assert out[1].startswith("base: error: invalid choice: 'baz'") -def test_sumcommand_tab_completion(subcommand_app): +@pytest.mark.skipif(sys.version_info < (3,0), reason="functools.partialmethod requires Python 3.4+") +def test_subcommand_tab_completion(subcommand_app): # This makes sure the correct completer for the sport subcommand is called text = 'Foot' line = 'base sport Foot' @@ -294,7 +300,8 @@ def test_sumcommand_tab_completion(subcommand_app): # It is at end of line, so extra space is present assert first_match is not None and subcommand_app.completion_matches == ['Football '] -def test_sumcommand_tab_completion_with_no_completer(subcommand_app): +@pytest.mark.skipif(sys.version_info < (3,0), reason="functools.partialmethod requires Python 3.4+") +def test_subcommand_tab_completion_with_no_completer(subcommand_app): # This tests what happens when a subcommand has no completer # In this case, the foo subcommand has no completer defined text = 'Foot' |