mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 04:18:55 +00:00
#N/A: Reset environment variables in tests
This commit is contained in:
parent
2bbba9a0c8
commit
754bb3e21f
@ -56,7 +56,13 @@ def set_shell(monkeypatch, request):
|
||||
def _set(cls):
|
||||
shell = cls()
|
||||
monkeypatch.setattr('thefuck.shells.shell', shell)
|
||||
request.addfinalizer()
|
||||
return shell
|
||||
|
||||
return _set
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def os_environ(monkeypatch):
|
||||
env = {'PATH': ''}
|
||||
monkeypatch.setattr('os.environ', env)
|
||||
return env
|
||||
|
@ -50,8 +50,8 @@ def test_match(command):
|
||||
assert match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
@pytest.mark.parametrize('command, url', [
|
||||
(Command('yarn help clean', stdout=stdout_clean),
|
||||
open_command('https://yarnpkg.com/en/docs/cli/clean'))])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command) == new_command
|
||||
'https://yarnpkg.com/en/docs/cli/clean')])
|
||||
def test_get_new_command(command, url):
|
||||
assert get_new_command(command) == open_command(url)
|
||||
|
@ -18,17 +18,14 @@ class TestFish(object):
|
||||
b'man\nmath\npopd\npushd\nruby')
|
||||
return mock
|
||||
|
||||
@pytest.fixture
|
||||
def os_environ(self, monkeypatch, key, value):
|
||||
monkeypatch.setattr('os.environ', {key: value})
|
||||
|
||||
@pytest.mark.parametrize('key, value', [
|
||||
('TF_OVERRIDDEN_ALIASES', 'cut,git,sed'), # legacy
|
||||
('THEFUCK_OVERRIDDEN_ALIASES', 'cut,git,sed'),
|
||||
('THEFUCK_OVERRIDDEN_ALIASES', 'cut, git, sed'),
|
||||
('THEFUCK_OVERRIDDEN_ALIASES', ' cut,\tgit,sed\n'),
|
||||
('THEFUCK_OVERRIDDEN_ALIASES', '\ncut,\n\ngit,\tsed\r')])
|
||||
def test_get_overridden_aliases(self, shell, os_environ):
|
||||
def test_get_overridden_aliases(self, shell, os_environ, key, value):
|
||||
os_environ[key] = value
|
||||
assert shell._get_overridden_aliases() == {'cd', 'cut', 'git', 'grep',
|
||||
'ls', 'man', 'open', 'sed'}
|
||||
|
||||
|
@ -10,14 +10,6 @@ def load_source(mocker):
|
||||
return mocker.patch('thefuck.conf.load_source')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def environ(monkeypatch):
|
||||
data = {}
|
||||
monkeypatch.setattr('thefuck.conf.os.environ', data)
|
||||
return data
|
||||
|
||||
|
||||
@pytest.mark.usefixture('environ')
|
||||
def test_settings_defaults(load_source, settings):
|
||||
load_source.return_value = object()
|
||||
settings.init()
|
||||
@ -25,7 +17,6 @@ def test_settings_defaults(load_source, settings):
|
||||
assert getattr(settings, key) == val
|
||||
|
||||
|
||||
@pytest.mark.usefixture('environ')
|
||||
class TestSettingsFromFile(object):
|
||||
def test_from_file(self, load_source, settings):
|
||||
load_source.return_value = Mock(rules=['test'],
|
||||
@ -54,15 +45,15 @@ class TestSettingsFromFile(object):
|
||||
|
||||
@pytest.mark.usefixture('load_source')
|
||||
class TestSettingsFromEnv(object):
|
||||
def test_from_env(self, environ, settings):
|
||||
environ.update({'THEFUCK_RULES': 'bash:lisp',
|
||||
'THEFUCK_EXCLUDE_RULES': 'git:vim',
|
||||
'THEFUCK_WAIT_COMMAND': '55',
|
||||
'THEFUCK_REQUIRE_CONFIRMATION': 'true',
|
||||
'THEFUCK_NO_COLORS': 'false',
|
||||
'THEFUCK_PRIORITY': 'bash=10:lisp=wrong:vim=15',
|
||||
'THEFUCK_WAIT_SLOW_COMMAND': '999',
|
||||
'THEFUCK_SLOW_COMMANDS': 'lein:react-native:./gradlew'})
|
||||
def test_from_env(self, os_environ, settings):
|
||||
os_environ.update({'THEFUCK_RULES': 'bash:lisp',
|
||||
'THEFUCK_EXCLUDE_RULES': 'git:vim',
|
||||
'THEFUCK_WAIT_COMMAND': '55',
|
||||
'THEFUCK_REQUIRE_CONFIRMATION': 'true',
|
||||
'THEFUCK_NO_COLORS': 'false',
|
||||
'THEFUCK_PRIORITY': 'bash=10:lisp=wrong:vim=15',
|
||||
'THEFUCK_WAIT_SLOW_COMMAND': '999',
|
||||
'THEFUCK_SLOW_COMMANDS': 'lein:react-native:./gradlew'})
|
||||
settings.init()
|
||||
assert settings.rules == ['bash', 'lisp']
|
||||
assert settings.exclude_rules == ['git', 'vim']
|
||||
@ -73,8 +64,8 @@ class TestSettingsFromEnv(object):
|
||||
assert settings.wait_slow_command == 999
|
||||
assert settings.slow_commands == ['lein', 'react-native', './gradlew']
|
||||
|
||||
def test_from_env_with_DEFAULT(self, environ, settings):
|
||||
environ.update({'THEFUCK_RULES': 'DEFAULT_RULES:bash:lisp'})
|
||||
def test_from_env_with_DEFAULT(self, os_environ, settings):
|
||||
os_environ.update({'THEFUCK_RULES': 'DEFAULT_RULES:bash:lisp'})
|
||||
settings.init()
|
||||
assert settings.rules == const.DEFAULT_RULES + ['bash', 'lisp']
|
||||
|
||||
@ -116,15 +107,15 @@ class TestInitializeSettingsFile(object):
|
||||
(False, '/user/test/config/', '/user/test/config/thefuck'),
|
||||
(True, '~/.config', '~/.thefuck'),
|
||||
(True, '/user/test/config/', '~/.thefuck')])
|
||||
def test_get_user_dir_path(mocker, environ, settings, legacy_dir_exists,
|
||||
def test_get_user_dir_path(mocker, os_environ, settings, legacy_dir_exists,
|
||||
xdg_config_home, result):
|
||||
mocker.patch('thefuck.conf.Path.is_dir',
|
||||
return_value=legacy_dir_exists)
|
||||
|
||||
if xdg_config_home is not None:
|
||||
environ['XDG_CONFIG_HOME'] = xdg_config_home
|
||||
os_environ['XDG_CONFIG_HOME'] = xdg_config_home
|
||||
else:
|
||||
environ.pop('XDG_CONFIG_HOME', None)
|
||||
os_environ.pop('XDG_CONFIG_HOME', None)
|
||||
|
||||
path = settings._get_user_dir_path().as_posix()
|
||||
assert path == os.path.expanduser(result)
|
||||
|
@ -115,11 +115,10 @@ class TestCommand(object):
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def prepare(self, monkeypatch):
|
||||
monkeypatch.setattr('thefuck.types.os.environ', {})
|
||||
monkeypatch.setattr('thefuck.types.Command._wait_output',
|
||||
staticmethod(lambda *_: True))
|
||||
|
||||
def test_from_script_calls(self, Popen, settings):
|
||||
def test_from_script_calls(self, Popen, settings, os_environ):
|
||||
settings.env = {}
|
||||
assert Command.from_raw_script(
|
||||
['apt-get', 'search', 'vim']) == Command(
|
||||
@ -129,7 +128,7 @@ class TestCommand(object):
|
||||
stdin=PIPE,
|
||||
stdout=PIPE,
|
||||
stderr=PIPE,
|
||||
env={})
|
||||
env=os_environ)
|
||||
|
||||
@pytest.mark.parametrize('script, result', [
|
||||
([''], None),
|
||||
|
@ -206,8 +206,7 @@ class TestGetValidHistoryWithoutCurrent(object):
|
||||
return_value='fuck')
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def bins(self, mocker, monkeypatch):
|
||||
monkeypatch.setattr('thefuck.conf.os.environ', {'PATH': 'path'})
|
||||
def bins(self, mocker):
|
||||
callables = list()
|
||||
for name in ['diff', 'ls', 'café']:
|
||||
bin_mock = mocker.Mock(name=name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user