-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathtest_file.py
33 lines (27 loc) · 992 Bytes
/
test_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pytest
from blendtorch.btt.file import FileRecorder, FileReader
@pytest.mark.background
def test_file_recorder_reader(tmp_path):
with FileRecorder(outpath=tmp_path / "record.mpkl", max_messages=10) as rec:
for i in range(7):
rec.save({"value": i}, is_pickled=False)
r = FileReader(tmp_path / "record.mpkl")
assert len(r) == 7
for i in range(7):
assert r[i]["value"] == i
@pytest.mark.background
def test_file_recorder_reader_exception(tmp_path):
try:
with FileRecorder(
outpath=tmp_path / "record.mpkl", max_messages=10, update_header=1
) as rec:
rec.save({"value": 0}, is_pickled=False)
rec.save({"value": 1}, is_pickled=False)
rec.save({"value": 2}, is_pickled=False)
raise ValueError("err")
except ValueError:
pass
r = FileReader(tmp_path / "record.mpkl")
assert len(r) == 3
for i in range(3):
assert r[i]["value"] == i