Пример #1
0
def test_metadata_dict(make_random_metadata_dict):
    random_metadata_dict = make_random_metadata_dict()
    items = sorted(random_metadata_dict.items())
    metadata = Metadata(**OrderedDict(items))

    for (k_it, v_it), k_md in zip(items, metadata.keys()):
        assert k_md == k_it

    for (k_it, v_it), v_md in zip(items, metadata.values()):
        assert v_md == v_it

    for (k_it, v_it), (k_md, v_md) in zip(items, metadata.items()):
        assert k_md == k_it
        assert v_md == v_it
Пример #2
0
def test_metadata_eq(make_random_metadata_dict):
    items = sorted(make_random_metadata_dict().items())
    md1 = Metadata(**OrderedDict(items))
    md2 = Metadata(**OrderedDict(items))
    assert md1 == md2

    items1 = sorted(make_random_metadata_dict().items())
    items2 = sorted(make_random_metadata_dict().items())
    while items1 == items2:
        items2 = sorted(make_random_metadata_dict().items())

    md1 = Metadata(**OrderedDict(items1))
    md2 = Metadata(**OrderedDict(items2))
    assert md1 != md2
Пример #3
0
    class TestDataset(Dataset):
        feat1 = Feature(shape=(1, 2, 3), dtype=int)
        feat2 = Feature(shape=None,
                        dtype=str,
                        metadata=Metadata(abc=123, xyz=False, pi=3.14))

        class DefaultMetadata:
            attr1 = "val1"
            attr2 = "val2"
Пример #4
0
def test_dataset_subclass():
    class TestDataset(Dataset):
        feat1 = Feature(shape=(1, 2, 3), dtype=int)
        feat2 = Feature(shape=None,
                        dtype=str,
                        metadata=Metadata(abc=123, xyz=False, pi=3.14))

        class DefaultMetadata:
            attr1 = "val1"
            attr2 = "val2"

    assert TestDataset.features["feat1"] == Feature(shape=(1, 2, 3), dtype=int)
    assert TestDataset.features["feat2"] == Feature(shape=None,
                                                    dtype=str,
                                                    metadata=Metadata(
                                                        abc=123,
                                                        xyz=False,
                                                        pi=3.14))

    assert TestDataset.metadata["attr1"] == "val1"
    assert TestDataset.metadata["attr2"] == "val2"
Пример #5
0
 def __make_random_metadata_object():
     random_metadata_dict = make_random_metadata_dict()
     return Metadata(**random_metadata_dict)
Пример #6
0
    class DatasetB(DatasetY, DatasetZ):
        feature = Feature(shape=None, dtype=int, metadata=Metadata(source="B"))

        class DefaultMetadata:
            source = "B"
Пример #7
0
    class DatasetX(Dataset):
        feature = Feature(shape=None, dtype=int, metadata=Metadata(source="X"))

        class DefaultMetadata:
            source = "X"
Пример #8
0
def test_metadata_serialize_deserialize(make_random_metadata_object):
    random_metadata_object = make_random_metadata_object()
    deserialized_metadata = Metadata.deserialize(random_metadata_object.serialize())
    assert deserialized_metadata == random_metadata_object
Пример #9
0
def test_metadata(make_random_metadata_dict):
    random_metadata_dict = make_random_metadata_dict()
    metadata = Metadata(**random_metadata_dict)
    for k, v in random_metadata_dict.items():
        assert metadata[k] == v
Пример #10
0
def test_metadata_contains(make_random_metadata_dict):
    random_metadata_dict = make_random_metadata_dict()
    metadata = Metadata(**random_metadata_dict)
    for k in random_metadata_dict:
        assert k in metadata
        assert (k + "abc") not in metadata
Пример #11
0
def test_metadata_iter(make_random_metadata_dict):
    random_metadata_dict = make_random_metadata_dict()
    metadata = Metadata(**random_metadata_dict)
    for k in metadata:
        assert k in random_metadata_dict
Пример #12
0
def test_metadata_len(make_random_metadata_dict):
    random_metadata_dict = make_random_metadata_dict()
    metadata = Metadata(**random_metadata_dict)
    assert len(metadata) == len(random_metadata_dict)
Пример #13
0
def test_metadata_empty():
    metadata = Metadata()
    assert len(metadata) == 0
    assert metadata.serialize() == "[]"