#334: Don't wait for all rules before showing result
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import pytest
|
||||
from mock import Mock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def no_memoize(monkeypatch):
|
||||
monkeypatch.setattr('thefuck.utils.memoize.disabled', True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def settings():
|
||||
return Mock(debug=False, no_colors=True)
|
||||
|
||||
+2
-11
@@ -3,7 +3,7 @@ from pathlib import PosixPath, Path
|
||||
from mock import Mock
|
||||
from thefuck import corrector, conf, types
|
||||
from tests.utils import Rule, Command, CorrectedCommand
|
||||
from thefuck.corrector import make_corrected_commands, get_corrected_commands, remove_duplicates
|
||||
from thefuck.corrector import make_corrected_commands, get_corrected_commands
|
||||
|
||||
|
||||
def test_load_rule(mocker):
|
||||
@@ -75,15 +75,6 @@ class TestGetCorrectedCommands(object):
|
||||
== [CorrectedCommand(script='test!', priority=100)]
|
||||
|
||||
|
||||
def test_remove_duplicates():
|
||||
side_effect = lambda *_: None
|
||||
assert set(remove_duplicates([CorrectedCommand('ls', priority=100),
|
||||
CorrectedCommand('ls', priority=200),
|
||||
CorrectedCommand('ls', side_effect, 300)])) \
|
||||
== {CorrectedCommand('ls', priority=100),
|
||||
CorrectedCommand('ls', side_effect, 300)}
|
||||
|
||||
|
||||
def test_get_corrected_commands(mocker):
|
||||
command = Command('test', 'test', 'test')
|
||||
rules = [Rule(match=lambda *_: False),
|
||||
@@ -94,4 +85,4 @@ def test_get_corrected_commands(mocker):
|
||||
priority=60)]
|
||||
mocker.patch('thefuck.corrector.get_rules', return_value=rules)
|
||||
assert [cmd.script for cmd in get_corrected_commands(command, None, Mock(debug=False))] \
|
||||
== ['test@', 'test!', 'test;']
|
||||
== ['test!', 'test@', 'test;']
|
||||
|
||||
+31
-2
@@ -1,5 +1,6 @@
|
||||
from thefuck.types import RulesNamesList, Settings
|
||||
from tests.utils import Rule
|
||||
from thefuck.types import RulesNamesList, Settings, \
|
||||
SortedCorrectedCommandsSequence
|
||||
from tests.utils import Rule, CorrectedCommand
|
||||
|
||||
|
||||
def test_rules_names_list():
|
||||
@@ -15,3 +16,31 @@ def test_update_settings():
|
||||
assert new_settings.key == 'val'
|
||||
assert new_settings.unset == 'unset-value'
|
||||
assert settings.key == 'val'
|
||||
|
||||
|
||||
class TestSortedCorrectedCommandsSequence(object):
|
||||
def test_realises_generator_only_on_demand(self, settings):
|
||||
should_realise = False
|
||||
|
||||
def gen():
|
||||
nonlocal should_realise
|
||||
yield CorrectedCommand('git commit')
|
||||
yield CorrectedCommand('git branch', priority=200)
|
||||
assert should_realise
|
||||
yield CorrectedCommand('git checkout', priority=100)
|
||||
|
||||
commands = SortedCorrectedCommandsSequence(gen(), settings)
|
||||
assert commands[0] == CorrectedCommand('git commit')
|
||||
should_realise = True
|
||||
assert commands[1] == CorrectedCommand('git checkout', priority=100)
|
||||
assert commands[2] == CorrectedCommand('git branch', priority=200)
|
||||
|
||||
def test_remove_duplicates(self, settings):
|
||||
side_effect = lambda *_: None
|
||||
seq = SortedCorrectedCommandsSequence(
|
||||
iter([CorrectedCommand('ls', priority=100),
|
||||
CorrectedCommand('ls', priority=200),
|
||||
CorrectedCommand('ls', side_effect, 300)]),
|
||||
settings)
|
||||
assert set(seq) == {CorrectedCommand('ls', priority=100),
|
||||
CorrectedCommand('ls', side_effect, 300)}
|
||||
|
||||
+15
-9
@@ -4,7 +4,7 @@ from mock import Mock
|
||||
import pytest
|
||||
from itertools import islice
|
||||
from thefuck import ui
|
||||
from thefuck.types import CorrectedCommand
|
||||
from thefuck.types import CorrectedCommand, SortedCorrectedCommandsSequence
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -58,14 +58,18 @@ def test_command_selector():
|
||||
|
||||
class TestSelectCommand(object):
|
||||
@pytest.fixture
|
||||
def commands_with_side_effect(self):
|
||||
return [CorrectedCommand('ls', lambda *_: None, 100),
|
||||
CorrectedCommand('cd', lambda *_: None, 100)]
|
||||
def commands_with_side_effect(self, settings):
|
||||
return SortedCorrectedCommandsSequence(
|
||||
iter([CorrectedCommand('ls', lambda *_: None, 100),
|
||||
CorrectedCommand('cd', lambda *_: None, 100)]),
|
||||
settings)
|
||||
|
||||
@pytest.fixture
|
||||
def commands(self):
|
||||
return [CorrectedCommand('ls', None, 100),
|
||||
CorrectedCommand('cd', None, 100)]
|
||||
def commands(self, settings):
|
||||
return SortedCorrectedCommandsSequence(
|
||||
iter([CorrectedCommand('ls', None, 100),
|
||||
CorrectedCommand('cd', None, 100)]),
|
||||
settings)
|
||||
|
||||
def test_without_commands(self, capsys):
|
||||
assert ui.select_command([], Mock(debug=False, no_color=True)) is None
|
||||
@@ -92,9 +96,11 @@ class TestSelectCommand(object):
|
||||
require_confirmation=True)) == commands[0]
|
||||
assert capsys.readouterr() == ('', u'\x1b[1K\rls [enter/↑/↓/ctrl+c]\n')
|
||||
|
||||
def test_with_confirmation_one_match(self, capsys, patch_getch, commands):
|
||||
def test_with_confirmation_one_match(self, capsys, patch_getch, commands,
|
||||
settings):
|
||||
patch_getch(['\n'])
|
||||
assert ui.select_command((commands[0],),
|
||||
seq = SortedCorrectedCommandsSequence(iter([commands[0]]), settings)
|
||||
assert ui.select_command(seq,
|
||||
Mock(debug=False, no_color=True,
|
||||
require_confirmation=True)) == commands[0]
|
||||
assert capsys.readouterr() == ('', u'\x1b[1K\rls [enter/ctrl+c]\n')
|
||||
|
||||
Reference in New Issue
Block a user