diff --git a/src/ansible_compat/prerun.py b/src/ansible_compat/prerun.py index 5d32fec0..2788f2d6 100644 --- a/src/ansible_compat/prerun.py +++ b/src/ansible_compat/prerun.py @@ -9,7 +9,7 @@ def get_cache_dir(project_dir: str) -> str: # we would use the same key regardless the location of the user home # directory or where the project is clones (as long the project folder uses # the same name). - basename = os.path.basename(project_dir).encode(encoding="utf-8") + basename = os.path.basename(os.path.abspath(project_dir)).encode(encoding="utf-8") # 6 chars of entropy should be enough cache_key = hashlib.sha256(basename).hexdigest()[:6] cache_dir = ( diff --git a/test/test_prerun.py b/test/test_prerun.py new file mode 100644 index 00000000..fa3651bf --- /dev/null +++ b/test/test_prerun.py @@ -0,0 +1,11 @@ +"""Tests for ansible_compat.prerun module.""" +import os + +from ansible_compat.prerun import get_cache_dir + + +def test_get_cache_dir_relative() -> None: + """Test behaviors of get_cache_dir.""" + relative_path = "." + abs_path = os.path.abspath(relative_path) + assert get_cache_dir(relative_path) == get_cache_dir(abs_path) diff --git a/tox.ini b/tox.ini index ad117182..ec386f25 100644 --- a/tox.ini +++ b/tox.ini @@ -52,9 +52,10 @@ setenv = PIP_DISABLE_PIP_VERSION_CHECK = 1 PIP_CONSTRAINT = {toxinidir}/constraints.txt PRE_COMMIT_COLOR = always - PYTEST_REQPASS = 73 + PYTEST_REQPASS = 74 FORCE_COLOR = 1 allowlist_externals = + ansible sh [testenv:lint]