Merge pull request #1443 from pre-commit/realpath_cache_dir

Use the real path of the cache root
This commit is contained in:
Anthony Sottile 2020-05-08 15:48:00 -07:00 committed by GitHub
commit 182658c88c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View file

@ -30,10 +30,11 @@ def _get_default_directory() -> str:
`Store.get_default_directory` can be mocked in tests and `Store.get_default_directory` can be mocked in tests and
`_get_default_directory` can be tested. `_get_default_directory` can be tested.
""" """
return os.environ.get('PRE_COMMIT_HOME') or os.path.join( ret = os.environ.get('PRE_COMMIT_HOME') or os.path.join(
os.environ.get('XDG_CACHE_HOME') or os.path.expanduser('~/.cache'), os.environ.get('XDG_CACHE_HOME') or os.path.expanduser('~/.cache'),
'pre-commit', 'pre-commit',
) )
return os.path.realpath(ret)
class Store: class Store:

View file

@ -25,7 +25,8 @@ def test_our_session_fixture_works():
def test_get_default_directory_defaults_to_home(): def test_get_default_directory_defaults_to_home():
# Not we use the module level one which is not mocked # Not we use the module level one which is not mocked
ret = _get_default_directory() ret = _get_default_directory()
assert ret == os.path.join(os.path.expanduser('~/.cache'), 'pre-commit') expected = os.path.realpath(os.path.expanduser('~/.cache/pre-commit'))
assert ret == expected
def test_adheres_to_xdg_specification(): def test_adheres_to_xdg_specification():
@ -33,7 +34,8 @@ def test_adheres_to_xdg_specification():
os.environ, {'XDG_CACHE_HOME': '/tmp/fakehome'}, os.environ, {'XDG_CACHE_HOME': '/tmp/fakehome'},
): ):
ret = _get_default_directory() ret = _get_default_directory()
assert ret == os.path.join('/tmp/fakehome', 'pre-commit') expected = os.path.realpath('/tmp/fakehome/pre-commit')
assert ret == expected
def test_uses_environment_variable_when_present(): def test_uses_environment_variable_when_present():
@ -41,7 +43,8 @@ def test_uses_environment_variable_when_present():
os.environ, {'PRE_COMMIT_HOME': '/tmp/pre_commit_home'}, os.environ, {'PRE_COMMIT_HOME': '/tmp/pre_commit_home'},
): ):
ret = _get_default_directory() ret = _get_default_directory()
assert ret == '/tmp/pre_commit_home' expected = os.path.realpath('/tmp/pre_commit_home')
assert ret == expected
def test_store_init(store): def test_store_init(store):