Added update() method to sparqlwrapper backend#356
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #356 +/- ##
==========================================
+ Coverage 77.77% 77.91% +0.14%
==========================================
Files 22 22
Lines 2515 2522 +7
==========================================
+ Hits 1956 1965 +9
+ Misses 559 557 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| def get_triplestore(tsname: str) -> "Triplestore": | ||
| """Help function that returns a new triplestore object.""" | ||
| from tripper import Triplestore | ||
|
|
||
| if tsname == "GraphDB": | ||
| ts = Triplestore( | ||
| backend="sparqlwrapper", | ||
| base_iri="http://localhost:7200/repositories/test_repo", | ||
| update_iri=( | ||
| "http://localhost:7200/repositories/test_repo/statements" | ||
| ), | ||
| ) | ||
| elif tsname == "Fuseki": | ||
| ts = Triplestore( | ||
| backend="sparqlwrapper", | ||
| base_iri=f"{FUSEKI_CHECK_URL}/test_repo", | ||
| update_iri=f"{FUSEKI_CHECK_URL}/test_repo/update", | ||
| username="admin", | ||
| password="admin0", | ||
| ) | ||
| else: | ||
| raise ValueError(f"Unsupported triplestore name: {tsname}") | ||
|
|
||
| return ts |
There was a problem hiding this comment.
I disagree with moving this out of the actual test for each triplestore. There is reduction in duplication of code here, and the test as it is, is so small already that moving things out makes it less readable.
There was a problem hiding this comment.
The point with this is to make it easy to run the test without pytest for debugging.
Now I can do:
if True:
tsname = "Fuseki"
#def populate_and_search(tsname):
...There was a problem hiding this comment.
You could run if True on test_fuseki and test_graphdb directly before.
There was a problem hiding this comment.
That will not allow me to debug. I want to be able to investigate variables within populate_and_search() with the interpreter.
| datasetinput = thisdir / "datadocumentation_sample.yaml" | ||
| datasetinput2 = thisdir / "datadocumentation_sample2.yaml" | ||
|
|
||
| ts = get_triplestore(tsname) |
There was a problem hiding this comment.
I see no reason to do this
There was a problem hiding this comment.
For debugging as explained above.
| # Test INSERT query | ||
| query = """ | ||
| PREFIX : <http://example.com#> | ||
| INSERT DATA { | ||
| :sub :pred :obj . | ||
| } | ||
| """ | ||
| EX = ts.bind("ex", "http://example.com#") | ||
| ts.update(query) | ||
| triples = list(ts.triples(EX.sub)) | ||
| assert triples == [(EX.sub, EX.pred, EX.obj)] | ||
|
|
There was a problem hiding this comment.
I prefer that ts.update tests are done in the same place and not scattered around.
There was a problem hiding this comment.
I don't want it to infer with the existing tests above, so I placed it at the end...
There was a problem hiding this comment.
You already do by adding the delete at the top.
There was a problem hiding this comment.
Would be better to use remove.
There was a problem hiding this comment.
You already do by adding the delete at the top.
True. That is by purpose, to avoid strange failures due to garbage in the triplestore.
| the query() method for ASK/CONSTRUCT/SELECT/DESCRIBE queries. | ||
| """ | ||
| query_type = self._get_sparql_query_type(update_object) | ||
| if query_type not in ("DELETE", "INSERT"): |
There was a problem hiding this comment.
If you put this in, I think you should also add a test to it. It is quite quick, there is already one that can be copied using query.
There was a problem hiding this comment.
Added some tests for these as well
francescalb
left a comment
There was a problem hiding this comment.
Please view my comments. Also, this PR is not linked to an issue and why this should have priority now.
Co-authored-by: Francesca L. Bleken <48128015+francescalb@users.noreply.github.com>
The main motivation for this PR is that it fixes some sporadic failing tests (like PR #324) by emptying the triplestore. |
|
Yes, I think so. I got similar failures as in 324 in master locally, which I got rid of by cleaning the triplestore in the start of the test. |
francescalb
left a comment
There was a problem hiding this comment.
Strongly displike these changes in the test, but one of us have to give.
Description
Added update() method to sparqlwrapper backend supporting both INSERT and DELETE queries.
Other fixes:
test_sqarqlwrapper_graphdb_fuseki.pywithout pytest.Type of change
Checklist for the reviewer
This checklist should be used as a help for the reviewer.