mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 03:56:01 +00:00
#682: Fix tests and flake8
This commit is contained in:
parent
cd3a3cd823
commit
31becc9456
@ -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)),
|
||||
|
@ -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 = {}
|
||||
|
@ -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)
|
||||
|
@ -1,5 +1,4 @@
|
||||
from imp import load_source
|
||||
from subprocess import Popen, PIPE
|
||||
import os
|
||||
import sys
|
||||
from . import logs
|
||||
|
Loading…
Reference in New Issue
Block a user