Uses black for code formatting

pull/258/head
Tpt 2 years ago committed by Thomas Tanon
parent 000bc16810
commit 992137441f
  1. 2
      .github/workflows/tests.yml
  2. 3
      python/pyproject.toml
  3. 1
      python/requirements.dev.txt
  4. 35
      python/tests/test_io.py
  5. 37
      python/tests/test_model.py
  6. 24
      python/tests/test_store.py

@ -94,6 +94,8 @@ jobs:
with: with:
python-version: "3.10" python-version: "3.10"
- run: pip install --upgrade -r python/requirements.dev.txt - run: pip install --upgrade -r python/requirements.dev.txt
- run: python -m black --check --diff --color .
working-directory: ./python
- run: maturin sdist -m python/Cargo.toml - run: maturin sdist -m python/Cargo.toml
- run: pip install target/wheels/*.tar.gz - run: pip install target/wheels/*.tar.gz
- run: python -m unittest - run: python -m unittest

@ -28,3 +28,6 @@ Documentation = "https://pyoxigraph.readthedocs.io/"
Homepage = "https://pyoxigraph.readthedocs.io/" Homepage = "https://pyoxigraph.readthedocs.io/"
Source = "https://github.com/oxigraph/oxigraph/tree/main/python" Source = "https://github.com/oxigraph/oxigraph/tree/main/python"
Tracker = "https://github.com/oxigraph/oxigraph/issues" Tracker = "https://github.com/oxigraph/oxigraph/issues"
[tool.black]
target-version = ['py37']

@ -1,3 +1,4 @@
black
furo furo
maturin maturin
sphinx sphinx

@ -6,9 +6,7 @@ from pyoxigraph import *
EXAMPLE_TRIPLE = Triple( EXAMPLE_TRIPLE = Triple(
NamedNode("http://example.com/foo"), NamedNode("http://example.com/foo"), NamedNode("http://example.com/p"), Literal("1")
NamedNode("http://example.com/p"),
Literal("1")
) )
@ -19,7 +17,7 @@ class TestParse(unittest.TestCase):
fp.flush() fp.flush()
self.assertEqual( self.assertEqual(
list(parse(fp.name, "text/turtle", base_iri="http://example.com/")), list(parse(fp.name, "text/turtle", base_iri="http://example.com/")),
[EXAMPLE_TRIPLE] [EXAMPLE_TRIPLE],
) )
def test_parse_not_existing_file(self): def test_parse_not_existing_file(self):
@ -28,14 +26,26 @@ class TestParse(unittest.TestCase):
def test_parse_str_io(self): def test_parse_str_io(self):
self.assertEqual( self.assertEqual(
list(parse(StringIO('<foo> <p> "1" .'), "text/turtle", base_iri="http://example.com/")), list(
[EXAMPLE_TRIPLE] parse(
StringIO('<foo> <p> "1" .'),
"text/turtle",
base_iri="http://example.com/",
)
),
[EXAMPLE_TRIPLE],
) )
def test_parse_bytes_io(self): def test_parse_bytes_io(self):
self.assertEqual( self.assertEqual(
list(parse(BytesIO(b'<foo> <p> "1" .'), "text/turtle", base_iri="http://example.com/")), list(
[EXAMPLE_TRIPLE] parse(
BytesIO(b'<foo> <p> "1" .'),
"text/turtle",
base_iri="http://example.com/",
)
),
[EXAMPLE_TRIPLE],
) )
def test_parse_io_error(self): def test_parse_io_error(self):
@ -50,9 +60,14 @@ class TestSerialize(unittest.TestCase):
def test_serialize_to_bytes_io(self): def test_serialize_to_bytes_io(self):
output = BytesIO() output = BytesIO()
serialize([EXAMPLE_TRIPLE], output, "text/turtle") serialize([EXAMPLE_TRIPLE], output, "text/turtle")
self.assertEqual(output.getvalue(), b'<http://example.com/foo> <http://example.com/p> "1" .\n') self.assertEqual(
output.getvalue(),
b'<http://example.com/foo> <http://example.com/p> "1" .\n',
)
def test_serialize_to_file(self): def test_serialize_to_file(self):
with NamedTemporaryFile() as fp: with NamedTemporaryFile() as fp:
serialize([EXAMPLE_TRIPLE], fp.name, "text/turtle") serialize([EXAMPLE_TRIPLE], fp.name, "text/turtle")
self.assertEqual(fp.read(), b'<http://example.com/foo> <http://example.com/p> "1" .\n') self.assertEqual(
fp.read(), b'<http://example.com/foo> <http://example.com/p> "1" .\n'
)

@ -29,8 +29,8 @@ class TestBlankNode(unittest.TestCase):
def test_equal(self): def test_equal(self):
self.assertEqual(BlankNode("foo"), BlankNode("foo")) self.assertEqual(BlankNode("foo"), BlankNode("foo"))
self.assertNotEqual(BlankNode("foo"), BlankNode("bar")) self.assertNotEqual(BlankNode("foo"), BlankNode("bar"))
self.assertNotEqual(BlankNode('foo'), NamedNode('http://foo')) self.assertNotEqual(BlankNode("foo"), NamedNode("http://foo"))
self.assertNotEqual(NamedNode('http://foo'), BlankNode('foo')) self.assertNotEqual(NamedNode("http://foo"), BlankNode("foo"))
class TestLiteral(unittest.TestCase): class TestLiteral(unittest.TestCase):
@ -59,10 +59,10 @@ class TestLiteral(unittest.TestCase):
Literal("foo", language="en", datatype=RDF_LANG_STRING), Literal("foo", language="en", datatype=RDF_LANG_STRING),
Literal("foo", language="en"), Literal("foo", language="en"),
) )
self.assertNotEqual(NamedNode('http://foo'), Literal('foo')) self.assertNotEqual(NamedNode("http://foo"), Literal("foo"))
self.assertNotEqual(Literal('foo'), NamedNode('http://foo')) self.assertNotEqual(Literal("foo"), NamedNode("http://foo"))
self.assertNotEqual(BlankNode('foo'), Literal('foo')) self.assertNotEqual(BlankNode("foo"), Literal("foo"))
self.assertNotEqual(Literal('foo'), BlankNode('foo')) self.assertNotEqual(Literal("foo"), BlankNode("foo"))
class TestTriple(unittest.TestCase): class TestTriple(unittest.TestCase):
@ -81,25 +81,32 @@ class TestTriple(unittest.TestCase):
Triple( Triple(
NamedNode("http://example.com/ss"), NamedNode("http://example.com/ss"),
NamedNode("http://example.com/sp"), NamedNode("http://example.com/sp"),
NamedNode("http://example.com/so") NamedNode("http://example.com/so"),
), ),
NamedNode("http://example.com/p"), NamedNode("http://example.com/p"),
Triple( Triple(
NamedNode("http://example.com/os"), NamedNode("http://example.com/os"),
NamedNode("http://example.com/op"), NamedNode("http://example.com/op"),
NamedNode("http://example.com/oo") NamedNode("http://example.com/oo"),
), ) ),
self.assertEqual(t.subject, Triple( )
self.assertEqual(
t.subject,
Triple(
NamedNode("http://example.com/ss"), NamedNode("http://example.com/ss"),
NamedNode("http://example.com/sp"), NamedNode("http://example.com/sp"),
NamedNode("http://example.com/so") NamedNode("http://example.com/so"),
)) ),
)
self.assertEqual(t.predicate, NamedNode("http://example.com/p")) self.assertEqual(t.predicate, NamedNode("http://example.com/p"))
self.assertEqual(t.object, Triple( self.assertEqual(
t.object,
Triple(
NamedNode("http://example.com/os"), NamedNode("http://example.com/os"),
NamedNode("http://example.com/op"), NamedNode("http://example.com/op"),
NamedNode("http://example.com/oo") NamedNode("http://example.com/oo"),
)) ),
)
def test_mapping(self): def test_mapping(self):
t = Triple( t = Triple(

@ -88,7 +88,8 @@ class TestStore(unittest.TestCase):
results = store.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }") results = store.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }")
self.assertIsInstance(results, QueryTriples) self.assertIsInstance(results, QueryTriples)
self.assertEqual( self.assertEqual(
set(results), {Triple(foo, bar, baz)}, set(results),
{Triple(foo, bar, baz)},
) )
def test_select_query(self): def test_select_query(self):
@ -154,30 +155,34 @@ class TestStore(unittest.TestCase):
def test_update_insert_data(self): def test_update_insert_data(self):
store = Store() store = Store()
store.update('INSERT DATA { <http://foo> <http://foo> <http://foo> }') store.update("INSERT DATA { <http://foo> <http://foo> <http://foo> }")
self.assertEqual(len(store), 1) self.assertEqual(len(store), 1)
def test_update_delete_data(self): def test_update_delete_data(self):
store = Store() store = Store()
store.add(Quad(foo, foo, foo)) store.add(Quad(foo, foo, foo))
store.update('DELETE DATA { <http://foo> <http://foo> <http://foo> }') store.update("DELETE DATA { <http://foo> <http://foo> <http://foo> }")
self.assertEqual(len(store), 0) self.assertEqual(len(store), 0)
def test_update_delete_where(self): def test_update_delete_where(self):
store = Store() store = Store()
store.add(Quad(foo, foo, foo)) store.add(Quad(foo, foo, foo))
store.update('DELETE WHERE { ?v ?v ?v }') store.update("DELETE WHERE { ?v ?v ?v }")
self.assertEqual(len(store), 0) self.assertEqual(len(store), 0)
def test_update_load(self): def test_update_load(self):
store = Store() store = Store()
store.update('LOAD <https://www.w3.org/1999/02/22-rdf-syntax-ns>') store.update("LOAD <https://www.w3.org/1999/02/22-rdf-syntax-ns>")
self.assertGreater(len(store), 100) self.assertGreater(len(store), 100)
def test_update_star(self): def test_update_star(self):
store = Store() store = Store()
store.update('PREFIX : <http://www.example.org/> INSERT DATA { :alice :claims << :bob :age 23 >> }') store.update(
results = store.query('PREFIX : <http://www.example.org/> SELECT ?p ?a WHERE { ?p :claims << :bob :age ?a >> }') "PREFIX : <http://www.example.org/> INSERT DATA { :alice :claims << :bob :age 23 >> }"
)
results = store.query(
"PREFIX : <http://www.example.org/> SELECT ?p ?a WHERE { ?p :claims << :bob :age ?a >> }"
)
self.assertEqual(len(list(results)), 1) self.assertEqual(len(list(results)), 1)
def test_load_ntriples_to_default_graph(self): def test_load_ntriples_to_default_graph(self):
@ -245,7 +250,8 @@ class TestStore(unittest.TestCase):
output = BytesIO() output = BytesIO()
store.dump(output, "application/n-triples", from_graph=graph) store.dump(output, "application/n-triples", from_graph=graph)
self.assertEqual( self.assertEqual(
output.getvalue(), b"<http://foo> <http://bar> <http://baz> .\n", output.getvalue(),
b"<http://foo> <http://bar> <http://baz> .\n",
) )
def test_dump_nquads(self): def test_dump_nquads(self):
@ -264,7 +270,7 @@ class TestStore(unittest.TestCase):
store = Store() store = Store()
store.add(Quad(foo, bar, baz, graph)) store.add(Quad(foo, bar, baz, graph))
store.dump(file_name, "application/n-quads") store.dump(file_name, "application/n-quads")
with open(file_name, 'rt') as fp: with open(file_name, "rt") as fp:
file_content = fp.read() file_content = fp.read()
self.assertEqual( self.assertEqual(
file_content, file_content,

Loading…
Cancel
Save