def test_W3CNTriplesParser_parsestring(self): p = ntriples.W3CNTriplesParser() data = 3 self.assertRaises(ntriples.ParseError, p.parsestring, data) with open(nt_file("lists-02.nt"), "r") as f: data = f.read() p = ntriples.W3CNTriplesParser() res = p.parsestring(data) self.assertTrue(res == None)
def testIssue1144_w3c(self): fname = "test/nt/lists-02.nt" sink1 = ntriples.NTGraphSink(Graph()) p1 = ntriples.W3CNTriplesParser(sink1) with open(fname, "r") as f: p1.parse(f) self.assertEqual(14, len(sink1.g)) sink2 = ntriples.NTGraphSink(Graph()) p2 = ntriples.W3CNTriplesParser(sink2) with open(fname, "rb") as f: p2.parse(f) self.assertEqual(14, len(sink2.g))
def test_bnode_distinct_across_instances(self): my_sink = FakeSink() p = ntriples.W3CNTriplesParser(my_sink) p.parsestring(""" _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000001> . """) q = ntriples.W3CNTriplesParser(my_sink) q.parsestring(""" _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000002> . """) self.assertEqual(len(my_sink.subs), 2)
def test_bnode_shared_across_instances(self): my_sink = FakeSink() bnode_context = dict() p = ntriples.W3CNTriplesParser(my_sink, bnode_context=bnode_context) p.parsestring(''' _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000001> . ''') q = ntriples.W3CNTriplesParser(my_sink, bnode_context=bnode_context) q.parsestring(''' _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000002> . ''') self.assertEqual(len(my_sink.subs), 1)
def test_cover_eat(self): data = ( """<http://example.org/resource32> 3 <http://example.org/datatype1> .\n""" ) p = ntriples.W3CNTriplesParser() p.line = data self.assertRaises(ntriples.ParseError, p.eat, re.compile("<http://example.org/datatype1>"))
def test_w3_ntriple_variants(self): uri = Path(nt_file("test.ntriples")).absolute().as_uri() parser = ntriples.W3CNTriplesParser() u = urlopen(uri) sink = parser.parse(u) u.close() # ATM we are only really interested in any exceptions thrown self.assertTrue(sink is not None)
def test_w3_ntriple_variants(self): uri = "file:///" + os.getcwd() + "/test/nt/test.ntriples" parser = ntriples.W3CNTriplesParser() u = urlopen(uri) sink = parser.parse(u) u.close() # ATM we are only really interested in any exceptions thrown self.assertTrue(sink is not None)
def test_bnode_shared_across_instances_with_parse_option(self): my_sink = FakeSink() bnode_ctx = dict() p = ntriples.W3CNTriplesParser(my_sink) p.parsestring( """ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000001> . """, bnode_context=bnode_ctx, ) q = ntriples.W3CNTriplesParser(my_sink) q.parsestring( """ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000002> . """, bnode_context=bnode_ctx, ) self.assertEqual(len(my_sink.subs), 1)
def test_bnode_distinct_across_parse(self): my_sink = FakeSink() p = ntriples.W3CNTriplesParser(my_sink) p.parsestring(''' _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000001> . ''', bnode_context=dict()) p.parsestring(''' _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000002> . ''', bnode_context=dict()) self.assertEqual(len(my_sink.subs), 2)
def test_cover_subjectobjectliteral(self): # data = '''<http://example.org/resource32> 3 <http://example.org/datatype1> .\n''' p = ntriples.W3CNTriplesParser() p.line = "baz" self.assertRaises(ntriples.ParseError, p.subject) self.assertRaises(ntriples.ParseError, p.object)
def test_bad_line(self): data = ( """<http://example.org/resource32> 3 <http://example.org/datatype1> .\n""" ) p = ntriples.W3CNTriplesParser() self.assertRaises(ntriples.ParseError, p.parsestring, data)
def test_W3CNTriplesParser_fpath(self): fpath = os.path.join(nt_file(os.listdir(NT_PATH)[0])) p = ntriples.W3CNTriplesParser() self.assertRaises(ntriples.ParseError, p.parse, fpath)
def test_W3CNTriplesParser_fpath(self): fpath = "test/nt/" + os.listdir("test/nt")[0] p = ntriples.W3CNTriplesParser() self.assertRaises(ntriples.ParseError, p.parse, fpath)