Files
beeos/tests/test_runtime_storage.py
T

34 lines
1.1 KiB
Python

import json
import tempfile
import unittest
from pathlib import Path
from beeos.core.runtime_api import BeeStorageAPI
class BeeStorageAPITests(unittest.TestCase):
def test_set_persists_json_and_leaves_no_temporary_file(self):
with tempfile.TemporaryDirectory() as temp_dir:
storage_file = Path(temp_dir) / "storage.json"
storage = BeeStorageAPI(storage_file)
storage.set("launches", 3)
self.assertEqual(storage.get("launches"), 3)
self.assertEqual(json.loads(storage_file.read_text(encoding="utf-8")), {"launches": 3})
self.assertFalse(storage_file.with_name("storage.json.tmp").exists())
def test_delete_removes_key_without_corrupting_other_values(self):
with tempfile.TemporaryDirectory() as temp_dir:
storage = BeeStorageAPI(Path(temp_dir) / "storage.json")
storage.set("launches", 3)
storage.set("theme", "yellow")
storage.delete("launches")
self.assertEqual(storage.all(), {"theme": "yellow"})
if __name__ == "__main__":
unittest.main()