2020-01-17 10:28:44 -08:00
|
|
|
import os
|
|
|
|
|
from uuid import uuid4
|
|
|
|
|
|
2023-08-20 20:49:55 -07:00
|
|
|
from openpilot.common.file_helpers import atomic_write_in_dir
|
2020-01-17 10:28:44 -08:00
|
|
|
|
|
|
|
|
|
2024-05-17 11:01:44 -07:00
|
|
|
class TestFileHelpers:
|
2020-01-17 10:28:44 -08:00
|
|
|
def run_atomic_write_func(self, atomic_write_func):
|
2021-12-16 14:58:17 +01:00
|
|
|
path = f"/tmp/tmp{uuid4()}"
|
2020-01-17 10:28:44 -08:00
|
|
|
with atomic_write_func(path) as f:
|
|
|
|
|
f.write("test")
|
2023-12-16 22:19:50 -08:00
|
|
|
assert not os.path.exists(path)
|
2020-01-17 10:28:44 -08:00
|
|
|
|
|
|
|
|
with open(path) as f:
|
2024-05-17 11:01:44 -07:00
|
|
|
assert f.read() == "test"
|
2020-01-17 10:28:44 -08:00
|
|
|
os.remove(path)
|
|
|
|
|
|
|
|
|
|
def test_atomic_write_in_dir(self):
|
|
|
|
|
self.run_atomic_write_func(atomic_write_in_dir)
|