-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added test for example at CBD definition. Fixes #1914. #1915
Conversation
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
test/test_graph/test_graph_cbd.py
Outdated
# add example from Concise Bounded Description definition at https://www.w3.org/Submission/CBD/#example | ||
g.parse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in a separate test function.
test/test_graph/test_graph_cbd.py
Outdated
PREFIX ex: <http://ex/> | ||
PREFIX dct: <http://purl.org/dc/terms/> | ||
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> | ||
PREFIX owl: <http://www.w3.org/2002/07/owl#> | ||
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> | ||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> | ||
PREFIX foaf: <http://xmlns.com/foaf/0.1/> | ||
PREFIX dc: <http://purl.org/dc/elements/1.1/> | ||
|
||
ex:aBookCritic ex:dislikes ex:anotherGreatBook ; | ||
ex:likes ex:aReallyGreatBook . | ||
|
||
[ a rdf:Statement ; | ||
rdf:object "image/jpeg" ; | ||
rdf:predicate dc:format ; | ||
rdf:subject foaf:Image ; | ||
rdfs:isDefinedBy ex:image-formats.rdf | ||
] . | ||
|
||
foaf:mbox a owl:InverseFunctionalProperty , rdf:Property . | ||
|
||
[ a rdf:Statement ; | ||
rdf:object "application/pdf" ; | ||
rdf:predicate dc:format ; | ||
rdf:subject ex:aReallyGreatBook ; | ||
rdfs:isDefinedBy ex:book-formats.rdf | ||
] . | ||
|
||
ex:aReallyGreatBook rdfs:seeAlso ex:anotherGreatBook ; | ||
dc:contributor [ a foaf:Person ; | ||
foaf:name "Jane Doe" | ||
] ; | ||
dc:creator [ a foaf:Person ; | ||
foaf:img ex:john.jpg ; | ||
foaf:mbox "[email protected]" ; | ||
foaf:name "John Doe" ; | ||
foaf:phone <tel:+1-999-555-1234> | ||
] ; | ||
dc:format "application/pdf" ; | ||
dc:language "en" ; | ||
dc:publisher "Examples-R-Us" ; | ||
dc:rights "Copyright (C) 2004 Examples-R-Us. All rights reserved." ; | ||
dc:title "A Really Great Book" ; | ||
dct:issued "2004-01-19"^^xsd:date . | ||
|
||
ex:anotherGreatBook rdfs:seeAlso ex:aReallyGreatBook ; | ||
dc:creator "June Doe ([email protected])" ; | ||
dc:format "application/pdf" ; | ||
dc:language "en" ; | ||
dc:publisher "Examples-R-Us" ; | ||
dc:rights "Copyright (C) 2004 Examples-R-Us. All rights reserved." ; | ||
dc:title "Another Great Book" ; | ||
dct:issued "2004-05-03"^^xsd:date . | ||
|
||
ex:john.jpg a foaf:Image ; | ||
dc:extent "1234" ; | ||
dc:format "image/jpeg" . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer this rather go into a file in test/data/spec/cbd/example_graph.rdf
as RDF XML (i.e. identical to what is here) and then place the "concise bounded description of http://example.com/aReallyGreatBook" in test/data/spec/cbd/example_graph_cbd.rdf
test/test_graph/test_graph_cbd.py
Outdated
assert len(g.cbd(EX.aReallyGreatBook)) == ( | ||
21 | ||
), "cbd() for aReallyGreatBook should return 21 triples" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not sufficent, this should check that the resulting graph from Graph.cbd
is isomorphic to and identical to (when discarding triples) the graph given in https://www.w3.org/Submission/CBD/#example
To do this you can use
GraphHelper.assert_isomorphic
and GraphHelper.assert_sets_equals(..., exclude_blanks=True)
for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review.
We have completed the above requirements. We have created a separate function for testing the CBD example along with all the above mentioned asserts, and also added two separate data files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for having a look at this @asejal - though please see the feedback.
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
test/test_graph/test_graph_cbd.py
Outdated
EXAMPLE_GRAPH_FILE_PATH = os.path.join(*[TEST_DATA_DIR, "spec", "cbd", "example_graph.rdf"]) | ||
EXAMPLE_GRAPH_CBD_FILE_PATH = os.path.join(*[TEST_DATA_DIR, "spec", "cbd", "example_graph_cbd.rdf"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is causing some failure:
test/test_graph/test_graph_cbd.py:9: error: No overload variant of "join" matches argument type "List[object]" [call-overload]
test/test_graph/test_graph_cbd.py:9: note: Possible overload variants:
test/test_graph/test_graph_cbd.py:9: note: def join(__a, Union[str, PathLike[str]], *paths: Union[str, PathLike[str]]) -> str
test/test_graph/test_graph_cbd.py:9: note: def join(__a, Union[bytes, PathLike[bytes]], *paths: Union[bytes, PathLike[bytes]]) -> bytes
test/test_graph/test_graph_cbd.py:10: error: No overload variant of "join" matches argument type "List[object]" [call-overload]
test/test_graph/test_graph_cbd.py:10: note: Possible overload variants:
test/test_graph/test_graph_cbd.py:10: note: def join(__a, Union[str, PathLike[str]], *paths: Union[str, PathLike[str]]) -> str
test/test_graph/test_graph_cbd.py:10: note: def join(__a, Union[bytes, PathLike[bytes]], *paths: Union[bytes, PathLike[bytes]]) -> bytes
Found 2 errors in 1 file (checked 299 source files)
The following should work:
EXAMPLE_GRAPH_FILE_PATH = os.path.join(*[TEST_DATA_DIR, "spec", "cbd", "example_graph.rdf"]) | |
EXAMPLE_GRAPH_CBD_FILE_PATH = os.path.join(*[TEST_DATA_DIR, "spec", "cbd", "example_graph_cbd.rdf"]) | |
EXAMPLE_GRAPH_FILE_PATH = TEST_DATA_DIR / "spec" / "cbd" / "example_graph.rdf" | |
EXAMPLE_GRAPH_CBD_FILE_PATH = TEST_DATA_DIR / "spec" / "cbd" / "example_graph_cbd.rdf" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good now, just some issue with the Paths.
test/test_graph/test_graph_cbd.py
Outdated
@@ -109,3 +122,21 @@ def testCbdReified(get_graph): | |||
) | |||
|
|||
assert len(g.cbd(EX.R6)) == (3 + 5 + 5), "cbd() for R6 should return 12 triples" | |||
|
|||
|
|||
def testCbdExample(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def testCbdExample(): | |
def test_cbd_example(): |
Function names should conform to PEP8[ref]:
https://peps.python.org/pep-0008/#function-and-variable-names
Function names should be lowercase, with words separated by underscores as necessary to improve readability.
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @asejal - very happy to have this in place.
Will wait for some more feedback but as this is just adding a test I think it is fine with one review, so I will merge it tomorrow unless there is more feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Hi @aucampia, since the pull request has been approved will it be possible for you to merge it? Thanks. |
Fixes #1914
Summary of changes
We have added a test for the example at the definition for Concise Bounded Definition here. It has been converted to turtle format for uniformity.
For the given RDF graph as input:
Expected output for CBD of
http://example.com/aReallyGreatBook
corresponds to the following subgraph:The test passes.
In collaboration with @ms1901.