Ejemplo n.º 1
0
def test_serialize_deserialize_record_pack(ident_testcase, nrecords):
    from hangar.remote.chunks import serialize_record
    from hangar.remote.chunks import serialize_record_pack
    from hangar.remote.chunks import deserialize_record
    from hangar.remote.chunks import deserialize_record_pack
    from hangar.remote.chunks import ArrayRecord

    idx = 0
    ArrList, RecList = [], []
    digest, schema = ident_testcase
    for shape in param_shapes:
        for dtype in param_dtypes:
            arr = 200 * np.random.random_sample(shape) + 100
            arr = arr.astype(dtype)
            digest = f'digest{str(idx)*len(digest)}'
            schema = f'schema{str(idx)*len(schema)}'
            idx += 1

            ArrList.append((arr, digest, schema))
            RecList.append(serialize_record(arr, digest, schema))

    rawpack = serialize_record_pack(RecList)
    reslist = deserialize_record_pack(rawpack)

    assert reslist == RecList

    for rawres, origRec in zip(reslist, ArrList):
        resRec = deserialize_record(rawres)
        assert isinstance(resRec, ArrayRecord)
        assert_equal(resRec.array, origRec[0])
        assert resRec.digest == origRec[1]
        assert resRec.schema == origRec[2]
Ejemplo n.º 2
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]