File: test_issue379.py

package info (click to toggle)
rdflib 7.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 77,852 kB
  • sloc: python: 59,555; sh: 153; makefile: 83; ruby: 74; xml: 45
file content (51 lines) | stat: -rw-r--r-- 1,421 bytes parent folder | download | duplicates (2)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Tests for GitHub Issue 379: https://github.com/RDFLib/rdflib/issues/379
"""

import pytest

import rdflib


@pytest.fixture
def prefix_data():
    return """
           @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
           @prefix : <http://www.example.com#> .

           <http://www.example.com#prefix> a rdf:class ."""


@pytest.fixture
def base_data():
    return """
           @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
           @base <http://www.example.com#> .

           <http://www.example.com#base> a rdf:class .
           """


@pytest.fixture
def graph():
    return rdflib.Graph()


def test_parse_successful_prefix_with_hash(graph, prefix_data):
    """
    Test parse of '@prefix' namespace directive to allow a trailing hash '#', as is
    permitted for an IRIREF:
    http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-prefixID
    """
    graph.parse(data=prefix_data, format="n3")
    assert isinstance(next(graph.subjects()), rdflib.URIRef)


def test_parse_successful_base_with_hash(graph, base_data):
    """
    Test parse of '@base' namespace directive to allow a trailing hash '#', as is
    permitted for an '@prefix' since both allow an IRIREF:
    http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-base
    """
    graph.parse(data=base_data, format="n3")
    assert isinstance(next(graph.subjects()), rdflib.URIRef)