-
Notifications
You must be signed in to change notification settings - Fork 543
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
fix for issue 1484 raised and solved by Graham Klyne: #1490
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import unittest | ||
import io | ||
import json | ||
from rdflib import Graph, RDF, RDFS, Namespace | ||
|
||
|
||
class TestIssue1484_json(unittest.TestCase): | ||
def test_issue_1484_json(self): | ||
""" | ||
Test JSON-LD parsing of result from json.dump | ||
""" | ||
n = Namespace("http://example.org/") | ||
jsondata = {"@id": n.s, "@type": [n.t], n.p: {"@id": n.o}} | ||
|
||
s = io.StringIO() | ||
json.dump(jsondata, s, indent=2, separators=(",", ": ")) | ||
s.seek(0) | ||
|
||
DEBUG = False | ||
if DEBUG: | ||
print("S: ", s.read()) | ||
s.seek(0) | ||
|
||
b = n.base | ||
g = Graph() | ||
g.bind("rdf", RDF) | ||
g.bind("rdfs", RDFS) | ||
g.parse(source=s, publicID=b, format="json-ld") | ||
|
||
assert (n.s, RDF.type, n.t) in g | ||
assert (n.s, n.p, n.o) in g | ||
|
||
|
||
class TestIssue1484_str(unittest.TestCase): | ||
def test_issue_1484_str(self): | ||
""" | ||
Test JSON-LD parsing of result from string (used by round tripping tests) | ||
|
||
(Previously passes, but broken by earlier fix for above.) | ||
""" | ||
n = Namespace("http://example.org/") | ||
jsonstr = """ | ||
{ | ||
"@id": "http://example.org/s", | ||
"@type": [ | ||
"http://example.org/t" | ||
], | ||
"http://example.org/p": { | ||
"@id": "http://example.org/o" | ||
} | ||
} | ||
""" | ||
|
||
b = n.base | ||
g = Graph() | ||
g.bind("rdf", RDF) | ||
g.bind("rdfs", RDFS) | ||
g.parse(data=jsonstr, publicID=b, format="json-ld") | ||
|
||
assert((n.s, RDF.type, n.t) in g) | ||
assert((n.s, n.p, n.o) in g) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm actually unsure if this condition will be true given this code from
rdflib.parser.FileInputSource
:rdflib/rdflib/parser.py
Lines 239 to 244 in 9379a69
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.
FWIW, I was trying to home in on the error that was triggered by trying to parse the output from
json.dump
, which specifically caused the stream result fromsource.getByteStream()
to be a character stream. I agree that seems not quite right, and the problem may lie deeper in the logic that sorts out the data stream to be parsed.But I was also trying to identify a minimal fix that could solve my immediate problem. Hopefully if someone chooses to delve deeper into the
create_input_source
logic, the test cases provided will still be helpful.