Beispiel #1
0
def test_markdown_with_dollar_sign(root_context: LDContext):
    """Update Octiron graph from a Markdown file with a $context."""
    data_dir = Path(__file__).parent / 'data'

    octiron = Octiron(
        root_directory=data_dir,
        root_context=root_context,
    )

    octiron.update_from_file(
        path=data_dir / 'test_dollar_id.md',
        local_iri=LOCAL_IRI,
    )

    assert set(octiron.graph.quads()).issuperset({
        (
            LOCAL_IRI,
            RDFS.label,
            Literal('Hey, I am a test!'),
            Graph(identifier=LOCAL_IRI),
        ),
        (
            LOCAL_IRI,
            RDFS.domain,
            LOCAL.UnitTesting,
            Graph(identifier=LOCAL_IRI),
        ),
        (
            LOCAL_IRI,
            RDF.type,
            OCTA.Page,
            Graph(identifier=LOCAL_IRI),
        ),
    })
Beispiel #2
0
def test_clear_named_graph(root_context: LDContext):
    """Update Octiron graph from a YAML file."""
    data_dir = Path(__file__).parent / 'data'

    octiron = Octiron(
        root_directory=data_dir,
        root_context=root_context,
    )

    octiron.update_from_file(
        path=data_dir / 'test.yaml',
        local_iri=LOCAL_IRI,
    )

    assert set(octiron.graph) == {
        (BNode(f'{LOCAL_IRI}/b0'), RDF.subject, Literal('s')),
        (BNode(f'{LOCAL_IRI}/b1'), RDF.predicate, Literal('p')),
        (BNode(f'{LOCAL_IRI}/b2'), RDF.object, Literal('o')),
        (LOCAL_IRI, LOCAL.given, Literal('spo')),
        (LOCAL_IRI, LOCAL.infer, BNode(f'{LOCAL_IRI}/b0')),
        (LOCAL_IRI, LOCAL.infer, BNode(f'{LOCAL_IRI}/b1')),
        (LOCAL_IRI, LOCAL.infer, BNode(f'{LOCAL_IRI}/b2')),
        (URIRef(LOCAL), RDF.type, OCTA.Directory),
        (LOCAL_IRI, OCTA.isChildOf, URIRef(LOCAL)),
        (LOCAL_IRI, OCTA.fileName, Literal('test.yaml')),
        (LOCAL_IRI, OCTA.subjectOf, LOCAL_IRI),
    }

    octiron.clear_named_graph(local_iri=LOCAL_IRI, )

    assert (LOCAL_IRI, LOCAL.given, Literal('spo')) not in set(octiron.graph)
Beispiel #3
0
def test_yaml_list(root_context: LDContext):
    """Update Octiron graph from a YAML file."""
    data_dir = Path(__file__).parent / 'data'

    octiron = Octiron(
        root_directory=data_dir,
        root_context=root_context,
    )

    octiron.update_from_file(
        path=data_dir / 'test_yaml/list.yaml',
        local_iri=LOCAL_IRI,
    )

    assert (
        URIRef(RDF),
        LOCAL.prefix,
        Literal('rdf'),
    ) in octiron.graph

    triples = set(octiron.graph.triples((None, RDFS.label, None)))
    assert triples == {
        (BNode('local:test.yaml/b0'), RDFS.label, Literal('boo')),
        (BNode('local:test.yaml/b1'), RDFS.label, Literal('foo')),
    }
Beispiel #4
0
def test_yaml_with_context(root_context: LDContext):
    """Update Octiron graph from a YAML file."""
    data_dir = Path(__file__).parent / 'data'

    octiron = Octiron(
        root_directory=data_dir,
        root_context=root_context,
    )

    octiron.update_from_file(
        path=data_dir / 'test_yaml/spo.yaml',
        local_iri=LOCAL_IRI,
    )

    assert (
        LOCAL_IRI,
        RDFS.label,
        Literal(
            'For any triple, its subject and object are Resources, and '
            'predicate is a Property.', ),
    ) in octiron.graph
Beispiel #5
0
def test_markdown_with_context(root_context: LDContext):
    """Update Octiron graph from a Markdown file with a $context."""
    data_dir = Path(__file__).parent / 'data'

    octiron = Octiron(
        root_directory=data_dir,
        root_context=root_context,
    )

    octiron.update_from_file(
        path=data_dir / 'test_with_context.md',
        local_iri=LOCAL_IRI,
    )

    assert set(octiron.graph) == {
        (LOCAL_IRI, RDFS.label, Literal('Hey, I am a test!')),
        (LOCAL_IRI, RDF.type, OCTA.Page),
        (LOCAL_IRI, OCTA.fileName, Literal('test_with_context.md')),
        (LOCAL_IRI, OCTA.subjectOf, LOCAL_IRI),
        (LOCAL_IRI, OCTA.url, Literal('/test/')),
        (URIRef('local:test_with_context.md'), OCTA.isChildOf, URIRef(LOCAL)),
        (URIRef(LOCAL), RDF.type, OCTA.Directory),
    }
Beispiel #6
0
def test_yaml_date(root_context: LDContext):
    """
    Update Octiron graph from a YAML file with a date in it.

    Created for https://github.com/digitalbazaar/pyld/issues/146
    """
    data_dir = Path(__file__).parent / 'data'

    octiron = Octiron(
        root_directory=data_dir,
        root_context=root_context,
    )

    octiron.update_from_file(
        path=data_dir / 'test_yaml/publication_date.yaml',
        local_iri=LOCAL_IRI,
    )

    assert (
        LOCAL.foo,
        LOCAL.publicationDate,
        Literal('2020-11-16'),
    ) in octiron.graph
Beispiel #7
0
def test_markdown_without_id(root_context: LDContext):
    """Update Octiron graph from a Markdown file without a $id."""
    data_dir = Path(__file__).parent / 'data'

    octiron = Octiron(
        root_directory=data_dir,
        root_context=root_context,
    )

    octiron.update_from_file(
        path=data_dir / 'test_without_id.md',
        local_iri=LOCAL_IRI,
    )

    REAL_IRI = LOCAL['test_without_id.md']
    assert set(octiron.graph.triples((None, None, None))) == {
        (LOCAL_IRI, OCTA.title, Literal('Hey, I am a test!')),
        (LOCAL_IRI, RDF.type, OCTA.Page),
        (LOCAL_IRI, OCTA.url, Literal('/test/')),
        (LOCAL_IRI, OCTA.fileName, Literal('test_without_id.md')),
        (LOCAL_IRI, OCTA.subjectOf, LOCAL_IRI),
        (REAL_IRI, OCTA.isChildOf, URIRef(LOCAL)),
        (LOCAL.term(''), RDF.type, OCTA.Directory),
    }