Esempio n. 1
0
 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)
Esempio n. 2
0
 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))
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
 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>"))
Esempio n. 6
0
    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)
Esempio n. 7
0
    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)
Esempio n. 8
0
    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)
Esempio n. 9
0
    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)
Esempio n. 10
0
 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)
Esempio n. 11
0
 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)
Esempio n. 12
0
 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)
Esempio n. 13
0
 def test_W3CNTriplesParser_fpath(self):
     fpath = "test/nt/" + os.listdir("test/nt")[0]
     p = ntriples.W3CNTriplesParser()
     self.assertRaises(ntriples.ParseError, p.parse, fpath)