Skip to content

Commit 086fade

Browse files
committed
+ Add tests for file buffer
1 parent d60a931 commit 086fade

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/buffer/file_test.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
3+
from tests.tools import RayUnittestBase
4+
from trinity.buffer.reader.file_reader import RawDataReader
5+
from trinity.buffer.writer.file_writer import RawFileWriter
6+
from trinity.common.config import StorageConfig
7+
from trinity.common.constants import StorageType
8+
9+
10+
class TestFileBuffer(RayUnittestBase):
11+
12+
temp_output_path = 'tmp/test_file_buffer/'
13+
14+
@classmethod
15+
def setUpClass(cls):
16+
os.makedirs(cls.temp_output_path, exist_ok=True)
17+
18+
@classmethod
19+
def tearDownClass(cls):
20+
super().tearDownClass()
21+
if os.path.exists(cls.temp_output_path):
22+
os.system(f'rm -rf {cls.temp_output_path}')
23+
24+
def test_file_buffer(self):
25+
meta = StorageConfig(
26+
name="test_buffer",
27+
path=os.path.join(self.temp_output_path, "buffer.jsonl"),
28+
storage_type=StorageType.FILE,
29+
raw=True,
30+
)
31+
data = [
32+
{'key1': 1, 'key2': 2},
33+
{'key1': 3, 'key2': 4},
34+
{'key1': 5, 'key2': 6},
35+
{'key1': 7, 'key2': 8},
36+
]
37+
38+
# test writer
39+
writer = RawFileWriter(meta, None)
40+
writer.write(data)
41+
writer.finish()
42+
43+
# test reader
44+
meta.path = self.temp_output_path
45+
reader = RawDataReader(meta, None)
46+
loaded_data = reader.read()
47+
self.assertEqual(len(loaded_data), 4)
48+
self.assertEqual(loaded_data, data)
49+
self.assertRaises(StopIteration, reader.read)

0 commit comments

Comments
 (0)