From a169575b0fc331f9729bfc703ff617a6c7752bd3 Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Thu, 11 Aug 2016 22:10:49 -0300 Subject: [PATCH] =?UTF-8?q?#534:=20Move=20=E2=80=9Cis=20arg=20a=20url=3F?= =?UTF-8?q?=E2=80=9D=20logic=20to=20a=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This function will be used in `get_new_command`. --- tests/rules/test_open.py | 30 ++++++++++++++++++++---------- thefuck/rules/open.py | 27 ++++++++++++++++----------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/tests/rules/test_open.py b/tests/rules/test_open.py index 109ceb66..5780e043 100644 --- a/tests/rules/test_open.py +++ b/tests/rules/test_open.py @@ -1,5 +1,5 @@ import pytest -from thefuck.rules.open import match, get_new_command +from thefuck.rules.open import is_arg_url, match, get_new_command from tests.utils import Command @@ -10,11 +10,26 @@ def stderr(script): @pytest.mark.parametrize('script', [ 'open foo.com', - 'open foo.ly', - 'open foo.org', - 'open foo.net', - 'open foo.se', + 'open foo.edu', + 'open foo.info', 'open foo.io', + 'open foo.ly', + 'open foo.me', + 'open foo.net', + 'open foo.org', + 'open foo.se', + 'open www.foo.ru']) +def test_is_arg_url(script): + assert is_arg_url(Command(script)) + + +@pytest.mark.parametrize('script', ['open foo', 'open bar.txt', 'open egg.doc']) +def test_not_is_arg_url(script): + assert not is_arg_url(Command(script)) + + +@pytest.mark.parametrize('script', [ + 'open foo.com', 'xdg-open foo.com', 'gnome-open foo.com', 'kde-open foo.com']) @@ -23,11 +38,6 @@ def test_match(script, stderr): @pytest.mark.parametrize('script, new_command', [ - ('open foo.com', 'open http://foo.com'), - ('open foo.ly', 'open http://foo.ly'), - ('open foo.org', 'open http://foo.org'), - ('open foo.net', 'open http://foo.net'), - ('open foo.se', 'open http://foo.se'), ('open foo.io', 'open http://foo.io'), ('xdg-open foo.io', 'xdg-open http://foo.io'), ('gnome-open foo.io', 'gnome-open http://foo.io'), diff --git a/thefuck/rules/open.py b/thefuck/rules/open.py index b46f497d..b253a489 100644 --- a/thefuck/rules/open.py +++ b/thefuck/rules/open.py @@ -5,21 +5,26 @@ # The file ~/github.com does not exist. # Perhaps you meant 'http://github.com'? # -from thefuck.utils import for_app +from thefuck.shells import shell +from thefuck.utils import eager, for_app + + +def is_arg_url(command): + return ('.com' in command.script or + '.edu' in command.script or + '.info' in command.script or + '.io' in command.script or + '.ly' in command.script or + '.me' in command.script or + '.net' in command.script or + '.org' in command.script or + '.se' in command.script or + 'www.' in command.script) @for_app('open', 'xdg-open', 'gnome-open', 'kde-open') def match(command): - return ('.com' in command.script - or '.net' in command.script - or '.org' in command.script - or '.ly' in command.script - or '.io' in command.script - or '.se' in command.script - or '.edu' in command.script - or '.info' in command.script - or '.me' in command.script - or 'www.' in command.script) + return is_arg_url(command) def get_new_command(command):