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
|
import unittest
from rdflib import RDFS, Graph, Literal, URIRef
class TestIssue977(unittest.TestCase):
def setUp(self):
self.graph = Graph()
# Bind prefixes.
self.graph.bind("isbn", "urn:isbn:")
self.graph.bind("webn", "http://w3c.org/example/isbn/")
# Populate graph.
self.graph.add(
(URIRef("urn:isbn:1503280780"), RDFS.label, Literal("Moby Dick"))
)
self.graph.add(
(
URIRef("http://w3c.org/example/isbn/1503280780"),
RDFS.label,
Literal("Moby Dick"),
)
)
def test_namespace_manager(self):
assert "isbn", "urn:isbn:" in tuple(self.graph.namespaces())
assert "webn", "http://w3c.org/example/isbn/" in tuple(self.graph.namespaces())
def test_turtle_serialization(self):
serialization = self.graph.serialize(None, format="turtle")
print(f"Test Issue 977, serialization output:\n---\n{serialization}---")
# Test serialization.
assert (
"@prefix webn:" in serialization
), "Prefix webn not found in serialization!"
assert (
"@prefix isbn:" in serialization
), "Prefix isbn not found in serialization!"
if __name__ == "__main__":
unittest.main()
|