"1" .')
fp.flush()
@@ -20,11 +20,11 @@ class TestParse(unittest.TestCase):
[EXAMPLE_TRIPLE],
)
- def test_parse_not_existing_file(self):
+ def test_parse_not_existing_file(self) -> None:
with self.assertRaises(IOError) as _:
parse("/tmp/not-existing-oxigraph-file.ttl", "text/turtle")
- def test_parse_str_io(self):
+ def test_parse_str_io(self) -> None:
self.assertEqual(
list(
parse(
@@ -36,7 +36,7 @@ class TestParse(unittest.TestCase):
[EXAMPLE_TRIPLE],
)
- def test_parse_bytes_io(self):
+ def test_parse_bytes_io(self) -> None:
self.assertEqual(
list(
parse(
@@ -48,7 +48,7 @@ class TestParse(unittest.TestCase):
[EXAMPLE_TRIPLE],
)
- def test_parse_io_error(self):
+ def test_parse_io_error(self) -> None:
class BadIO(RawIOBase):
pass
@@ -57,7 +57,7 @@ class TestParse(unittest.TestCase):
class TestSerialize(unittest.TestCase):
- def test_serialize_to_bytes_io(self):
+ def test_serialize_to_bytes_io(self) -> None:
output = BytesIO()
serialize([EXAMPLE_TRIPLE], output, "text/turtle")
self.assertEqual(
@@ -65,7 +65,7 @@ class TestSerialize(unittest.TestCase):
b' "1" .\n',
)
- def test_serialize_to_file(self):
+ def test_serialize_to_file(self) -> None:
with NamedTemporaryFile() as fp:
serialize([EXAMPLE_TRIPLE], fp.name, "text/turtle")
self.assertEqual(
diff --git a/python/tests/test_model.py b/python/tests/test_model.py
index d663d7a1..e84322a4 100644
--- a/python/tests/test_model.py
+++ b/python/tests/test_model.py
@@ -7,26 +7,26 @@ RDF_LANG_STRING = NamedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#langStri
class TestNamedNode(unittest.TestCase):
- def test_constructor(self):
+ def test_constructor(self) -> None:
self.assertEqual(NamedNode("http://foo").value, "http://foo")
- def test_string(self):
+ def test_string(self) -> None:
self.assertEqual(str(NamedNode("http://foo")), "")
- def test_equal(self):
+ def test_equal(self) -> None:
self.assertEqual(NamedNode("http://foo"), NamedNode("http://foo"))
self.assertNotEqual(NamedNode("http://foo"), NamedNode("http://bar"))
class TestBlankNode(unittest.TestCase):
- def test_constructor(self):
+ def test_constructor(self) -> None:
self.assertEqual(BlankNode("foo").value, "foo")
self.assertNotEqual(BlankNode(), BlankNode())
- def test_string(self):
+ def test_string(self) -> None:
self.assertEqual(str(BlankNode("foo")), "_:foo")
- def test_equal(self):
+ def test_equal(self) -> None:
self.assertEqual(BlankNode("foo"), BlankNode("foo"))
self.assertNotEqual(BlankNode("foo"), BlankNode("bar"))
self.assertNotEqual(BlankNode("foo"), NamedNode("http://foo"))
@@ -34,7 +34,7 @@ class TestBlankNode(unittest.TestCase):
class TestLiteral(unittest.TestCase):
- def test_constructor(self):
+ def test_constructor(self) -> None:
self.assertEqual(Literal("foo").value, "foo")
self.assertEqual(Literal("foo").datatype, XSD_STRING)
@@ -45,7 +45,7 @@ class TestLiteral(unittest.TestCase):
self.assertEqual(Literal("foo", datatype=XSD_INTEGER).value, "foo")
self.assertEqual(Literal("foo", datatype=XSD_INTEGER).datatype, XSD_INTEGER)
- def test_string(self):
+ def test_string(self) -> None:
self.assertEqual(str(Literal("foo")), '"foo"')
self.assertEqual(str(Literal("foo", language="en")), '"foo"@en')
self.assertEqual(
@@ -53,7 +53,7 @@ class TestLiteral(unittest.TestCase):
'"foo"^^',
)
- def test_equals(self):
+ def test_equals(self) -> None:
self.assertEqual(Literal("foo", datatype=XSD_STRING), Literal("foo"))
self.assertEqual(
Literal("foo", language="en", datatype=RDF_LANG_STRING),
@@ -66,7 +66,7 @@ class TestLiteral(unittest.TestCase):
class TestTriple(unittest.TestCase):
- def test_constructor(self):
+ def test_constructor(self) -> None:
t = Triple(
NamedNode("http://example.com/s"),
NamedNode("http://example.com/p"),
@@ -76,7 +76,7 @@ class TestTriple(unittest.TestCase):
self.assertEqual(t.predicate, NamedNode("http://example.com/p"))
self.assertEqual(t.object, NamedNode("http://example.com/o"))
- def test_rdf_star_constructor(self):
+ def test_rdf_star_constructor(self) -> None:
t = Triple(
Triple(
NamedNode("http://example.com/ss"),
@@ -108,7 +108,7 @@ class TestTriple(unittest.TestCase):
),
)
- def test_mapping(self):
+ def test_mapping(self) -> None:
t = Triple(
NamedNode("http://example.com/s"),
NamedNode("http://example.com/p"),
@@ -118,7 +118,7 @@ class TestTriple(unittest.TestCase):
self.assertEqual(t[1], NamedNode("http://example.com/p"))
self.assertEqual(t[2], NamedNode("http://example.com/o"))
- def test_destruct(self):
+ def test_destruct(self) -> None:
(s, p, o) = Triple(
NamedNode("http://example.com/s"),
NamedNode("http://example.com/p"),
@@ -128,7 +128,7 @@ class TestTriple(unittest.TestCase):
self.assertEqual(p, NamedNode("http://example.com/p"))
self.assertEqual(o, NamedNode("http://example.com/o"))
- def test_string(self):
+ def test_string(self) -> None:
self.assertEqual(
str(
Triple(
@@ -142,7 +142,7 @@ class TestTriple(unittest.TestCase):
class TestQuad(unittest.TestCase):
- def test_constructor(self):
+ def test_constructor(self) -> None:
t = Quad(
NamedNode("http://example.com/s"),
NamedNode("http://example.com/p"),
@@ -175,7 +175,7 @@ class TestQuad(unittest.TestCase):
),
)
- def test_mapping(self):
+ def test_mapping(self) -> None:
t = Quad(
NamedNode("http://example.com/s"),
NamedNode("http://example.com/p"),
@@ -187,7 +187,7 @@ class TestQuad(unittest.TestCase):
self.assertEqual(t[2], NamedNode("http://example.com/o"))
self.assertEqual(t[3], NamedNode("http://example.com/g"))
- def test_destruct(self):
+ def test_destruct(self) -> None:
(s, p, o, g) = Quad(
NamedNode("http://example.com/s"),
NamedNode("http://example.com/p"),
@@ -199,7 +199,7 @@ class TestQuad(unittest.TestCase):
self.assertEqual(o, NamedNode("http://example.com/o"))
self.assertEqual(g, NamedNode("http://example.com/g"))
- def test_string(self):
+ def test_string(self) -> None:
self.assertEqual(
str(
Triple(
@@ -213,13 +213,13 @@ class TestQuad(unittest.TestCase):
class TestVariable(unittest.TestCase):
- def test_constructor(self):
+ def test_constructor(self) -> None:
self.assertEqual(Variable("foo").value, "foo")
- def test_string(self):
+ def test_string(self) -> None:
self.assertEqual(str(Variable("foo")), "?foo")
- def test_equal(self):
+ def test_equal(self) -> None:
self.assertEqual(Variable("foo"), Variable("foo"))
self.assertNotEqual(Variable("foo"), Variable("bar"))
diff --git a/python/tests/test_store.py b/python/tests/test_store.py
index 88152f7d..a8ac1e0b 100644
--- a/python/tests/test_store.py
+++ b/python/tests/test_store.py
@@ -1,6 +1,7 @@
import os
import unittest
from io import BytesIO, RawIOBase
+from typing import Any
from pyoxigraph import *
from tempfile import NamedTemporaryFile
@@ -13,7 +14,7 @@ graph = NamedNode("http://graph")
class TestStore(unittest.TestCase):
- def test_add(self):
+ def test_add(self) -> None:
store = Store()
store.add(Quad(foo, bar, baz))
store.add(Quad(foo, bar, baz, DefaultGraph()))
@@ -22,7 +23,7 @@ class TestStore(unittest.TestCase):
store.add(Quad(foo, bar, triple))
self.assertEqual(len(store), 4)
- def test_remove(self):
+ def test_remove(self) -> None:
store = Store()
store.add(Quad(foo, bar, baz))
store.add(Quad(foo, bar, baz, DefaultGraph()))
@@ -30,13 +31,13 @@ class TestStore(unittest.TestCase):
store.remove(Quad(foo, bar, baz))
self.assertEqual(len(store), 1)
- def test_len(self):
+ def test_len(self) -> None:
store = Store()
store.add(Quad(foo, bar, baz))
store.add(Quad(foo, bar, baz, graph))
self.assertEqual(len(store), 2)
- def test_in(self):
+ def test_in(self) -> None:
store = Store()
store.add(Quad(foo, bar, baz))
store.add(Quad(foo, bar, baz, DefaultGraph()))
@@ -46,7 +47,7 @@ class TestStore(unittest.TestCase):
self.assertIn(Quad(foo, bar, baz, graph), store)
self.assertNotIn(Quad(foo, bar, baz, foo), store)
- def test_iter(self):
+ def test_iter(self) -> None:
store = Store()
store.add(Quad(foo, bar, baz, DefaultGraph()))
store.add(Quad(foo, bar, baz, graph))
@@ -55,7 +56,7 @@ class TestStore(unittest.TestCase):
{Quad(foo, bar, baz, DefaultGraph()), Quad(foo, bar, baz, graph)},
)
- def test_quads_for_pattern(self):
+ def test_quads_for_pattern(self) -> None:
store = Store()
store.add(Quad(foo, bar, baz, DefaultGraph()))
store.add(Quad(foo, bar, baz, graph))
@@ -76,26 +77,26 @@ class TestStore(unittest.TestCase):
{Quad(foo, bar, baz, DefaultGraph())},
)
- def test_ask_query(self):
+ def test_ask_query(self) -> None:
store = Store()
store.add(Quad(foo, foo, foo))
self.assertTrue(store.query("ASK { ?s ?s ?s }"))
self.assertFalse(store.query("ASK { FILTER(false) }"))
- def test_construct_query(self):
+ def test_construct_query(self) -> None:
store = Store()
store.add(Quad(foo, bar, baz))
- results = store.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }")
+ results: Any = store.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }")
self.assertIsInstance(results, QueryTriples)
self.assertEqual(
set(results),
{Triple(foo, bar, baz)},
)
- def test_select_query(self):
+ def test_select_query(self) -> None:
store = Store()
store.add(Quad(foo, bar, baz))
- solutions = store.query("SELECT ?s ?o WHERE { ?s ?p ?o }")
+ solutions: Any = store.query("SELECT ?s ?o WHERE { ?s ?p ?o }")
self.assertIsInstance(solutions, QuerySolutions)
self.assertEqual(solutions.variables, [Variable("s"), Variable("o")])
solution = next(solutions)
@@ -110,10 +111,11 @@ class TestStore(unittest.TestCase):
self.assertEqual(s, foo)
self.assertEqual(o, baz)
- def test_select_query_union_default_graph(self):
+ def test_select_query_union_default_graph(self) -> None:
store = Store()
store.add(Quad(foo, bar, baz, graph))
- self.assertEqual(len(list(store.query("SELECT ?s WHERE { ?s ?p ?o }"))), 0)
+ results: Any = store.query("SELECT ?s WHERE { ?s ?p ?o }")
+ self.assertEqual(len(list(results)), 0)
results = store.query(
"SELECT ?s WHERE { ?s ?p ?o }", use_default_graph_as_union=True
)
@@ -125,13 +127,14 @@ class TestStore(unittest.TestCase):
)
self.assertEqual(len(list(results)), 1)
- def test_select_query_with_default_graph(self):
+ def test_select_query_with_default_graph(self) -> None:
store = Store()
graph_bnode = BlankNode("g")
store.add(Quad(foo, bar, baz, graph))
store.add(Quad(foo, bar, foo))
store.add(Quad(foo, bar, bar, graph_bnode))
- self.assertEqual(len(list(store.query("SELECT ?s WHERE { ?s ?p ?o }"))), 1)
+ results: Any = store.query("SELECT ?s WHERE { ?s ?p ?o }")
+ self.assertEqual(len(list(results)), 1)
results = store.query("SELECT ?s WHERE { ?s ?p ?o }", default_graph=graph)
self.assertEqual(len(list(results)), 1)
results = store.query(
@@ -140,52 +143,52 @@ class TestStore(unittest.TestCase):
)
self.assertEqual(len(list(results)), 3)
- def test_select_query_with_named_graph(self):
+ def test_select_query_with_named_graph(self) -> None:
store = Store()
graph_bnode = BlankNode("g")
store.add(Quad(foo, bar, baz, graph))
store.add(Quad(foo, bar, foo))
store.add(Quad(foo, bar, bar, graph_bnode))
store.add(Quad(foo, bar, bar, foo))
- results = store.query(
+ results: Any = store.query(
"SELECT ?s WHERE { GRAPH ?g { ?s ?p ?o } }",
named_graphs=[graph, graph_bnode],
)
self.assertEqual(len(list(results)), 2)
- def test_update_insert_data(self):
+ def test_update_insert_data(self) -> None:
store = Store()
store.update("INSERT DATA { }")
self.assertEqual(len(store), 1)
- def test_update_delete_data(self):
+ def test_update_delete_data(self) -> None:
store = Store()
store.add(Quad(foo, foo, foo))
store.update("DELETE DATA { }")
self.assertEqual(len(store), 0)
- def test_update_delete_where(self):
+ def test_update_delete_where(self) -> None:
store = Store()
store.add(Quad(foo, foo, foo))
store.update("DELETE WHERE { ?v ?v ?v }")
self.assertEqual(len(store), 0)
- def test_update_load(self):
+ def test_update_load(self) -> None:
store = Store()
store.update("LOAD ")
self.assertGreater(len(store), 100)
- def test_update_star(self):
+ def test_update_star(self) -> None:
store = Store()
store.update(
"PREFIX : INSERT DATA { :alice :claims << :bob :age 23 >> }"
)
- results = store.query(
+ results: Any = store.query(
"PREFIX : SELECT ?p ?a WHERE { ?p :claims << :bob :age ?a >> }"
)
self.assertEqual(len(list(results)), 1)
- def test_load_ntriples_to_default_graph(self):
+ def test_load_ntriples_to_default_graph(self) -> None:
store = Store()
store.load(
BytesIO(b" ."),
@@ -193,7 +196,7 @@ class TestStore(unittest.TestCase):
)
self.assertEqual(set(store), {Quad(foo, bar, baz, DefaultGraph())})
- def test_load_ntriples_to_named_graph(self):
+ def test_load_ntriples_to_named_graph(self) -> None:
store = Store()
store.load(
BytesIO(b" ."),
@@ -202,7 +205,7 @@ class TestStore(unittest.TestCase):
)
self.assertEqual(set(store), {Quad(foo, bar, baz, graph)})
- def test_load_turtle_with_base_iri(self):
+ def test_load_turtle_with_base_iri(self) -> None:
store = Store()
store.load(
BytesIO(b" <> ."),
@@ -211,7 +214,7 @@ class TestStore(unittest.TestCase):
)
self.assertEqual(set(store), {Quad(foo, bar, baz, DefaultGraph())})
- def test_load_nquads(self):
+ def test_load_nquads(self) -> None:
store = Store()
store.load(
BytesIO(b" ."),
@@ -219,7 +222,7 @@ class TestStore(unittest.TestCase):
)
self.assertEqual(set(store), {Quad(foo, bar, baz, graph)})
- def test_load_trig_with_base_iri(self):
+ def test_load_trig_with_base_iri(self) -> None:
store = Store()
store.load(
BytesIO(b" { <> . }"),
@@ -228,7 +231,7 @@ class TestStore(unittest.TestCase):
)
self.assertEqual(set(store), {Quad(foo, bar, baz, graph)})
- def test_load_file(self):
+ def test_load_file(self) -> None:
with NamedTemporaryFile(delete=False) as fp:
file_name = fp.name
fp.write(b" .")
@@ -237,14 +240,14 @@ class TestStore(unittest.TestCase):
os.remove(file_name)
self.assertEqual(set(store), {Quad(foo, bar, baz, graph)})
- def test_load_with_io_error(self):
+ def test_load_with_io_error(self) -> None:
class BadIO(RawIOBase):
pass
with self.assertRaises(NotImplementedError) as _:
Store().load(BadIO(), mime_type="application/n-triples")
- def test_dump_ntriples(self):
+ def test_dump_ntriples(self) -> None:
store = Store()
store.add(Quad(foo, bar, baz, graph))
output = BytesIO()
@@ -254,7 +257,7 @@ class TestStore(unittest.TestCase):
b" .\n",
)
- def test_dump_nquads(self):
+ def test_dump_nquads(self) -> None:
store = Store()
store.add(Quad(foo, bar, baz, graph))
output = BytesIO()
@@ -264,7 +267,7 @@ class TestStore(unittest.TestCase):
b" .\n",
)
- def test_dump_file(self):
+ def test_dump_file(self) -> None:
with NamedTemporaryFile(delete=False) as fp:
file_name = fp.name
store = Store()
@@ -277,14 +280,14 @@ class TestStore(unittest.TestCase):
" .\n",
)
- def test_dump_with_io_error(self):
+ def test_dump_with_io_error(self) -> None:
class BadIO(RawIOBase):
pass
with self.assertRaises(OSError) as _:
Store().dump(BadIO(), mime_type="application/rdf+xml")
- def test_write_in_read(self):
+ def test_write_in_read(self) -> None:
store = Store()
store.add(Quad(foo, bar, bar))
store.add(Quad(foo, bar, baz))
@@ -292,12 +295,12 @@ class TestStore(unittest.TestCase):
store.add(Quad(triple.object, triple.predicate, triple.subject))
self.assertEqual(len(store), 4)
- def test_add_graph(self):
+ def test_add_graph(self) -> None:
store = Store()
store.add_graph(graph)
self.assertEqual(list(store.named_graphs()), [graph])
- def test_remove_graph(self):
+ def test_remove_graph(self) -> None:
store = Store()
store.add(Quad(foo, bar, baz, graph))
store.add_graph(NamedNode("http://graph2"))