summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNicholas Car <nicholas.car@surroundaustralia.com>2021-10-17 21:23:14 +1000
committerGitHub <noreply@github.com>2021-10-17 21:23:14 +1000
commit735ecb99b6def1f0dd7aa480e3a81334ae740a0f (patch)
treece1a92c82c735479ce89ba3258a866d998e286c9 /test
parent9a9ca7c37d936d7ae00134226a8d249d6a97fed7 (diff)
parent49462fddad2bd2ff148134b49241e1c9d5a8e09f (diff)
downloadrdflib-ttl2.tar.gz
Merge branch 'master' into ttl2ttl2
Diffstat (limited to 'test')
-rw-r--r--test/test_graph.py19
-rw-r--r--test/test_graph_http.py25
-rw-r--r--test/test_namespace.py9
-rw-r--r--test/test_rules.py2
-rw-r--r--test/test_store.py25
5 files changed, 77 insertions, 3 deletions
diff --git a/test/test_graph.py b/test/test_graph.py
index 08c112a5..8143eff9 100644
--- a/test/test_graph.py
+++ b/test/test_graph.py
@@ -9,9 +9,14 @@ from urllib.error import URLError, HTTPError
from rdflib import URIRef, Graph, plugin
from rdflib.exceptions import ParserError
from rdflib.plugin import PluginException
+from rdflib.namespace import Namespace
from nose.exc import SkipTest
+from pathlib import Path
+
+from test.testutils import GraphHelper
+
class GraphTestCase(unittest.TestCase):
store = "default"
@@ -326,6 +331,20 @@ class GraphTestCase(unittest.TestCase):
# this endpoint is currently not available, ignore this test.
pass
+ def test_parse_file_uri(self):
+ EG = Namespace("http://example.org/#")
+ g = Graph()
+ g.parse(Path("./test/nt/simple-04.nt").absolute().as_uri())
+ triple_set = GraphHelper.triple_set(g)
+ self.assertEqual(
+ triple_set,
+ {
+ (EG["Subject"], EG["predicate"], EG["ObjectP"]),
+ (EG["Subject"], EG["predicate"], EG["ObjectQ"]),
+ (EG["Subject"], EG["predicate"], EG["ObjectR"]),
+ },
+ )
+
def testTransitive(self):
person = URIRef("ex:person")
dad = URIRef("ex:dad")
diff --git a/test/test_graph_http.py b/test/test_graph_http.py
index 1ee8292e..927fdc2e 100644
--- a/test/test_graph_http.py
+++ b/test/test_graph_http.py
@@ -63,7 +63,7 @@ class ContentNegotiationHandler(BaseHTTPRequestHandler):
class TestGraphHTTP(unittest.TestCase):
- def content_negotiation(self) -> None:
+ def test_content_negotiation(self) -> None:
EG = Namespace("http://example.org/")
expected = Graph()
expected.add((EG["a"], EG["b"], EG["c"]))
@@ -77,6 +77,29 @@ class TestGraphHTTP(unittest.TestCase):
graph.parse(url, format=format)
self.assertEqual(expected_triples, GraphHelper.triple_set(graph))
+ def test_source(self) -> None:
+ EG = Namespace("http://example.org/")
+ expected = Graph()
+ expected.add((EG["a"], EG["b"], EG["c"]))
+ expected_triples = GraphHelper.triple_set(expected)
+
+ httpmock = SimpleHTTPMock()
+ with ctx_http_server(httpmock.Handler) as server:
+ (host, port) = server.server_address
+ url = f"http://{host}:{port}/"
+
+ httpmock.do_get_responses.append(
+ MockHTTPResponse(
+ 200,
+ "OK",
+ f"<{EG['a']}> <{EG['b']}> <{EG['c']}>.".encode(),
+ {"Content-Type": ["text/turtle"]},
+ )
+ )
+ graph = Graph()
+ graph.parse(source=url)
+ self.assertEqual(expected_triples, GraphHelper.triple_set(graph))
+
def test_3xx(self) -> None:
EG = Namespace("http://example.com/")
expected = Graph()
diff --git a/test/test_namespace.py b/test/test_namespace.py
index 76f5bbf1..e6473c8b 100644
--- a/test/test_namespace.py
+++ b/test/test_namespace.py
@@ -7,6 +7,7 @@ from rdflib import DCTERMS
from rdflib.graph import Graph
from rdflib.namespace import (
FOAF,
+ OWL,
RDF,
RDFS,
SH,
@@ -41,7 +42,7 @@ class NamespaceTest(unittest.TestCase):
prefix = "http://jörn.loves.encoding.problems/"
ns = Namespace(prefix)
self.assertEqual(ns, str(prefix))
- self.assert_(ns["jörn"].startswith(ns))
+ self.assertTrue(ns["jörn"].startswith(ns))
class ClosedNamespaceTest(unittest.TestCase):
@@ -245,3 +246,9 @@ class NamespacePrefixTest(unittest.TestCase):
ref = URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#_1")
self.assertTrue(ref in RDF, "RDF does not include rdf:_1")
+
+ ref = URIRef("http://www.w3.org/2002/07/owl#rational")
+ self.assertTrue(ref in OWL, "OWL does not include owl:rational")
+
+ ref = URIRef("http://www.w3.org/2002/07/owl#real")
+ self.assertTrue(ref in OWL, "OWL does not include owl:real")
diff --git a/test/test_rules.py b/test/test_rules.py
index c2496760..e020193d 100644
--- a/test/test_rules.py
+++ b/test/test_rules.py
@@ -55,7 +55,7 @@ try:
def tearDown(self):
self.g.close()
- shutil.rmtree(tmppath)
+ shutil.rmtree(self.tmppath)
def testPychinko(self):
rules = []
diff --git a/test/test_store.py b/test/test_store.py
new file mode 100644
index 00000000..d4d8d0a8
--- /dev/null
+++ b/test/test_store.py
@@ -0,0 +1,25 @@
+import unittest
+from rdflib import Graph
+from rdflib.store import Store
+from rdflib.namespace import NamespaceManager
+
+
+class TestAbstractStore(unittest.TestCase):
+ def test_namespaces(self):
+ """
+ This tests that Store.namespaces is an empty generator.
+ """
+ store = Store()
+ self.assertEqual(list(store.namespaces()), [])
+
+ def test_namespaces_via_manager(self):
+ """
+ This tests that NamespaceManager.namespaces works correctly with an
+ abstract Store.
+ """
+ namespace_manager = NamespaceManager(Graph(store=Store()))
+ self.assertEqual(list(namespace_manager.namespaces()), [])
+
+
+if __name__ == "__main__":
+ unittest.main()