Skip to content

Commit

Permalink
triplestore coverage now 100%, total coverage 82%
Browse files Browse the repository at this point in the history
  • Loading branch information
staffanm committed Oct 18, 2013
1 parent 3c94fc3 commit 7900020
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 23 deletions.
28 changes: 13 additions & 15 deletions ferenda/triplestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ def select(self, query, format="sparql"):
raise NotImplementedError # pragma: no cover

def construct(self, query):
"""
Run a SPARQL CONSTRUCT query against the triple store and returns the results as a RDFLib graph
"""Run a SPARQL CONSTRUCT query against the triple store and returns
the results as a RDFLib graph
:param query: A SPARQL query with all neccessary prefixes defined.
:type query: str
"""
raise NotImplementedError # pragma: no cover

Expand All @@ -155,11 +156,14 @@ def triple_count(self, context=None):
raise NotImplementedError # pragma: no cover

def clear(self, context=None):
"""Removes all statements from the repository (without removing the repository as such)."""
"""Removes all statements from the repository (without removing the
repository as such)."""
raise NotImplementedError # pragma: no cover

def close(self):
"""Close all connections to the triplestore. Needed if using RDFLib-based triple store, a no-op if using HTTP based stores."""
"""Close all connections to the triplestore. Needed if using
RDFLib-based triple store, a no-op if using HTTP based stores."""
raise NotImplementedError # pragma: no cover


class RDFLibStore(TripleStore):
Expand Down Expand Up @@ -295,10 +299,11 @@ def _storeid(self):
# -----------------
# For servers implementing the SPARQL 1.1 Graph Store HTTP Protocol
# http://www.w3.org/TR/sparql11-http-rdf-update/


class RemoteStore(TripleStore):

def close(self):
pass

_contenttype = {"xml": "application/rdf+xml",
"sparql": "application/sparql-results+xml",
"nt": "text/plain",
Expand Down Expand Up @@ -341,9 +346,6 @@ def add_serialized(self, data, format, context=None):
resp = requests.post(self._statements_url(context),
headers=headers,
data=datastream)
if resp.status_code >= 400:
print("Something went wrong posting to %s" % self._statements_url(context))
print(resp.text.encode('latin-1', errors='xmlcharrefreplace'))
resp.raise_for_status()

def add_serialized_file(self, filename, format, context=None):
Expand Down Expand Up @@ -410,11 +412,7 @@ def clear(self, context=None):

def select(self, query, format="sparql"):
url = self._endpoint_url()
if "?" in url:
url += "&"
else:
url += "?"
url += "query=" + quote(query.replace("\n", " ")).replace("/", "%2F")
url += "?query=" + quote(query.replace("\n", " ")).replace("/", "%2F")

headers = {}
if format == "python":
Expand Down Expand Up @@ -445,7 +443,7 @@ def construct(self, query):
result.parse(data=resp.text, format=format)
return result
except requests.exceptions.HTTPError as e:
raise errors.SparqlError(e.response.text)
raise errors.SparqlError(e)

def _sparql_results_to_list(self, results):
res = []
Expand Down
1 change: 1 addition & 0 deletions test/files/triplestore/size-18.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
1 change: 1 addition & 0 deletions test/files/triplestore/size-39.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
39
Loading

0 comments on commit 7900020

Please sign in to comment.