def test_factory_method_implemented(node_class):
    """
    Confirm that a subclass of TaggedObjectNode has a factory method
    available.
    """
    instance = create_node(node_class)
    assert isinstance(instance, node_class)
def test_instance_valid(node_class):
    """
    Confirm that a class's factory method creates an object that
    is valid against its schema.
    """
    with asdf.AsdfFile() as af:
        af["node"] = create_node(node_class)
        af.validate()
Esempio n. 3
0
def test_serialization(node_class, tmp_path):
    file_path = tmp_path / "test.asdf"

    node = create_node(node_class)
    with asdf.AsdfFile() as af:
        af["node"] = node
        af.write_to(file_path)

    with asdf.open(file_path) as af:
        assert_node_equal(af["node"], node)
def test_no_extra_fields(node_class, manifest):
    instance = create_node(node_class)
    instance_keys = set(instance.keys())

    schema_uri = next(t["schema_uri"] for t in manifest["tags"] if t["tag_uri"] == instance.tag)
    schema = asdf.schema.load_schema(schema_uri, resolve_references=True)

    schema_keys = set()
    subschemas = [schema]
    if "allOf" in schema:
        subschemas.extend(schema["allOf"])
    for subschema in subschemas:
        schema_keys.update(subschema.get("properties", {}).keys())

    diff = instance_keys - schema_keys
    assert len(diff) == 0, "Factory instance has extra keys: " + ", ".join(diff)