Пример #1
0
def test_writing_one_int(monkeypatch):
    monkeypatch.setattr(uuid, 'uuid4', FakeUUID)
    buf = BytesIO()
    sch = cavro.Schema('"int"')
    writer = cavro.ContainerWriter(buf, sch)
    writer.write_one(1)
    writer.close()
    assert buf.getvalue() == FakeUUID.HEADER + b'\x02\x02\x02' + FakeUUID.bytes
Пример #2
0
def test_writing_empty_no_close(monkeypatch):
    monkeypatch.setattr(uuid, 'uuid4', FakeUUID)
    buf = BytesIO()
    sch = cavro.Schema('"int"')
    writer = cavro.ContainerWriter(buf, sch)
    del writer
    assert buf.getvalue(
    ) == b'Obj\x01\x04\x16avro.schema\n"int"\x14avro.codec\x08null\x00abcdefghijklmnop\x00\x00abcdefghijklmnop'
Пример #3
0
def test_cannot_write_after_close():
    buf = BytesIO()
    sch = cavro.Schema('"int"')
    writer = cavro.ContainerWriter(buf, sch)
    writer.write_one(1)
    writer.close()
    with pytest.raises(ValueError):
        writer.write_one(2)
Пример #4
0
def test_writing_two_ints_context(monkeypatch):
    monkeypatch.setattr(uuid, 'uuid4', FakeUUID)
    buf = BytesIO()
    sch = cavro.Schema('"int"')
    with cavro.ContainerWriter(buf, sch) as writer:
        writer.write_one(64)
        writer.write_one(1)
    assert buf.getvalue(
    ) == FakeUUID.HEADER + b'\x04\x06\x80\x01\x02' + FakeUUID.bytes
Пример #5
0
def test_round_tripping(source_vals, schema):
    for codec in ['null', 'deflate', 'snappy']:
        buf = BytesIO()
        sch = cavro.Schema(schema)
        with cavro.ContainerWriter(buf, sch, codec) as writer:
            writer.write_many(source_vals)
        buf.seek(0)
        reader = cavro.ContainerReader(buf)
        obs = list(reader)
        assert obs == source_vals
Пример #6
0
def test_writing_two_blocks_of_ints(monkeypatch):
    monkeypatch.setattr(uuid, 'uuid4', FakeUUID)
    buf = BytesIO()
    sch = cavro.Schema('"int"')
    writer = cavro.ContainerWriter(buf, sch, max_blocksize=1)
    writer.write_one(64)
    assert buf.getvalue() == FakeUUID.HEADER
    writer.write_one(1)
    assert buf.getvalue(
    ) == FakeUUID.HEADER + b'\x02\x04\x80\x01' + FakeUUID.bytes
    writer.close()
    assert buf.getvalue(
    ) == FakeUUID.HEADER + b'\x02\x04\x80\x01' + FakeUUID.bytes + b'\x02\x02\x02' + FakeUUID.bytes
Пример #7
0
def main(count):
    if count < 0:
        counter = itertools.count()
    else:
        counter = range(count)
    for it in tqdm.tqdm(counter):
        try:
            tmp = io.BytesIO()
            sch_json = schema.make_schema_json(5)
            sch = cavro.Schema(sch_json)

            vals = [
                values.make_value_for_type(sch.type, 5)
                for _ in range(randint(0, 2000))
            ]
            with cavro.ContainerWriter(tmp, sch) as writer:
                writer.write_many(vals)

            tmp.seek(0)
            reader = cavro.ContainerReader(tmp)
            decoded = [values.de_record(v) for v in reader]
            expected = [values.de_record(v) for v in vals]

            info = []
            equal = values.almost_equal(decoded, expected, info)

            if not equal:
                print("----------- SCHEMA -------------")
                print(sch_json)
                # print("\n----------- VALUE ---------------")
                # print(value)
                # print("\n----------- DECODED ---------------")
                # print(decoded)
                # print("\n----------- DECODED DATA ---------------")
                # print(de_recorded)
                print("\n----------- INFO ---------------")
                print(info)
                return
        except:
            print(tmp.getvalue())
            raise