Example #1
0
def test_hierarchical_dataset_invalid_json_fail(hierarchical_dataset_fields):
    with pytest.raises(JSONDecodeError):
        HierarchicalDataset.from_json(
            INVALID_JSON,
            hierarchical_dataset_fields,
            HierarchicalDataset.get_default_dict_parser("children"),
        )
Example #2
0
def test_hierarchical_dataset_json_root_element_not_list_fail(
    hierarchical_dataset_fields, ):
    with pytest.raises(ValueError):
        HierarchicalDataset.from_json(
            JSON_ROOT_NOT_LIST,
            hierarchical_dataset_fields,
            HierarchicalDataset.get_default_dict_parser("children"),
        )
Example #3
0
def hierarchical_dataset_2(hierarchical_dataset_fields, hierarchical_dataset_parser):
    dataset = HierarchicalDataset.from_json(
        HIERARCHIAL_DATASET_JSON_EXAMPLE_2,
        hierarchical_dataset_fields,
        hierarchical_dataset_parser,
    )
    return dataset
Example #4
0
def hierarchical_dataset(hierarchical_dataset_fields,
                         hierarchical_dataset_parser):
    return HierarchicalDataset.from_json(
        dataset=HIERARCHIAL_DATASET_JSON_EXAMPLE,
        fields=hierarchical_dataset_fields,
        parser=hierarchical_dataset_parser,
    )
Example #5
0
def hierarchical_dataset(hierarchical_dataset_fields, hierarchical_dataset_parser):
    dataset = HierarchicalDataset.from_json(
        HIERARCHIAL_DATASET_JSON_EXAMPLE,
        hierarchical_dataset_fields,
        hierarchical_dataset_parser,
    )
    dataset.finalize_fields()
    return dataset
Example #6
0
def test_hierarchical_dataset_finalize_fields(hierarchical_dataset_parser):
    name_vocab = Vocab()
    number_vocab = Vocab()
    name_field = Field("name",
                       keep_raw=True,
                       tokenizer=None,
                       numericalizer=name_vocab)
    number_field = Field("number",
                         keep_raw=True,
                         tokenizer=None,
                         numericalizer=number_vocab)

    fields = {"name": name_field, "number": number_field}
    dataset = HierarchicalDataset.from_json(
        dataset=HIERARCHIAL_DATASET_JSON_EXAMPLE,
        fields=fields,
        parser=hierarchical_dataset_parser,
    )
    dataset.finalize_fields()
    assert name_vocab.is_finalized
    assert number_vocab.is_finalized