Some checks failed
Desktop Dev Pre-release / prerelease (push) Failing after 2m18s
- added retry-based file copy, rollback restart, and version marker validation in updater GUI - added build step to write dist/version.txt for post-update validation - added unit tests for updater helpers
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
import importlib.util
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
MODULE_PATH = Path("updater_gui.py")
|
|
SPEC = importlib.util.spec_from_file_location("updater_gui_under_test", MODULE_PATH)
|
|
updater_gui = importlib.util.module_from_spec(SPEC)
|
|
SPEC.loader.exec_module(updater_gui)
|
|
|
|
|
|
class UpdaterGuiTests(unittest.TestCase):
|
|
def test_read_version_marker(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
marker = Path(tmp_dir) / "version.txt"
|
|
marker.write_text("2.0.1\n", encoding="utf-8")
|
|
value = updater_gui._read_version_marker(tmp_dir)
|
|
self.assertEqual(value, "2.0.1")
|
|
|
|
def test_mirror_tree_skips_selected_file(self):
|
|
with tempfile.TemporaryDirectory() as src_tmp, tempfile.TemporaryDirectory() as dst_tmp:
|
|
src = Path(src_tmp)
|
|
dst = Path(dst_tmp)
|
|
(src / "keep.txt").write_text("ok", encoding="utf-8")
|
|
(src / "skip.bin").write_text("x", encoding="utf-8")
|
|
(src / "sub").mkdir()
|
|
(src / "sub" / "nested.txt").write_text("nested", encoding="utf-8")
|
|
|
|
updater_gui._mirror_tree(str(src), str(dst), skip_names={"skip.bin"})
|
|
|
|
self.assertTrue((dst / "keep.txt").exists())
|
|
self.assertTrue((dst / "sub" / "nested.txt").exists())
|
|
self.assertFalse((dst / "skip.bin").exists())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|