Python: adds Store.extend

pull/428/head
Tpt 2 years ago committed by Thomas Tanon
parent e553b6374a
commit 0e00e8209a
  1. 22
      python/src/store.rs
  2. 5
      python/tests/test_store.py

@ -130,6 +130,28 @@ impl PyStore {
})
}
/// Adds atomically a set of quads to this store.
///
/// :param quads: the quads to add.
/// :type quad: iterable(Quad)
/// :rtype: None
/// :raises IOError: if an I/O error happens during the quad insertion.
///
/// >>> store = Store()
/// >>> store.extend([Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))])
/// >>> list(store)
/// [<Quad subject=<NamedNode value=http://example.com> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>]
fn extend(&self, quads: &PyAny, py: Python<'_>) -> PyResult<()> {
let quads = quads
.iter()?
.map(|q| q?.extract())
.collect::<PyResult<Vec<PyQuad>>>()?;
py.allow_threads(|| {
self.inner.extend(quads).map_err(map_storage_error)?;
Ok(())
})
}
/// Removes a quad from the store.
///
/// :param quad: the quad to remove.

@ -23,6 +23,11 @@ class TestStore(unittest.TestCase):
store.add(Quad(foo, bar, triple))
self.assertEqual(len(store), 4)
def test_extend(self) -> None:
store = Store()
store.extend((Quad(foo, bar, baz), Quad(foo, bar, baz, graph), Quad(foo, bar, baz, DefaultGraph())))
self.assertEqual(len(store), 2)
def test_remove(self) -> None:
store = Store()
store.add(Quad(foo, bar, baz))

Loading…
Cancel
Save