Beispiel #1
0
def test_json_save_load_roundtrip(extension):
    data = {'some': ['data']}
    with NamedTemporaryFile() as f:
        path = Path(f.name).with_suffix(extension)
        save_to_json(data, path)
        f.flush()
        data_deserialized = load_json(path)
    assert data == data_deserialized
Beispiel #2
0
def load_manifest(path: Pathlike) -> Manifest:
    """Generic utility for reading an arbitrary manifest."""
    try:
        raw_data = load_json(path)
    except JSONDecodeError:
        try:
            raw_data = load_yaml(path)
        except:
            raise ValueError(f"Not a valid manifest: {path}")
    data_set = None
    for manifest_type in [RecordingSet, SupervisionSet, FeatureSet, CutSet]:
        try:
            data_set = manifest_type.from_dicts(raw_data)
        except Exception:
            pass
    if data_set is None:
        raise ValueError(f'Unknown type of manifest: {path}')
    return data_set