24 lines
984 B
Python
24 lines
984 B
Python
"""配置缓存必须保留热更新和调用者之间的数据隔离。"""
|
|
from pathlib import Path
|
|
from tempfile import TemporaryDirectory
|
|
from unittest import TestCase
|
|
from unittest.mock import patch
|
|
|
|
from station import site_catalog as console
|
|
|
|
|
|
class SiteConfigTest(TestCase):
|
|
def test_edit_and_delete_config(self):
|
|
with TemporaryDirectory() as folder, patch.object(console, "ROOT", Path(folder)):
|
|
path = Path(folder) / "config" / "site.yaml"
|
|
path.parent.mkdir()
|
|
self.assertEqual(console._site(), {})
|
|
path.write_text("robot:\n sn: original\n")
|
|
first = console._site()
|
|
first["robot"]["sn"] = "local change"
|
|
self.assertEqual(console._site()["robot"]["sn"], "original")
|
|
path.write_text("robot:\n sn: updated-robot\n")
|
|
self.assertEqual(console._site()["robot"]["sn"], "updated-robot")
|
|
path.unlink()
|
|
self.assertEqual(console._site(), {})
|