Skip to content

Commit

Permalink
test: testing cache dir creating race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
syu-w committed Jan 2, 2024
1 parent 8d5b992 commit 6522e7a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/unit/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,20 @@ def test_get_project_other_dir(monkeypatch, tmp_path, app, fake_project_file):

assert app.get_project(fake_project_file.parent) is project
assert app.get_project() is project


def test_get_cache_dir(tmp_path, app):
"""Test that the cache dir is created and returned."""
with mock.patch("xdg.BaseDirectory.xdg_cache_home", str(tmp_path / "cache")):
assert app.cache_dir == str(tmp_path / "cache" / "testcraft")


def test_get_cache_dir_exists(tmp_path, app):
"""Test that the cache dir is returned when already exists."""
# This currently fails with pyxdg, [Errno 17] File exists
(tmp_path / "cache" / "testcraft").makedirs()
with mock.patch("xdg.BaseDirectory.xdg_cache_home", str(tmp_path / "cache")):
# Race condition here, that is in shared environment
with mock.patch("os.path.isdir") as isdir:
isdir.return_value = False
assert app.cache_dir == str(tmp_path / "cache" / "testcraft")

0 comments on commit 6522e7a

Please sign in to comment.