1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-18 12:06:04 +00:00

#682: Fix tests and flake8

This commit is contained in:
Vladimir Iakovlev 2017-08-26 06:16:51 +02:00
parent cd3a3cd823
commit 31becc9456
4 changed files with 20 additions and 12 deletions

View File

@ -6,7 +6,8 @@ from thefuck.const import ARGUMENT_PLACEHOLDER
def _args(**override): def _args(**override):
args = {'alias': None, 'command': [], 'yes': False, args = {'alias': None, 'command': [], 'yes': False,
'help': False, 'version': False, 'debug': 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) args.update(override)
return args return args
@ -14,6 +15,8 @@ def _args(**override):
@pytest.mark.parametrize('argv, result', [ @pytest.mark.parametrize('argv, result', [
(['thefuck'], _args()), (['thefuck'], _args()),
(['thefuck', '-a'], _args(alias='fuck')), (['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', '-a', 'fix'], _args(alias='fix')),
(['thefuck', 'git', 'branch', ARGUMENT_PLACEHOLDER, '-y'], (['thefuck', 'git', 'branch', ARGUMENT_PLACEHOLDER, '-y'],
_args(command=['git', 'branch'], yes=True)), _args(command=['git', 'branch'], yes=True)),

View File

@ -110,13 +110,13 @@ class TestCommand(object):
Popen = Mock() Popen = Mock()
Popen.return_value.stdout.read.return_value = b'stdout' Popen.return_value.stdout.read.return_value = b'stdout'
Popen.return_value.stderr.read.return_value = b'stderr' Popen.return_value.stderr.read.return_value = b'stderr'
monkeypatch.setattr('thefuck.types.Popen', Popen) monkeypatch.setattr('thefuck.output.rerun.Popen', Popen)
return Popen return Popen
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def prepare(self, monkeypatch): def prepare(self, monkeypatch):
monkeypatch.setattr('thefuck.types.Command._wait_output', monkeypatch.setattr('thefuck.output.rerun._wait_output',
staticmethod(lambda *_: True)) lambda *_: True)
def test_from_script_calls(self, Popen, settings, os_environ): def test_from_script_calls(self, Popen, settings, os_environ):
settings.env = {} settings.env = {}

View File

@ -69,34 +69,40 @@ class TestSelectCommand(object):
def test_without_confirmation(self, capsys, commands, settings): def test_without_confirmation(self, capsys, commands, settings):
settings.require_confirmation = False settings.require_confirmation = False
assert ui.select_command(iter(commands)) == commands[0] 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( def test_without_confirmation_with_side_effects(
self, capsys, commands_with_side_effect, settings): self, capsys, commands_with_side_effect, settings):
settings.require_confirmation = False settings.require_confirmation = False
assert (ui.select_command(iter(commands_with_side_effect)) assert (ui.select_command(iter(commands_with_side_effect))
== commands_with_side_effect[0]) == 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): def test_with_confirmation(self, capsys, patch_get_key, commands):
patch_get_key(['\n']) patch_get_key(['\n'])
assert ui.select_command(iter(commands)) == commands[0] 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): def test_with_confirmation_abort(self, capsys, patch_get_key, commands):
patch_get_key([const.KEY_CTRL_C]) patch_get_key([const.KEY_CTRL_C])
assert ui.select_command(iter(commands)) is None 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, def test_with_confirmation_with_side_effct(self, capsys, patch_get_key,
commands_with_side_effect): commands_with_side_effect):
patch_get_key(['\n']) patch_get_key(['\n'])
assert (ui.select_command(iter(commands_with_side_effect)) assert (ui.select_command(iter(commands_with_side_effect))
== commands_with_side_effect[0]) == 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): def test_with_confirmation_select_second(self, capsys, patch_get_key, commands):
patch_get_key([const.KEY_DOWN, '\n']) patch_get_key([const.KEY_DOWN, '\n'])
assert ui.select_command(iter(commands)) == commands[1] assert ui.select_command(iter(commands)) == commands[1]
assert capsys.readouterr() == ( stderr = (
'', u'\x1b[1K\rls [enter/↑/↓/ctrl+c]\x1b[1K\rcd [enter/↑/↓/ctrl+c]\n') 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)

View File

@ -1,5 +1,4 @@
from imp import load_source from imp import load_source
from subprocess import Popen, PIPE
import os import os
import sys import sys
from . import logs from . import logs