diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-04-15 16:14:09 -0700 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-04-15 16:14:09 -0700 |
commit | 480c7f8bbcdf1179312f71f525e79102aa4551ae (patch) | |
tree | 1206a00a4e8d8a521dc00970c25da9973c5ac4f7 | |
parent | 6b23d7e610b8f8634ad4535d5fbfdb5bfd944b5a (diff) | |
download | cmd2-git-480c7f8bbcdf1179312f71f525e79102aa4551ae.tar.gz |
Finished removing all dependencies on the six module
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | CONTRIBUTING.md | 4 | ||||
-rwxr-xr-x | cmd2.py | 7 | ||||
-rw-r--r-- | docs/install.rst | 1 | ||||
-rw-r--r-- | docs/requirements.txt | 1 | ||||
-rw-r--r-- | tests/test_cmd2.py | 43 | ||||
-rw-r--r-- | tests/test_transcript.py | 1 | ||||
-rw-r--r-- | tox.ini | 6 |
8 files changed, 24 insertions, 41 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fc32546..38b54efb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ ## 0.9.0 (TBD, 2018) +* Enhancements + * ``cmd2`` no longer depends on the ``six`` module * Deletions (potentially breaking changes) * Deleted all ``optparse`` code which had previously been deprecated in release 0.8.0 * The ``options`` decorator no longer exists diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c280b37c..f7eba2fa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -45,7 +45,6 @@ The tables below list all prerequisites along with the minimum required version | Prerequisite | Minimum Version | | --------------------------------------------------- | --------------- | | [Python](https://www.python.org/downloads/) | `3.4` | -| [six](https://pypi.python.org/pypi/six) | `1.8` | | [pyparsing](http://pyparsing.wikispaces.com) | `2.1` | | [pyperclip](https://github.com/asweigart/pyperclip) | `1.6` | @@ -72,7 +71,6 @@ If Python is already installed in your machine, run the following commands to va ```shell python -V -pip freeze | grep six pip freeze | grep pyparsing ``` @@ -192,7 +190,7 @@ Once you have cmd2 cloned, before you start any cmd2 application, you first need ```bash # Install cmd2 prerequisites -pip install -U six pyparsing pyperclip +pip install -U pyparsing pyperclip # Install prerequisites for running cmd2 unit tests pip install -U pytest @@ -53,7 +53,6 @@ except ImportError: import pyparsing import pyperclip from pyperclip import PyperclipException -import six.moves as sm # Used for sm.input # Collection is a container that is sizable and iterable # It was introduced in Python 3.6. We will try to import it, otherwise use our implementation @@ -2402,9 +2401,9 @@ class Cmd(cmd.Cmd): if self.use_rawinput: try: if sys.stdin.isatty(): - line = sm.input(safe_prompt) + line = input(safe_prompt) else: - line = sm.input() + line = input() if self.echo: sys.stdout.write('{}{}\n'.format(safe_prompt, line)) except EOFError: @@ -2798,7 +2797,7 @@ Usage: Usage: unalias [-a] name [name ...] for (idx, (value, text)) in enumerate(fulloptions): self.poutput(' %2d. %s\n' % (idx + 1, text)) while True: - response = sm.input(prompt) + response = input(prompt) hlen = readline.get_current_history_length() if hlen >= 1 and response != '': readline.remove_history_item(hlen - 1) diff --git a/docs/install.rst b/docs/install.rst index ac8b19a6..be7c61dd 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -98,7 +98,6 @@ either composition or inheritance to achieve the same goal. This approach will obviously NOT automatically install the required 3rd-party dependencies, so you need to make sure the following Python packages are installed: - * six * pyparsing * pyperclip diff --git a/docs/requirements.txt b/docs/requirements.txt index 44427665..4f05675a 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,5 +1,4 @@ pyparsing -six pyperclip contextlib2 enum34 diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 9f0b13ee..e4316757 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -6,6 +6,7 @@ Copyright 2016 Federico Ceratto <federico.ceratto@gmail.com> Released under MIT license, see LICENSE file """ import argparse +import builtins from code import InteractiveConsole import os import sys @@ -13,8 +14,6 @@ import io import tempfile import pytest -import six -import six.moves as sm # Python 3.5 had some regressions in the unitest.mock module, so use 3rd party mock if available try: @@ -839,7 +838,7 @@ def test_base_cmdloop_without_queue(): # Mock out the input call so we don't actually wait for a user's response on stdin m = mock.MagicMock(name='input', return_value='quit') - sm.input = m + builtins.input = m # Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args testargs = ["prog"] @@ -861,7 +860,7 @@ def test_cmdloop_without_rawinput(): # Mock out the input call so we don't actually wait for a user's response on stdin m = mock.MagicMock(name='input', return_value='quit') - sm.input = m + builtins.input = m # Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args testargs = ["prog"] @@ -916,7 +915,7 @@ def test_interrupt_quit(say_app): # Mock out the input call so we don't actually wait for a user's response on stdin m = mock.MagicMock(name='input') m.side_effect = ['say hello', KeyboardInterrupt(), 'say goodbye', 'eof'] - sm.input = m + builtins.input = m say_app.cmdloop() @@ -930,7 +929,7 @@ def test_interrupt_noquit(say_app): # Mock out the input call so we don't actually wait for a user's response on stdin m = mock.MagicMock(name='input') m.side_effect = ['say hello', KeyboardInterrupt(), 'say goodbye', 'eof'] - sm.input = m + builtins.input = m say_app.cmdloop() @@ -1189,7 +1188,7 @@ def select_app(): def test_select_options(select_app): # Mock out the input call so we don't actually wait for a user's response on stdin m = mock.MagicMock(name='input', return_value='2') - sm.input = m + builtins.input = m food = 'bacon' out = run_cmd(select_app, "eat {}".format(food)) @@ -1210,7 +1209,7 @@ def test_select_invalid_option(select_app): m = mock.MagicMock(name='input') # If side_effect is an iterable then each call to the mock will return the next value from the iterable. m.side_effect = ['3', '1'] # First pass and invalid selection, then pass a valid one - sm.input = m + builtins.input = m food = 'fish' out = run_cmd(select_app, "eat {}".format(food)) @@ -1232,7 +1231,7 @@ def test_select_invalid_option(select_app): def test_select_list_of_strings(select_app): # Mock out the input call so we don't actually wait for a user's response on stdin m = mock.MagicMock(name='input', return_value='2') - sm.input = m + builtins.input = m out = run_cmd(select_app, "study") expected = normalize(""" @@ -1250,7 +1249,7 @@ Good luck learning {}! def test_select_list_of_tuples(select_app): # Mock out the input call so we don't actually wait for a user's response on stdin m = mock.MagicMock(name='input', return_value='2') - sm.input = m + builtins.input = m out = run_cmd(select_app, "procrastinate") expected = normalize(""" @@ -1269,7 +1268,7 @@ Have fun procrasinating with {}! def test_select_uneven_list_of_tuples(select_app): # Mock out the input call so we don't actually wait for a user's response on stdin m = mock.MagicMock(name='input', return_value='2') - sm.input = m + builtins.input = m out = run_cmd(select_app, "play") expected = normalize(""" @@ -1352,7 +1351,7 @@ def test_multiline_complete_empty_statement_raises_exception(multiline_app): def test_multiline_complete_statement_without_terminator(multiline_app): # Mock out the input call so we don't actually wait for a user's response on stdin when it looks for more input m = mock.MagicMock(name='input', return_value='\n') - sm.input = m + builtins.input = m command = 'orate' args = 'hello world' @@ -1452,10 +1451,8 @@ def test_echo(capsys): def test_pseudo_raw_input_tty_rawinput_true(): # use context managers so original functions get put back when we are done # we dont use decorators because we need m_input for the assertion - with mock.patch('sys.stdin.isatty', - mock.MagicMock(name='isatty', return_value=True)): - with mock.patch('six.moves.input', - mock.MagicMock(name='input', side_effect=['set', EOFError])) as m_input: + with mock.patch('sys.stdin.isatty', mock.MagicMock(name='isatty', return_value=True)): + with mock.patch('builtins.input', mock.MagicMock(name='input', side_effect=['set', EOFError])) as m_input: # run the cmdloop, which should pull input from our mocks app = cmd2.Cmd() app.use_rawinput = True @@ -1498,10 +1495,8 @@ def piped_rawinput_true(capsys, echo, command): out, err = capsys.readouterr() return (app, out) -# using the decorator puts the original function at six.moves.input -# back when this method returns -@mock.patch('six.moves.input', - mock.MagicMock(name='input', side_effect=['set', EOFError])) +# using the decorator puts the original input function back when this unit test returns +@mock.patch('builtins.input', mock.MagicMock(name='input', side_effect=['set', EOFError])) def test_pseudo_raw_input_piped_rawinput_true_echo_true(capsys): command = 'set' app, out = piped_rawinput_true(capsys, True, command) @@ -1509,10 +1504,8 @@ def test_pseudo_raw_input_piped_rawinput_true_echo_true(capsys): assert out[0] == '{}{}'.format(app.prompt, command) assert out[1].startswith('colors:') -# using the decorator puts the original function at six.moves.input -# back when this method returns -@mock.patch('six.moves.input', - mock.MagicMock(name='input', side_effect=['set', EOFError])) +# using the decorator puts the original input function back when this unit test returns +@mock.patch('builtins.input', mock.MagicMock(name='input', side_effect=['set', EOFError])) def test_pseudo_raw_input_piped_rawinput_true_echo_false(capsys): command = 'set' app, out = piped_rawinput_true(capsys, False, command) @@ -1554,7 +1547,7 @@ def test_raw_input(base_app): # Mock out the input call so we don't actually wait for a user's response on stdin m = mock.Mock(name='input', return_value=fake_input) - sm.input = m + builtins.input = m line = base_app.pseudo_raw_input('(cmd2)') assert line == fake_input diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 311a3f42..a24f2fa5 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -13,7 +13,6 @@ import random from unittest import mock import pytest -import six import cmd2 from cmd2 import Cmd, Cmd2TestCase, set_posix_shlex, set_strip_quotes @@ -18,7 +18,6 @@ deps = pytest-cov pytest-forked pytest-xdist - six wcwidth commands = py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing --forked @@ -32,7 +31,6 @@ deps = pytest pytest-forked pytest-xdist - six wcwidth commands = py.test -v -n2 --forked @@ -44,7 +42,6 @@ deps = pyreadline pytest pytest-xdist - six commands = py.test -v -n2 [testenv:py36] @@ -56,7 +53,6 @@ deps = pytest-cov pytest-forked pytest-xdist - six wcwidth commands = py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing --forked @@ -71,7 +67,6 @@ deps = pytest pytest-cov pytest-xdist - six commands = py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing codecov @@ -83,7 +78,6 @@ deps = pytest pytest-forked pytest-xdist - six wcwidth commands = py.test -v -n2 --forked |