Skip to content

Added update() method to sparqlwrapper backend#356

Merged
jesper-friis merged 10 commits intomasterfrom
update-query
Mar 14, 2025
Merged

Added update() method to sparqlwrapper backend#356
jesper-friis merged 10 commits intomasterfrom
update-query

Conversation

@jesper-friis
Copy link
Contributor

@jesper-friis jesper-friis commented Mar 11, 2025

Description

Added update() method to sparqlwrapper backend supporting both INSERT and DELETE queries.

Other fixes:

  • fixed failing test by empty the triplestore as the first thing in the test
  • made it easier to run the populate_and_search() test in test_sqarqlwrapper_graphdb_fuseki.py without pytest.

Type of change

  • Bug fix and code cleanup
  • New feature
  • Documentation update
  • Testing

Checklist for the reviewer

This checklist should be used as a help for the reviewer.

  • Is the change limited to one issue?
  • Does this PR close the issue?
  • Is the code easy to read and understand?
  • Do all new feature have an accompanying new test?
  • Has the documentation been updated as necessary?
  • Is the code properly tested?

@codecov
Copy link

codecov bot commented Mar 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.91%. Comparing base (004f05e) to head (0de7c6b).
Report is 11 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +59 to +82
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

@jesper-friis jesper-friis Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
    ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could run if True on test_fuseki and test_graphdb directly before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no reason to do this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For debugging as explained above.

Comment on lines +218 to +229
# 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)]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer that ts.update tests are done in the same place and not scattered around.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want it to infer with the existing tests above, so I placed it at the end...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already do by adding the delete at the top.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to use remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some tests for these as well

Copy link
Contributor

@francescalb francescalb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please view my comments. Also, this PR is not linked to an issue and why this should have priority now.

@jesper-friis
Copy link
Contributor Author

jesper-friis commented Mar 11, 2025

Please view my comments. Also, this PR is not linked to an issue and why this should have priority now.

The main motivation for this PR is that it fixes some sporadic failing tests (like PR #324) by emptying the triplestore.

@francescalb
Copy link
Contributor

Please view my comments. Also, this PR is not linked to an issue and why this should have priority now.

The main motivation for this PR is that it fixes some sporadic failing tests (like PR #324) by emptying the triplestore.
Are you sure 324 fails because if this? A new triplestore is added in each test.

@jesper-friis
Copy link
Contributor Author

Please view my comments. Also, this PR is not linked to an issue and why this should have priority now.

The main motivation for this PR is that it fixes some sporadic failing tests (like PR #324) by emptying the triplestore.
Are you sure 324 fails because if this? A new triplestore is added in each test.

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.

Copy link
Contributor

@francescalb francescalb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strongly displike these changes in the test, but one of us have to give.

@jesper-friis jesper-friis merged commit 7450e6a into master Mar 14, 2025
19 checks passed
@jesper-friis jesper-friis deleted the update-query branch March 14, 2025 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants