From ed24e4ca61d5943a4ff6c4db7217f810e75b2632 Mon Sep 17 00:00:00 2001 From: Vladimir Iakovlev Date: Fri, 23 Feb 2018 20:45:36 +0100 Subject: [PATCH] Squashed commit of the following: commit 8573f94c2f3ba17ec5d7dd123338c14a550e57e6 Author: Vladimir Iakovlev Date: Fri Feb 23 20:45:01 2018 +0100 #785: Remove functional test commit 5484576d6e3ef4a53d69860ef953bb48037e8a72 Merge: a36a8b4 f59aa93 Author: Vladimir Iakovlev Date: Fri Feb 23 20:44:20 2018 +0100 Merge branch 'master' of https://github.com/alexbarcelo/thefuck into alexbarcelo-master commit f59aa931c3d76b40b2078cf2926b239dc0798b74 Author: Alex Barcelo Date: Fri Feb 16 23:43:43 2018 +0100 rewritten match + fish output check for cd_* rules commit 150ecee00ff3354a2b952a55565d08ed26161273 Author: Alex Barcelo Date: Fri Feb 16 23:43:19 2018 +0100 Adding unittest for cd_correction (with extra fish test case, also for cd_mkdir) commit e73dd3f6d108fa081da891c61f91968afd9c5518 Author: Alex Barcelo Date: Fri Feb 16 22:48:22 2018 +0100 adding functional test for cd_correction rule commit d1dbbb57d96df06cf0608f2d4325abf265498aa6 Author: Alex Barcelo Date: Fri Feb 16 12:21:33 2018 +0100 Include root (start with /) case --- tests/rules/test_cd_correction.py | 23 +++++++++++++++++++++++ tests/rules/test_cd_mkdir.py | 3 ++- thefuck/rules/cd_correction.py | 15 +++++++++++---- thefuck/rules/cd_mkdir.py | 9 +++++---- 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 tests/rules/test_cd_correction.py diff --git a/tests/rules/test_cd_correction.py b/tests/rules/test_cd_correction.py new file mode 100644 index 00000000..d2576584 --- /dev/null +++ b/tests/rules/test_cd_correction.py @@ -0,0 +1,23 @@ +import pytest +from thefuck.rules.cd_correction import match +from thefuck.types import Command + + +@pytest.mark.parametrize('command', [ + Command('cd foo', 'cd: foo: No such file or directory'), + Command('cd foo/bar/baz', + 'cd: foo: No such file or directory'), + Command('cd foo/bar/baz', 'cd: can\'t cd to foo/bar/baz'), + Command('cd /foo/bar/', 'cd: The directory "/foo/bar/" does not exist')]) +def test_match(command): + assert match(command) + + +@pytest.mark.parametrize('command', [ + Command('cd foo', ''), Command('', '')]) +def test_not_match(command): + assert not match(command) + + +# Note that get_new_command uses local filesystem, so not testing it here. +# Instead, see the functional test `functional.test_cd_correction` diff --git a/tests/rules/test_cd_mkdir.py b/tests/rules/test_cd_mkdir.py index 61dc30e1..aa3d82ef 100644 --- a/tests/rules/test_cd_mkdir.py +++ b/tests/rules/test_cd_mkdir.py @@ -7,7 +7,8 @@ from thefuck.types import Command Command('cd foo', 'cd: foo: No such file or directory'), Command('cd foo/bar/baz', 'cd: foo: No such file or directory'), - Command('cd foo/bar/baz', 'cd: can\'t cd to foo/bar/baz')]) + Command('cd foo/bar/baz', 'cd: can\'t cd to foo/bar/baz'), + Command('cd /foo/bar/', 'cd: The directory "/foo/bar/" does not exist')]) def test_match(command): assert match(command) diff --git a/thefuck/rules/cd_correction.py b/thefuck/rules/cd_correction.py index ca3464b1..376e51ed 100644 --- a/thefuck/rules/cd_correction.py +++ b/thefuck/rules/cd_correction.py @@ -21,9 +21,12 @@ def _get_sub_dirs(parent): @for_app('cd') def match(command): """Match function copied from cd_mkdir.py""" - return (command.script.startswith('cd ') - and ('no such file or directory' in command.output.lower() - or 'cd: can\'t cd to' in command.output.lower())) + return ( + command.script.startswith('cd ') and any(( + 'no such file or directory' in command.output.lower(), + 'cd: can\'t cd to' in command.output.lower(), + 'does not exist' in command.output.lower() + ))) @sudo_support @@ -37,7 +40,11 @@ def get_new_command(command): dest = command.script_parts[1].split(os.sep) if dest[-1] == '': dest = dest[:-1] - if six.PY2: + + if dest[0] == '': + cwd = os.sep + dest = dest[1:] + elif six.PY2: cwd = os.getcwdu() else: cwd = os.getcwd() diff --git a/thefuck/rules/cd_mkdir.py b/thefuck/rules/cd_mkdir.py index 09e3ab64..363b92d4 100644 --- a/thefuck/rules/cd_mkdir.py +++ b/thefuck/rules/cd_mkdir.py @@ -8,10 +8,11 @@ from thefuck.shells import shell @for_app('cd') def match(command): return ( - 'no such file or directory' in command.output.lower() - or 'cd: can\'t cd to' in command.output.lower() - or 'the system cannot find the path specified.' in command.output.lower() - ) + command.script.startswith('cd ') and any(( + 'no such file or directory' in command.output.lower(), + 'cd: can\'t cd to' in command.output.lower(), + 'does not exist' in command.output.lower() + ))) @sudo_support