From db6053b301e2b3f4363401e457b5dc4ad2e8429b Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Wed, 6 Apr 2016 22:58:08 -0300 Subject: [PATCH] #253: Update default overridden aliases with user's --- tests/shells/test_fish.py | 17 ++++++++++------- thefuck/shells/fish.py | 9 ++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/shells/test_fish.py b/tests/shells/test_fish.py index 7dd46848..7f32da3a 100644 --- a/tests/shells/test_fish.py +++ b/tests/shells/test_fish.py @@ -19,14 +19,17 @@ class TestFish(object): return mock @pytest.fixture - def environ(self, monkeypatch): - data = {'TF_OVERRIDDEN_ALIASES': 'cd, ls, man, open'} - monkeypatch.setattr('thefuck.shells.fish.os.environ', data) - return data + def tf_overridden(self, monkeypatch, aliases): + monkeypatch.setattr('os.environ', {'TF_OVERRIDDEN_ALIASES': aliases}) - @pytest.mark.usefixture('environ') - def test_get_overridden_aliases(self, shell, environ): - assert shell._get_overridden_aliases() == ['cd', 'ls', 'man', 'open'] + @pytest.mark.parametrize('aliases', [ + 'cut,git,sed', + 'cut, git, sed', + ' cut,\tgit,sed\n', + '\ncut,\n\ngit,\tsed\r']) + def test_get_overridden_aliases(self, shell, tf_overridden): + assert shell._get_overridden_aliases() == {'cd', 'cut', 'git', 'grep', + 'ls', 'man', 'open', 'sed'} @pytest.mark.parametrize('before, after', [ ('cd', 'cd'), diff --git a/thefuck/shells/fish.py b/thefuck/shells/fish.py index bc2b2ec7..b1ef2d7b 100644 --- a/thefuck/shells/fish.py +++ b/thefuck/shells/fish.py @@ -7,11 +7,10 @@ from .generic import Generic class Fish(Generic): def _get_overridden_aliases(self): - overridden_aliases = os.environ.get('TF_OVERRIDDEN_ALIASES', '').strip() - if overridden_aliases: - return [alias.strip() for alias in overridden_aliases.split(',')] - else: - return ['cd', 'grep', 'ls', 'man', 'open'] + default = {'cd', 'grep', 'ls', 'man', 'open'} + for alias in os.environ.get('TF_OVERRIDDEN_ALIASES', '').split(','): + default.add(alias.strip()) + return default def app_alias(self, fuck): # It is VERY important to have the variables declared WITHIN the alias