19 lines
624 B
Python
19 lines
624 B
Python
import json
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from common_util.common_util_json import atomic_write_json
|
|
|
|
|
|
class AtomicWriteJsonTest(unittest.TestCase):
|
|
def test_atomic_write_json(self) -> None:
|
|
with tempfile.TemporaryDirectory() as temporary_directory:
|
|
target = Path(temporary_directory) / "nested" / "result.json"
|
|
value = {"status": "완료", "items": [1, 2, 3]}
|
|
|
|
atomic_write_json(target, value)
|
|
|
|
self.assertEqual(json.loads(target.read_text(encoding="utf-8")), value)
|
|
self.assertEqual(list(target.parent.glob("*.tmp")), [])
|