Adding tests for BNode contexts in NTriplesParser
@@ -130,5 +130,46 @@ class NTTestCase(unittest.TestCase):
# self.assertRaises(ntriples.ParseError, p.literal)
+class BNodeContextTestCase(unittest.TestCase):
+ def test_bnode_shared_across_parse(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> .
+ ''')
+
+ p = ntriples.NTriplesParser(my_sink, bnode_context=bnode_context)
+ p.parsestring('''
+ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000002> .
+ ''')
+
+ assert len(my_sink.subs) == 1
+
+ def test_bnode_distinct_across_parse(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> .
+ ''')
+
+ p = ntriples.NTriplesParser(my_sink)
+ p.parsestring('''
+ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000002> .
+ ''')
+
+ assert len(my_sink.subs) == 2
+
+
+class FakeSink(object):
+ def __init__(self):
+ self.subs = set()
+
+ def triple(self, s, p, o):
+ self.subs.add(s)
+
+
if __name__ == "__main__":
unittest.main()
