diff --git a/rdflib_jsonld/serializer.py b/rdflib_jsonld/serializer.py index 36d9d03..6815ffd 100644 --- a/rdflib_jsonld/serializer.py +++ b/rdflib_jsonld/serializer.py @@ -10,6 +10,7 @@ >>> register('json-ld', Serializer, 'rdflib_jsonld.serializer', 'JsonLDSerializer') >>> from rdflib import Graph + >>> from rdflib import __version__ as rdflib_version >>> testrdf = ''' ... @prefix dcterms: . @@ -19,7 +20,12 @@ >>> g = Graph().parse(data=testrdf, format='n3') - >>> print(g.serialize(format='json-ld', indent=4).decode()) + >>> g_display = g.serialize(format='json-ld', indent=4) + >>> if rdflib_version < "6.0.0": + ... # rdflib < 6.0.0 returns bytes when no + ... # destination is provided. + ... g_display = g_display.decode() + >>> print(g_display) [ { "@id": "http://example.org/about", diff --git a/setup.py b/setup.py index 1ac76e6..bd5e09f 100644 --- a/setup.py +++ b/setup.py @@ -77,7 +77,6 @@ def md2pypi(filename): url="https://github.com/RDFLib/rdflib-jsonld", license="BSD", packages=["rdflib_jsonld"], - use_2to3=True, zip_safe=False, platforms=["any"], classifiers=[ @@ -93,7 +92,7 @@ def md2pypi(filename): "Natural Language :: English", ], test_suite="nose.collector", - install_requires=["rdflib>=5.0.0"], + install_requires=["rdflib"], tests_require=["nose"], command_options={ "build_sphinx": { diff --git a/test/runner.py b/test/runner.py index 4d2452d..5cd51b1 100644 --- a/test/runner.py +++ b/test/runner.py @@ -1,5 +1,6 @@ from __future__ import with_statement import json +import rdflib from rdflib import ConjunctiveGraph from rdflib.compare import isomorphic from rdflib_jsonld._compat import IS_PY3 @@ -9,14 +10,25 @@ # monkey-patch NTriplesParser to keep source bnode id:s .. -from rdflib.plugins.parsers.ntriples import NTriplesParser, r_nodeid, bNode - - -def _preserving_nodeid(self): - if not self.peek("_"): - return False - return bNode(self.eat(r_nodeid).group(1)) - +from rdflib.plugins.parsers.ntriples import r_nodeid, bNode +# NTriplesParser was renamed between 5.0.0 and 6.0.0. +if rdflib.__version__ < "6": + from rdflib.plugins.parsers.ntriples import NTriplesParser +else: + from rdflib.plugins.parsers.ntriples import W3CNTriplesParser as NTriplesParser + + +# NTriplesParser.nodeid changed its function signature between 5.0.0 and 6.0.0. +if rdflib.__version__ < "6": + def _preserving_nodeid(self): + if not self.peek("_"): + return False + return bNode(self.eat(r_nodeid).group(1)) +else: + def _preserving_nodeid(self, bnode_context=None): + if not self.peek("_"): + return False + return bNode(self.eat(r_nodeid).group(1)) NTriplesParser.nodeid = _preserving_nodeid # .. and accept bnodes everywhere diff --git a/test/test_compaction.py b/test/test_compaction.py index 6a77dae..e34b312 100644 --- a/test/test_compaction.py +++ b/test/test_compaction.py @@ -233,7 +233,9 @@ def case(*args): def run(data, expected): g = Graph().parse(data=data, format="turtle") - result = g.serialize(format="json-ld", context=expected["@context"]).decode("utf-8") + result = g.serialize(format="json-ld", context=expected["@context"]) + if isinstance(result, bytes): + result = result.decode("utf-8") result = json.loads(result) sort_graph(result)