From 4c31cd7ecd53aef9893de01a4c11dedd7bc35cef Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Sun, 28 Jun 2026 00:07:51 +0900 Subject: [PATCH] chore: add test for no import case --- dzgui/app_init.py | 13 ++++++---- tests/test_bare_conf_files.py | 45 +++++++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/dzgui/app_init.py b/dzgui/app_init.py index 2535f0e..3bd1f0d 100644 --- a/dzgui/app_init.py +++ b/dzgui/app_init.py @@ -51,8 +51,7 @@ def setup_logger(log_path: "Path") -> None: logger.addHandler(fh) - -def copy_bare_configs(config: "Path", resolution: "Path") -> None: +def copy_bare_configs(config: "Path", resolution: "Path") -> tuple[bool, bool]: # NOTE: temporary workaround for #375 conf = "config.json" state = [ @@ -63,13 +62,16 @@ def copy_bare_configs(config: "Path", resolution: "Path") -> None: "dzg.columns.json", "dzg.notes.json", "ips.csv", - ".month" + ".month", ] + config_changed = False + state_changed = False if APP_NAME_LOWER not in str(config): new_file = config.parent / APP_NAME_LOWER / conf - make_parents(new_file) if config.is_file(): + make_parents(new_file) shutil.copy(config, new_file) + config_changed = True if APP_NAME_LOWER not in str(resolution): state_path = resolution.parent for state_file in state: @@ -78,6 +80,9 @@ def copy_bare_configs(config: "Path", resolution: "Path") -> None: new_file = state_path / APP_NAME_LOWER / state_file make_parents(new_file) shutil.copy(old_file, new_file) + state_changed = True + return (config_changed, state_changed) + def load_gui(version: str, is_debug: bool) -> None: lock = lock_acquire() # noqa diff --git a/tests/test_bare_conf_files.py b/tests/test_bare_conf_files.py index 4dffa6b..1eb58a6 100644 --- a/tests/test_bare_conf_files.py +++ b/tests/test_bare_conf_files.py @@ -4,10 +4,8 @@ import tempfile from dzgui.app_init import copy_bare_configs from pathlib import Path -@pytest.mark.mods -def test_bare_file_import(): - conf_string = "DZGUI_CONF\n" - state_string = "DZGUI_STATE\n" +@pytest.fixture +def state_files(): state = [ "dzg.history", "dzg.versions", @@ -18,6 +16,12 @@ def test_bare_file_import(): "ips.csv", ".month" ] + return state + +@pytest.mark.mods +def test_config_file_import(state_files): + conf_string = "DZGUI_CONF\n" + state_string = "DZGUI_STATE\n" tmp = tempfile.TemporaryDirectory() tmp2 = tempfile.TemporaryDirectory() @@ -26,12 +30,39 @@ def test_bare_file_import(): tmp_conf_file = tmp_conf / "config.json" tmp_conf_file.write_text(conf_string) - for file in state: + for file in state_files: tmp_state.joinpath(file).write_text(state_string) tmp_state_file = tmp_state / "dzg.res.json" - copy_bare_configs(tmp_conf_file, tmp_state_file) + config_changed, state_changed = copy_bare_configs(tmp_conf_file, tmp_state_file) assert (tmp_conf / "dzgui/config.json").read_text() == conf_string - for file in state: + for file in state_files: assert (tmp_state / "dzgui" / 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" + subdir.mkdir() + + tmp_conf_file = tmp_conf / "dzgui/config.json" + tmp_conf_file.write_text(conf_string) + + 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) + assert config_changed is False + assert state_changed is False