test_dotfiles_state_migration.pyPython44 lines1.8 KiBraw download
"""The one-time carry of app state from the old dotfiles checkout into dotfiles/."""
from pathlib import Path
import subprocess
import tempfile
import unittest
SCRIPT = Path(__file__).resolve().parents[1] / "modules/home/_activation/migrate-dotfiles-state.sh"
class DotfilesStateMigrationTest(unittest.TestCase):
def run_migration(self, old, new):
subprocess.run(["bash", str(SCRIPT), str(old), str(new)], check=True, capture_output=True)
def test_copies_once_without_overwriting_or_locks(self):
with tempfile.TemporaryDirectory() as tmp:
old, new = Path(tmp, "old"), Path(tmp, "new")
vesktop = old / "home/.config/vesktop"
(vesktop / "sessionData").mkdir(parents=True)
(vesktop / "sessionData/Cookies").write_text("session")
(vesktop / "settings.json").write_text("old")
(vesktop / "SingletonLock").write_text("")
(old / "home/.config/jj/repos/abc").mkdir(parents=True)
(new / "home/.config/vesktop").mkdir(parents=True)
(new / "home/.config/vesktop/settings.json").write_text("new")
self.run_migration(old, new)
self.run_migration(old, new)
nv = new / "home/.config/vesktop"
self.assertEqual((nv / "sessionData/Cookies").read_text(), "session")
self.assertEqual((nv / "settings.json").read_text(), "new")
self.assertFalse((nv / "SingletonLock").exists())
self.assertTrue((new / "home/.config/jj/repos/abc").is_dir())
def test_no_old_checkout_is_a_no_op(self):
with tempfile.TemporaryDirectory() as tmp:
new = Path(tmp, "new/home")
new.mkdir(parents=True)
self.run_migration(Path(tmp, "gone"), new.parent)
self.assertEqual(list(new.iterdir()), [])
if __name__ == "__main__":
unittest.main()