43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
|
|
from ptlinux.paths import AppPaths
|
|
from ptlinux.settings import Settings, load_settings, save_settings
|
|
|
|
|
|
class ChannelSettingsTests(unittest.TestCase):
|
|
def test_existing_users_default_to_stable(self) -> None:
|
|
with tempfile.TemporaryDirectory() as temporary:
|
|
root = Path(temporary)
|
|
paths = AppPaths(root / "data", root / "config", root / "state", root / "cache")
|
|
paths.config.mkdir(parents=True)
|
|
paths.settings_file.write_text('{"realm": "Babel"}\n', encoding="utf-8")
|
|
|
|
self.assertEqual(load_settings(paths).update_channel, "stable")
|
|
|
|
def test_prerelease_preference_round_trips(self) -> None:
|
|
with tempfile.TemporaryDirectory() as temporary:
|
|
root = Path(temporary)
|
|
paths = AppPaths(root / "data", root / "config", root / "state", root / "cache")
|
|
|
|
save_settings(paths, Settings(update_channel="prerelease"))
|
|
|
|
self.assertEqual(load_settings(paths).update_channel, "prerelease")
|
|
|
|
def test_unknown_channel_is_rejected(self) -> None:
|
|
with tempfile.TemporaryDirectory() as temporary:
|
|
root = Path(temporary)
|
|
paths = AppPaths(root / "data", root / "config", root / "state", root / "cache")
|
|
paths.config.mkdir(parents=True)
|
|
paths.settings_file.write_text('{"update_channel": "nightly"}\n', encoding="utf-8")
|
|
|
|
with self.assertRaisesRegex(ValueError, "update channel"):
|
|
load_settings(paths)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|