mirror of
https://github.com/aclist/dztui.git
synced 2026-08-25 17:32:36 +02:00
chore: add test for no import case
This commit is contained in:
parent
61f90d6016
commit
4c31cd7ecd
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user