Esempio n. 1
0
def test_serialize_deserialize_ident_only_schema_only_record_pack(ident_testcase, nrecords):
    from hangar.remote.chunks import serialize_ident
    from hangar.remote.chunks import deserialize_ident
    from hangar.remote.chunks import serialize_record_pack
    from hangar.remote.chunks import deserialize_record_pack
    from hangar.remote.chunks import ArrayIdent

    idx = 0
    IdentList, RawList = [], []
    digest, schema = ident_testcase
    for idx in range(nrecords):
        digest = f''
        schema = f'schema{str(idx)*len(schema)}'

        IdentList.append((digest, schema))
        RawList.append(serialize_ident(digest, schema))

    packed_raw = serialize_record_pack(RawList)
    unpacked_raw = deserialize_record_pack(packed_raw)

    assert unpacked_raw == RawList

    for raw, origIdent in zip(unpacked_raw, IdentList):
        resIdent = deserialize_ident(raw)
        assert isinstance(resIdent, ArrayIdent)
        assert resIdent.digest == origIdent[0]
        assert resIdent.schema == origIdent[1]
Esempio n. 2
0
def test_serialize_deserialize_ident(ident_testcase):
    from hangar.remote.chunks import serialize_ident
    from hangar.remote.chunks import deserialize_ident
    from hangar.remote.chunks import ArrayIdent

    digest, schema = ident_testcase
    raw = serialize_ident(digest, schema)
    res = deserialize_ident(raw)
    assert isinstance(res, ArrayIdent)
    assert res.digest == digest
    assert res.schema == schema
def test_serialize_deserialize_ident_schema_field_only(ident_testcase):
    from hangar.remote.chunks import serialize_ident
    from hangar.remote.chunks import deserialize_ident
    from hangar.remote.chunks import DataIdent

    digest, schema = ident_testcase
    raw = serialize_ident('', schema)
    res = deserialize_ident(raw)
    assert isinstance(res, DataIdent)
    assert res.digest == ''
    assert res.schema == schema