mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-15 22:32:11 +08:00
4012d181e1
date: 2024-03-17T10:14:38 master commit: 7e9a909e0e57ecb31df4c87c5b9a06b1204fd034
25 lines
567 B
Python
25 lines
567 B
Python
import os
|
|
import unittest
|
|
from uuid import uuid4
|
|
|
|
from openpilot.common.file_helpers import atomic_write_in_dir
|
|
|
|
|
|
class TestFileHelpers(unittest.TestCase):
|
|
def run_atomic_write_func(self, atomic_write_func):
|
|
path = f"/tmp/tmp{uuid4()}"
|
|
with atomic_write_func(path) as f:
|
|
f.write("test")
|
|
assert not os.path.exists(path)
|
|
|
|
with open(path) as f:
|
|
self.assertEqual(f.read(), "test")
|
|
os.remove(path)
|
|
|
|
def test_atomic_write_in_dir(self):
|
|
self.run_atomic_write_func(atomic_write_in_dir)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|