From 31becc94562c4881ab3b12bcc194e8290ff8f068 Mon Sep 17 00:00:00 2001 From: Vladimir Iakovlev Date: Sat, 26 Aug 2017 06:16:51 +0200 Subject: [PATCH] #682: Fix tests and flake8 --- tests/test_argument_parser.py | 5 ++++- tests/test_types.py | 6 +++--- tests/test_ui.py | 20 +++++++++++++------- thefuck/types.py | 1 - 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/tests/test_argument_parser.py b/tests/test_argument_parser.py index 015449bd..d2eb7c27 100644 --- a/tests/test_argument_parser.py +++ b/tests/test_argument_parser.py @@ -6,7 +6,8 @@ from thefuck.const import ARGUMENT_PLACEHOLDER def _args(**override): args = {'alias': None, 'command': [], 'yes': False, 'help': False, 'version': False, 'debug': False, - 'force_command': None, 'repeat': False} + 'force_command': None, 'repeat': False, + 'enable_experimental_instant_mode': False} args.update(override) return args @@ -14,6 +15,8 @@ def _args(**override): @pytest.mark.parametrize('argv, result', [ (['thefuck'], _args()), (['thefuck', '-a'], _args(alias='fuck')), + (['thefuck', '--alias', '--enable-experimental-instant-mode'], + _args(alias='fuck', enable_experimental_instant_mode=True)), (['thefuck', '-a', 'fix'], _args(alias='fix')), (['thefuck', 'git', 'branch', ARGUMENT_PLACEHOLDER, '-y'], _args(command=['git', 'branch'], yes=True)), diff --git a/tests/test_types.py b/tests/test_types.py index 6b3d81ff..45729140 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -110,13 +110,13 @@ class TestCommand(object): Popen = Mock() Popen.return_value.stdout.read.return_value = b'stdout' Popen.return_value.stderr.read.return_value = b'stderr' - monkeypatch.setattr('thefuck.types.Popen', Popen) + monkeypatch.setattr('thefuck.output.rerun.Popen', Popen) return Popen @pytest.fixture(autouse=True) def prepare(self, monkeypatch): - monkeypatch.setattr('thefuck.types.Command._wait_output', - staticmethod(lambda *_: True)) + monkeypatch.setattr('thefuck.output.rerun._wait_output', + lambda *_: True) def test_from_script_calls(self, Popen, settings, os_environ): settings.env = {} diff --git a/tests/test_ui.py b/tests/test_ui.py index 1c2a9933..1e539651 100644 --- a/tests/test_ui.py +++ b/tests/test_ui.py @@ -69,34 +69,40 @@ class TestSelectCommand(object): def test_without_confirmation(self, capsys, commands, settings): settings.require_confirmation = False assert ui.select_command(iter(commands)) == commands[0] - assert capsys.readouterr() == ('', 'ls\n') + assert capsys.readouterr() == ('', const.USER_COMMAND_MARK + 'ls\n') def test_without_confirmation_with_side_effects( self, capsys, commands_with_side_effect, settings): settings.require_confirmation = False assert (ui.select_command(iter(commands_with_side_effect)) == commands_with_side_effect[0]) - assert capsys.readouterr() == ('', 'ls (+side effect)\n') + assert capsys.readouterr() == ('', const.USER_COMMAND_MARK + 'ls (+side effect)\n') def test_with_confirmation(self, capsys, patch_get_key, commands): patch_get_key(['\n']) assert ui.select_command(iter(commands)) == commands[0] - assert capsys.readouterr() == ('', u'\x1b[1K\rls [enter/↑/↓/ctrl+c]\n') + assert capsys.readouterr() == ( + '', const.USER_COMMAND_MARK + u'\x1b[1K\rls [enter/↑/↓/ctrl+c]\n') def test_with_confirmation_abort(self, capsys, patch_get_key, commands): patch_get_key([const.KEY_CTRL_C]) assert ui.select_command(iter(commands)) is None - assert capsys.readouterr() == ('', u'\x1b[1K\rls [enter/↑/↓/ctrl+c]\nAborted\n') + assert capsys.readouterr() == ( + '', const.USER_COMMAND_MARK + u'\x1b[1K\rls [enter/↑/↓/ctrl+c]\nAborted\n') def test_with_confirmation_with_side_effct(self, capsys, patch_get_key, commands_with_side_effect): patch_get_key(['\n']) assert (ui.select_command(iter(commands_with_side_effect)) == commands_with_side_effect[0]) - assert capsys.readouterr() == ('', u'\x1b[1K\rls (+side effect) [enter/↑/↓/ctrl+c]\n') + assert capsys.readouterr() == ( + '', const.USER_COMMAND_MARK + u'\x1b[1K\rls (+side effect) [enter/↑/↓/ctrl+c]\n') def test_with_confirmation_select_second(self, capsys, patch_get_key, commands): patch_get_key([const.KEY_DOWN, '\n']) assert ui.select_command(iter(commands)) == commands[1] - assert capsys.readouterr() == ( - '', u'\x1b[1K\rls [enter/↑/↓/ctrl+c]\x1b[1K\rcd [enter/↑/↓/ctrl+c]\n') + stderr = ( + u'{mark}\x1b[1K\rls [enter/↑/↓/ctrl+c]' + u'{mark}\x1b[1K\rcd [enter/↑/↓/ctrl+c]\n' + ).format(mark=const.USER_COMMAND_MARK) + assert capsys.readouterr() == ('', stderr) diff --git a/thefuck/types.py b/thefuck/types.py index 461ac18b..872daa9b 100644 --- a/thefuck/types.py +++ b/thefuck/types.py @@ -1,5 +1,4 @@ from imp import load_source -from subprocess import Popen, PIPE import os import sys from . import logs