Ejemplo n.º 1
0
 def test_NTriplesParser_parsestring(self):
     p = ntriples.NTriplesParser()
     data = 3
     self.assertRaises(ntriples.ParseError, p.parsestring, data)
     fname = "test/nt/lists-02.nt"
     data = open(fname, 'r').read()
     p = ntriples.NTriplesParser()
     res = p.parsestring(data)
     self.assert_(res == None)
Ejemplo n.º 2
0
 def test_NTriplesParser_parsestring(self):
     p = ntriples.NTriplesParser()
     data = 3
     self.assertRaises(ntriples.ParseError, p.parsestring, data)
     fname = "test/nt/lists-02.nt"
     with open(fname, "r") as f:
         data = f.read()
     p = ntriples.NTriplesParser()
     res = p.parsestring(data)
     self.assertTrue(res == None)
Ejemplo n.º 3
0
    def test_bnode_distinct_across_instances(self):
        my_sink = FakeSink()
        p = ntriples.NTriplesParser(my_sink)
        p.parsestring('''
        _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000001> .
        ''')

        q = ntriples.NTriplesParser(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)
Ejemplo n.º 4
0
    def test_bnode_shared_across_instances(self):
        my_sink = FakeSink()
        bnode_context = dict()
        p = ntriples.NTriplesParser(my_sink, bnode_context=bnode_context)
        p.parsestring('''
        _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000001> .
        ''')

        q = ntriples.NTriplesParser(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)
Ejemplo n.º 5
0
 def test_cover_eat(self):
     data = (
         """<http://example.org/resource32> 3 <http://example.org/datatype1> .\n"""
     )
     p = ntriples.NTriplesParser()
     p.line = data
     self.assertRaises(ntriples.ParseError, p.eat,
                       re.compile("<http://example.org/datatype1>"))
Ejemplo n.º 6
0
 def test_w3_ntriple_variants(self):
     uri = "file:///" + os.getcwd() + "/test/nt/test.ntriples"
     import urllib
     parser = ntriples.NTriplesParser()
     u = urllib.urlopen(uri)
     sink = parser.parse(u)
     u.close()
     # ATM we are only really interested in any exceptions thrown
     self.assert_(sink is not None)
Ejemplo n.º 7
0
 def test_NTriplesParser_fpath(self):
     fpath = "test/nt/" + os.listdir('test/nt')[0]
     p = ntriples.NTriplesParser()
     self.assertRaises(ntriples.ParseError, p.parse, fpath)
Ejemplo n.º 8
0
def check_nt_parse(fpath, fmt):
    fp = open(fpath, 'rb')
    p = ntriples.NTriplesParser(sink=ntriples.Sink())
    sink = p.parse(fp)  # file; use parsestring for a string
    fp.close()
    assert (sink is not None)
Ejemplo n.º 9
0
 def test_cover_subjectobjectliteral(self):
     # data = '''<http://example.org/resource32> 3 <http://example.org/datatype1> .\n'''
     p = ntriples.NTriplesParser()
     p.line = b("baz")
     self.assertRaises(ntriples.ParseError, p.subject)
     self.assertRaises(ntriples.ParseError, p.object)
Ejemplo n.º 10
0
 def test_bad_line(self):
     data = '''<http://example.org/resource32> 3 <http://example.org/datatype1> .\n'''
     p = ntriples.NTriplesParser()
     self.assertRaises(ntriples.ParseError, p.parsestring, data)
Ejemplo n.º 11
0
 def test__no_EOF(self):
     data = '''<http://example.org/resource32> <http://example.org/property> <http://example.org/datatype1> .'''
     p = ntriples.NTriplesParser()
     self.assertRaises(ntriples.ParseError, p.parsestring, data)
Ejemplo n.º 12
0
 def test__no_EOF(self):
     data = '''<http://example.org/resource32> <http://example.org/property> <http://example.org/datatype1> .'''
     p = ntriples.NTriplesParser()