-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_avro_adapter.py
51 lines (37 loc) · 1.44 KB
/
test_avro_adapter.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from flow.record import RecordReader, RecordWriter
from ._utils import generate_plain_records
def test_avro_adapter(tmpdir):
json_file = tmpdir.join("records.avro")
record_adapter_path = "avro://{}".format(json_file)
writer = RecordWriter(record_adapter_path)
nr_records = 1337
for record in generate_plain_records(nr_records):
writer.write(record)
writer.flush()
nr_received_records = 0
reader = RecordReader(record_adapter_path)
for _ in reader:
nr_received_records += 1
assert nr_records == nr_received_records
def test_avro_adapter_contextmanager(tmpdir):
json_file = tmpdir.join("records.avro")
record_adapter_path = "avro://{}".format(json_file)
with RecordWriter(record_adapter_path) as writer:
nr_records = 1337
for record in generate_plain_records(nr_records):
writer.write(record)
nr_received_records = 0
with RecordReader(record_adapter_path) as reader:
for _ in reader:
nr_received_records += 1
assert nr_records == nr_received_records
def test_avro_adapter_empty(tmpdir):
json_file = tmpdir.join("records.avro")
record_adapter_path = "avro://{}".format(json_file)
with RecordWriter(record_adapter_path):
pass
nr_received_records = 0
with RecordReader(record_adapter_path) as reader:
for _ in reader:
nr_received_records += 1
assert nr_received_records == 0