Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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>"))
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio n. 12
0
 def test__no_EOF(self):
     data = '''<http://example.org/resource32> <http://example.org/property> <http://example.org/datatype1> .'''
     p = ntriples.NTriplesParser()