Skip to content

Commit

Permalink
#697: Encode expanded script on Python 2
Browse files Browse the repository at this point in the history
Fix #697
  • Loading branch information
scorphus committed Aug 17, 2021
1 parent 2a166a7 commit 7b7c150
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/output_readers/test_rerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def test_get_output_invalid_continuation_byte(self, popen_mock):
actual = rerun.get_output('', '')
assert actual == expected

@patch('thefuck.output_readers.rerun._wait_output')
def test_get_output_unicode_misspell(self, wait_output_mock):
rerun.get_output(u'pácman', u'pácman')
wait_output_mock.assert_called_once()

def test_wait_output_is_slow(self, settings):
assert rerun._wait_output(Mock(), True)
self.proc_mock.wait.assert_called_once_with(settings.wait_slow_command)
Expand Down
3 changes: 3 additions & 0 deletions thefuck/output_readers/read_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def _group_by_calls(log):


def _get_script_group_lines(grouped, script):
if six.PY2:
script = script.encode('utf-8')

parts = shlex.split(script)

for script_line, lines in reversed(grouped):
Expand Down
4 changes: 4 additions & 0 deletions thefuck/output_readers/rerun.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import shlex
import six
from subprocess import Popen, PIPE, STDOUT
from psutil import AccessDenied, Process, TimeoutExpired
from .. import logs
Expand Down Expand Up @@ -53,6 +54,9 @@ def get_output(script, expanded):
env = dict(os.environ)
env.update(settings.env)

if six.PY2:
expanded = expanded.encode('utf-8')

split_expand = shlex.split(expanded)
is_slow = split_expand[0] in settings.slow_commands if split_expand else False
with logs.debug_time(u'Call: {}; with env: {}; is slow: {}'.format(
Expand Down

0 comments on commit 7b7c150

Please sign in to comment.