File: test_nquads_w3c.py

package info (click to toggle)
rdflib 6.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 38,248 kB
  • sloc: python: 39,216; sh: 153; makefile: 110
file content (36 lines) | stat: -rw-r--r-- 887 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""This runs the nquads tests for the W3C RDF Working Group's N-Quads
test suite."""

from typing import Callable, Dict
from rdflib import ConjunctiveGraph
from rdflib.term import Node, URIRef
from test.manifest import RDFT, RDFTest, read_manifest
import pytest

verbose = False


def nquads(test):
    g = ConjunctiveGraph()

    try:
        g.parse(test.action, format="nquads")
        if not test.syntax:
            raise AssertionError("Input shouldn't have parsed!")
    except:
        if test.syntax:
            raise


testers: Dict[Node, Callable[[RDFTest], None]] = {
    RDFT.TestNQuadsPositiveSyntax: nquads,
    RDFT.TestNQuadsNegativeSyntax: nquads,
}


@pytest.mark.parametrize(
    "rdf_test_uri, type, rdf_test",
    read_manifest("test/w3c/nquads/manifest.ttl"),
)
def test_manifest(rdf_test_uri: URIRef, type: Node, rdf_test: RDFTest):
    testers[type](rdf_test)