dzgui/tests/test_bare_conf_files.py
aclist 4de5147899
Some checks are pending
Mirror to Codeberg / mirror-to-codeberg (push) Waiting to run
fix: parse parent directory
2026-06-28 23:52:13 +09:00

78 lines
2.1 KiB
Python

import pytest
import tempfile
import os
from dzgui.app_init import copy_bare_configs
from dzgui.config.xdg import get_xdg_paths, parse_filepaths
from pathlib import Path
CONF_STRING = "DZGUI_CONF\n"
STATE_STRING = "DZGUI_STATE\n"
@pytest.fixture
def state_files():
state = [
"dzg.history",
"dzg.versions",
"dzg.res.json",
"dzg.filters.json",
"dzg.columns.json",
"dzg.notes.json",
"ips.csv",
".month",
]
return state
@pytest.fixture
def xdg_paths():
paths = []
routes = {"XDG_CONFIG_HOME": "", "XDG_STATE_HOME": "", "XDG_DATA_HOME": "", "XDG_CACHE_HOME": ""}
for route in routes:
tmp = tempfile.TemporaryDirectory(delete=False)
routes[route] = tmp.name
for k, v in routes.items():
os.environ[k] = v
env = get_xdg_paths()
return parse_filepaths(env)
@pytest.mark.mods
def test_config_file_import(xdg_paths, state_files):
tmp_conf = xdg_paths.config.parent.parent
tmp_conf_file = tmp_conf / xdg_paths.config.name
tmp_conf_file.write_text(CONF_STRING)
tmp_state = xdg_paths.resolution.parent.parent
tmp_state_file = tmp_state / xdg_paths.resolution.name
for file in state_files:
tmp_state.joinpath(file).write_text(STATE_STRING)
config_changed, state_changed = copy_bare_configs(xdg_paths.config, xdg_paths.resolution)
assert (tmp_conf / xdg_paths.config.name).read_text() == CONF_STRING
for file in state_files:
assert (tmp_state / file).read_text() == STATE_STRING
assert config_changed is True
assert state_changed is True
@pytest.mark.mods
def test_config_file_no_import(xdg_paths, state_files):
for subdir in xdg_paths.config.parent, xdg_paths.resolution.parent:
subdir.mkdir()
tmp_conf_file = xdg_paths.config
tmp_conf_file.write_text(CONF_STRING)
tmp_state_file = xdg_paths.resolution
for file in state_files:
xdg_paths.resolution.parent.joinpath(file).write_text(STATE_STRING)
config_changed, state_changed = copy_bare_configs(xdg_paths.config, xdg_paths.resolution)
assert config_changed is False
assert state_changed is False