mirror of
https://github.com/aclist/dztui.git
synced 2026-10-25 12:12:31 +01:00
This commit is contained in:
1 parent
4c31cd7ecd
commit
4de5147899
4 files changed
+51
-40
No files matched your search
@@ -1,9 +1,15 @@
|
||||
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 = [
|
||||
@@ -14,55 +20,58 @@ def state_files():
|
||||
"dzg.columns.json",
|
||||
"dzg.notes.json",
|
||||
"ips.csv",
|
||||
".month"
|
||||
".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(state_files):
|
||||
conf_string = "DZGUI_CONF\n"
|
||||
state_string = "DZGUI_STATE\n"
|
||||
def test_config_file_import(xdg_paths, state_files):
|
||||
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
tmp2 = tempfile.TemporaryDirectory()
|
||||
tmp_conf = Path(tmp.name)
|
||||
tmp_state = Path(tmp2.name)
|
||||
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
|
||||
|
||||
tmp_conf_file = tmp_conf / "config.json"
|
||||
tmp_conf_file.write_text(conf_string)
|
||||
for file in state_files:
|
||||
tmp_state.joinpath(file).write_text(state_string)
|
||||
tmp_state.joinpath(file).write_text(STATE_STRING)
|
||||
config_changed, state_changed = copy_bare_configs(xdg_paths.config, xdg_paths.resolution)
|
||||
|
||||
tmp_state_file = tmp_state / "dzg.res.json"
|
||||
config_changed, state_changed = copy_bare_configs(tmp_conf_file, tmp_state_file)
|
||||
|
||||
assert (tmp_conf / "dzgui/config.json").read_text() == conf_string
|
||||
assert (tmp_conf / xdg_paths.config.name).read_text() == CONF_STRING
|
||||
for file in state_files:
|
||||
assert (tmp_state / "dzgui" / file).read_text() == state_string
|
||||
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(state_files):
|
||||
conf_string = "DZGUI_CONF\n"
|
||||
state_string = "DZGUI_STATE\n"
|
||||
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
tmp2 = tempfile.TemporaryDirectory()
|
||||
tmp_conf = Path(tmp.name)
|
||||
tmp_state = Path(tmp2.name)
|
||||
|
||||
for d in tmp_conf, tmp_state:
|
||||
subdir = d / "dzgui"
|
||||
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 = tmp_conf / "dzgui/config.json"
|
||||
tmp_conf_file.write_text(conf_string)
|
||||
tmp_conf_file = xdg_paths.config
|
||||
tmp_conf_file.write_text(CONF_STRING)
|
||||
|
||||
tmp_state_file = xdg_paths.resolution
|
||||
|
||||
for file in state_files:
|
||||
tmp_state.joinpath("dzgui").joinpath(file).write_text(state_string)
|
||||
tmp_state_file = tmp_state / "dzgui/dzg.res.json"
|
||||
config_changed, state_changed = copy_bare_configs(tmp_conf_file, tmp_state_file)
|
||||
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
|
||||
Reference in new issue
Block a user