"""Tests for fungus.path_manager — PathManager static methods.""" import os from unittest.mock import patch from fungus.path_manager import PathManager class TestUserConfig: def test_default_fallback(self): """When XDG_CONFIG_HOME is unset, falls back to ~/.config.""" env = os.environ.copy() env.pop("XDG_CONFIG_HOME", None) with patch.dict(os.environ, env, clear=True): result = PathManager.user_config() assert "config" in result assert result.endswith(".config") def test_custom_xdg_config_home(self): with patch.dict(os.environ, {"XDG_CONFIG_HOME": "/tmp/myconfig"}): result = PathManager.user_config("fungus-launcher") assert result == "/tmp/myconfig/fungus-launcher" def test_joins_multiple_segments(self): with patch.dict(os.environ, {"XDG_CONFIG_HOME": "/tmp/c"}): result = PathManager.user_config("fungus-launcher", "sub", "dir") assert result == "/tmp/c/fungus-launcher/sub/dir" class TestUserData: def test_default_fallback(self): """When XDG_DATA_HOME is unset, falls back to ~/.local/share.""" env = os.environ.copy() env.pop("XDG_DATA_HOME", None) with patch.dict(os.environ, env, clear=True): result = PathManager.user_data() assert "local/share" in result def test_custom_xdg_data_home(self): with patch.dict(os.environ, {"XDG_DATA_HOME": "/tmp/mydata"}): result = PathManager.user_data("Steam") assert result == "/tmp/mydata/Steam" class TestFindBinary: def test_finds_existing_binary(self): """Should find python3 which is on the PATH.""" result = PathManager.find_binary("python3") assert result != "" def test_nonexistent_binary(self): with patch.dict(os.environ, {"PATH": "/nonexistent"}): result = PathManager.find_binary("somebinary") assert result == "" class TestGetIcon: def test_returns_fallback_when_not_found(self): """When no icon exists, returns the last fallback path.""" result = PathManager.get_icon("nonexistent-icon.png") assert "nonexistent-icon.png" in result class TestSystemData: def test_searches_xdg_data_dirs(self): """Should return the first existing path from XDG_DATA_DIRS.""" with patch.dict( os.environ, {"XDG_DATA_DIRS": "/nonexistent1:/nonexistent2:/usr/share"}, clear=True, ): result = PathManager.system_data("icons") assert result == "/usr/share/icons" def test_returns_first_existing(self): """Should return the first existing directory, not the last.""" with patch.dict( os.environ, {"XDG_DATA_DIRS": "/usr/share:/usr/local/share"}, clear=True, ): result = PathManager.system_data("applications") # /usr/share/applications should exist assert "applications" in result