import os from src.utils import config from src.utils import platform_utils def _set_os(monkeypatch, system): monkeypatch.setattr(platform_utils, 'system', lambda: system) def test_config_path_linux_uses_xdg_config_home(monkeypatch, tmp_path): _set_os(monkeypatch, platform_utils.LINUX) monkeypatch.setenv('XDG_CONFIG_HOME', str(tmp_path)) assert config.get_config_path() == os.path.join( str(tmp_path), platform_utils.APP_DIR_NAME, 'albion-online-stats.cfg') def test_config_path_linux_falls_back_to_home(monkeypatch, tmp_path): _set_os(monkeypatch, platform_utils.LINUX) monkeypatch.delenv('XDG_CONFIG_HOME', raising=False) monkeypatch.setenv('HOME', str(tmp_path)) assert config.get_config_path() == os.path.join( str(tmp_path), '.config', platform_utils.APP_DIR_NAME, 'albion-online-stats.cfg') def test_config_path_windows_uses_appdata(monkeypatch, tmp_path): _set_os(monkeypatch, platform_utils.WINDOWS) monkeypatch.setenv('APPDATA', str(tmp_path)) assert config.get_config_path() == os.path.join( str(tmp_path), platform_utils.APP_DIR_NAME, 'albion-online-stats.cfg') def test_config_path_falls_back_to_script_dir(monkeypatch): _set_os(monkeypatch, 'SomethingElse') assert os.path.basename(config.get_config_path()) == 'albion-online-stats.cfg' def test_config_creates_missing_directory(monkeypatch, tmp_path): _set_os(monkeypatch, platform_utils.LINUX) monkeypatch.setenv('XDG_CONFIG_HOME', str(tmp_path)) monkeypatch.setattr(config, '_config', None) expected = os.path.join( str(tmp_path), platform_utils.APP_DIR_NAME, 'albion-online-stats.cfg') cfg = config.config() assert os.path.isfile(expected) assert cfg['window']['width'] == 1280 assert cfg['window']['height'] == 720 assert cfg['window']['fullscreen'] is True config._config = None