From 7a57355e7e5d24f6d8daf36031df783ef46fdaba Mon Sep 17 00:00:00 2001 From: Vladimir Iakovlev Date: Sat, 26 Aug 2017 13:16:10 +0200 Subject: [PATCH] #682: Disable instant mode on Python 2 --- tests/test_types.py | 4 ++-- thefuck/output_readers/__init__.py | 11 ++++++++++- thefuck/output_readers/read_log.py | 13 ++++++++++++- thefuck/output_readers/rerun.py | 7 +++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/tests/test_types.py b/tests/test_types.py index 4572914..d9326d3 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -110,12 +110,12 @@ 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.output.rerun.Popen', Popen) + monkeypatch.setattr('thefuck.output_readers.rerun.Popen', Popen) return Popen @pytest.fixture(autouse=True) def prepare(self, monkeypatch): - monkeypatch.setattr('thefuck.output.rerun._wait_output', + monkeypatch.setattr('thefuck.output_readers.rerun._wait_output', lambda *_: True) def test_from_script_calls(self, Popen, settings, os_environ): diff --git a/thefuck/output_readers/__init__.py b/thefuck/output_readers/__init__.py index cdd69d0..c07a8cb 100644 --- a/thefuck/output_readers/__init__.py +++ b/thefuck/output_readers/__init__.py @@ -3,7 +3,16 @@ from . import read_log, rerun def get_output(script, expanded): + """Get output of the script. + + :param script: Console script. + :type script: str + :param expanded: Console script with expanded aliases. + :type expanded: str + :rtype: (str, str) + + """ if settings.instant_mode: - return read_log.get_output(script, expanded) + return read_log.get_output(script) else: return rerun.get_output(script, expanded) diff --git a/thefuck/output_readers/read_log.py b/thefuck/output_readers/read_log.py index 47dfa94..ffb8da6 100644 --- a/thefuck/output_readers/read_log.py +++ b/thefuck/output_readers/read_log.py @@ -5,6 +5,7 @@ try: except ImportError: from backports.shutil_get_terminal_size import get_terminal_size from warnings import warn +import six import pyte from ..exceptions import ScriptNotInLog from .. import const @@ -53,7 +54,17 @@ def _get_output_lines(script, log_file): return screen.display -def get_output(script, _): +def get_output(script): + """Reads script output from log. + + :type script: str + :rtype: (str, str) + + """ + if six.PY2: + warn('Experimental instant mode is Python 3+ only') + return None, None + if 'THEFUCK_OUTPUT_LOG' not in os.environ: warn("Output log isn't specified") return None, None diff --git a/thefuck/output_readers/rerun.py b/thefuck/output_readers/rerun.py index 2583de9..571dd3a 100644 --- a/thefuck/output_readers/rerun.py +++ b/thefuck/output_readers/rerun.py @@ -29,6 +29,13 @@ def _wait_output(popen, is_slow): def get_output(script, expanded): + """Runs the script and obtains stdin/stderr. + + :type script: str + :type expanded: str + :rtype: (str, str) + + """ env = dict(os.environ) env.update(settings.env)