def testSubclassNameAppearsInRepr(self): class MyURIRef(URIRef): pass x = MyURIRef('http://example.com/') self.assertEqual(repr(x), uformat("MyURIRef(%(u)s'http://example.com/')"))
uformat(""" This parser will read in an JSON-LD formatted document and create an RDF Graph. See: http://json-ld.org/ Example usage:: >>> from rdflib import Graph, URIRef, Literal >>> test_json = ''' ... { ... "@context": { ... "dc": "http://purl.org/dc/terms/", ... "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", ... "rdfs": "http://www.w3.org/2000/01/rdf-schema#" ... }, ... "@id": "http://example.org/about", ... "dc:title": { ... "@language": "en", ... "@literal": "Someone's Homepage" ... } ... } ... ''' >>> g = Graph().parse(data=test_json, format='json-ld') >>> list(g) == [(URIRef('http://example.org/about'), ... URIRef('http://purl.org/dc/terms/title'), ... Literal(%(u)s"Someone's Homepage", lang=%(u)s'en'))] True """ )
def testSubclassNameAppearsInRepr(self): class MyLiteral(Literal): pass x = MyLiteral(u"foo") self.assertEqual(repr(x), uformat("MyLiteral(%(u)s'foo')"))
def testOmitsMissingDatatype(self): self.assertEqual(repr(Literal("foo", lang='en')), uformat("rdflib.term.Literal(%(u)s'foo', lang='en')"))
def testOmitsMissingLang(self): self.assertEqual( repr(Literal("foo", datatype=URIRef('http://example.com/'))), uformat( "rdflib.term.Literal(%(u)s'foo', datatype=rdflib.term.URIRef(%(u)s'http://example.com/'))" ))
def testOmitsMissingDatatypeAndLang(self): self.assertEqual(repr(Literal("foo")), uformat("rdflib.term.Literal(%(u)s'foo')"))
def testOmitsMissingLang(self): self.assertEqual( repr(Literal("foo", datatype=URIRef('http://example.com/'))), uformat("rdflib.term.Literal(%(u)s'foo', datatype=rdflib.term.URIRef(%(u)s'http://example.com/'))"))
from rdflib.py3compat import format_doctest_out as uformat uformat(""" This parser will read in an JSON-LD formatted document and create an RDF Graph. See: http://json-ld.org/ Example usage:: >>> from rdflib import Graph, URIRef, Literal >>> test_json = ''' ... { ... "@context": { ... "dc": "http://purl.org/dc/terms/", ... "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", ... "rdfs": "http://www.w3.org/2000/01/rdf-schema#" ... }, ... "@id": "http://example.org/about", ... "dc:title": { ... "@language": "en", ... "@literal": "Someone's Homepage" ... } ... } ... ''' >>> g = Graph().parse(data=test_json, format='json-ld') >>> list(g) == [(URIRef('http://example.org/about'), ... URIRef('http://purl.org/dc/terms/title'), ... Literal(%(u)s"Someone's Homepage", lang=%(u)s'en'))] True """) # NOTE: This code reads the entire JSON object into memory before parsing, but