Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update configmanager.py to expand user directory in returned paths #304

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions surfactant/configmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def _get_config_file_path(self) -> Path:
config_dir = Path(os.getenv("APPDATA", str(Path("~\\AppData\\Roaming"))))
else:
config_dir = Path(os.getenv("XDG_CONFIG_HOME", str(Path("~/.config"))))
config_dir = config_dir / self.app_name
return config_dir / "config.toml"
config_dir = config_dir / self.app_name / "config.toml"
return config_dir.expanduser()

def _load_config(self) -> None:
"""Loads the configuration from the configuration file."""
Expand Down Expand Up @@ -153,4 +153,4 @@ def get_data_dir_path(self) -> Path:
else:
data_dir = Path(os.getenv("XDG_DATA_HOME", str(Path("~/.local/share"))))
data_dir = data_dir / self.app_name
return data_dir
return data_dir.expanduser()
8 changes: 4 additions & 4 deletions tests/config/test_configmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_config_file_creation(config_manager):
@pytest.mark.skipif(platform.system() != "Windows", reason="Test specific to Windows platform")
def test_windows_config_path():
config_manager = ConfigManager(app_name="testapp")
config_path = config_manager._get_config_file_path().expanduser() # pylint: disable=protected-access
config_path = config_manager._get_config_file_path() # pylint: disable=protected-access
expected_config_dir = Path(os.getenv("APPDATA", str(Path("~\\AppData\\Roaming").expanduser())))
assert expected_config_dir in config_path.parents
assert config_path.parts[-2:] == ("testapp", "config.toml")
Expand All @@ -68,7 +68,7 @@ def test_windows_config_path():
@pytest.mark.skipif(platform.system() == "Windows", reason="Test specific to Unix-like platforms")
def test_unix_config_path():
config_manager = ConfigManager(app_name="testapp")
config_path = config_manager._get_config_file_path().expanduser() # pylint: disable=protected-access
config_path = config_manager._get_config_file_path() # pylint: disable=protected-access
expected_config_dir = Path(os.getenv("XDG_CONFIG_HOME", str(Path("~/.config").expanduser())))
assert expected_config_dir in config_path.parents
assert config_path.parts[-2:] == ("testapp", "config.toml")
Expand All @@ -79,7 +79,7 @@ def test_unix_config_path():
@pytest.mark.skipif(platform.system() != "Windows", reason="Test specific to Windows platform")
def test_windows_data_dir_path():
config_manager = ConfigManager(app_name="testapp")
data_dir = config_manager.get_data_dir_path().expanduser() # pylint: disable=protected-access
data_dir = config_manager.get_data_dir_path() # pylint: disable=protected-access
expected_data_dir = Path(os.getenv("LOCALAPPDATA", str(Path("~\\AppData\\Local").expanduser())))
assert expected_data_dir in data_dir.parents
assert data_dir.name == "testapp"
Expand All @@ -90,7 +90,7 @@ def test_windows_data_dir_path():
@pytest.mark.skipif(platform.system() == "Windows", reason="Test specific to Unix-like platforms")
def test_unix_data_dir_path():
config_manager = ConfigManager(app_name="testapp")
data_dir = config_manager.get_data_dir_path().expanduser() # pylint: disable=protected-access
data_dir = config_manager.get_data_dir_path() # pylint: disable=protected-access
expected_data_dir = Path(os.getenv("XDG_DATA_HOME", str(Path("~/.local/share").expanduser())))
assert expected_data_dir in data_dir.parents
assert data_dir.name == "testapp"
Expand Down
Loading