mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-20 20:09:07 +00:00
#540: Fix code style, add test
This commit is contained in:
parent
1a4d74d487
commit
afd2ed4e51
@ -1,5 +1,6 @@
|
||||
import pytest
|
||||
import six
|
||||
import os
|
||||
from mock import Mock
|
||||
from thefuck import const
|
||||
|
||||
@ -101,3 +102,22 @@ class TestInitializeSettingsFile(object):
|
||||
for setting in const.DEFAULT_SETTINGS.items():
|
||||
assert '# {} = {}\n'.format(*setting) in settings_file_contents
|
||||
settings_file.close()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('legacy_dir_exists, xdg_config_home, result', [
|
||||
(False, '~/.config', '~/.config/thefuck'),
|
||||
(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,
|
||||
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
|
||||
else:
|
||||
environ.pop('XDG_CONFIG_HOME', None)
|
||||
|
||||
path = settings._get_user_dir_path().as_posix()
|
||||
assert path == os.path.expanduser(result)
|
||||
|
@ -40,21 +40,18 @@ class Settings(dict):
|
||||
settings_file.write(u'# {} = {}\n'.format(*setting))
|
||||
|
||||
def _get_user_dir_path(self):
|
||||
"""returns Path object representing the user config resource"""
|
||||
xdg_config_home = os.getenv("XDG_CONFIG_HOME", "~/.config")
|
||||
user_dir_modern = Path(xdg_config_home, 'thefuck').expanduser()
|
||||
user_dir_legacy = Path('~', '.thefuck').expanduser()
|
||||
"""Returns Path object representing the user config resource"""
|
||||
xdg_config_home = os.environ.get('XDG_CONFIG_HOME', '~/.config')
|
||||
user_dir = Path(xdg_config_home, 'thefuck').expanduser()
|
||||
legacy_user_dir = Path('~', '.thefuck').expanduser()
|
||||
|
||||
# default to standards-based location
|
||||
user_dir = user_dir_modern
|
||||
|
||||
# for backward compatibility use legacy '~/.thefuck' if it exists
|
||||
if user_dir_legacy.is_dir():
|
||||
user_dir = user_dir_legacy
|
||||
message = 'config path {} is deprecated. please move to {}'
|
||||
warn(message.format(user_dir_legacy, user_dir_modern))
|
||||
|
||||
return user_dir
|
||||
# For backward compatibility use legacy '~/.thefuck' if it exists:
|
||||
if legacy_user_dir.is_dir():
|
||||
warn(u'Config path {} is deprecated. Please move to {}'.format(
|
||||
legacy_user_dir, user_dir))
|
||||
return legacy_user_dir
|
||||
else:
|
||||
return user_dir
|
||||
|
||||
def _setup_user_dir(self):
|
||||
"""Returns user config dir, create it when it doesn't exist."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user