diff options
author | Dave Challis <suicas@gmail.com> | 2014-10-30 16:26:18 +0000 |
---|---|---|
committer | Gunnar Aastrand Grimnes <gromgull@users.noreply.github.com> | 2017-01-24 15:04:10 +0100 |
commit | ff7957020ebb242333c8416b743507e94d8f4765 (patch) | |
tree | fcd316aeda0f75bab1d1b3a20cdf787c053ca567 | |
parent | fa3271d99371e13a85d2420085186dfba893c98c (diff) | |
download | rdflib-ff7957020ebb242333c8416b743507e94d8f4765.tar.gz |
Added additional trig unit tests to highlight some currently occurring issues.
-rw-r--r-- | test/test_trig.py | 71 | ||||
-rw-r--r-- | test/test_trig_export.py | 23 |
2 files changed, 93 insertions, 1 deletions
diff --git a/test/test_trig.py b/test/test_trig.py index 33fa7bed..d4d0a9eb 100644 --- a/test/test_trig.py +++ b/test/test_trig.py @@ -80,5 +80,74 @@ class TestTrig(unittest.TestCase): g.add(TRIPLE + (rdflib.BNode(),)) out = g.serialize(format='trig') graph_label_line = out.splitlines()[-4] + self.assertTrue(re.match(br'^_:[a-zA-Z0-9]+ \{', graph_label_line)) - + + def testGraphParsing(self): + # should parse into single default graph context + data = """ +<http://example.com/thing#thing_a> <http://example.com/knows> <http://example.com/thing#thing_b> . +""" + g = rdflib.ConjunctiveGraph() + g.parse(data=data, format='trig') + self.assertEqual(len(list(g.contexts())), 1) + + # should parse into single default graph context + data = """ +<http://example.com/thing#thing_a> <http://example.com/knows> <http://example.com/thing#thing_b> . + +{ <http://example.com/thing#thing_c> <http://example.com/knows> <http://example.com/thing#thing_d> . } +""" + g = rdflib.ConjunctiveGraph() + g.parse(data=data, format='trig') + self.assertEqual(len(list(g.contexts())), 1) + + # should parse into 2 contexts, one default, one named + data = """ +<http://example.com/thing#thing_a> <http://example.com/knows> <http://example.com/thing#thing_b> . + +{ <http://example.com/thing#thing_c> <http://example.com/knows> <http://example.com/thing#thing_d> . } + +<http://example.com/graph#graph_a> { + <http://example.com/thing/thing_e> <http://example.com/knows> <http://example.com/thing#thing_f> . +} +""" + g = rdflib.ConjunctiveGraph() + g.parse(data=data, format='trig') + self.assertEqual(len(list(g.contexts())), 2) + + def testRoundTrips(self): + data = """ +<http://example.com/thing#thing_a> <http://example.com/knows> <http://example.com/thing#thing_b> . + +{ <http://example.com/thing#thing_c> <http://example.com/knows> <http://example.com/thing#thing_d> . } + +<http://example.com/graph#graph_a> { + <http://example.com/thing/thing_e> <http://example.com/knows> <http://example.com/thing#thing_f> . +} +""" + g = rdflib.ConjunctiveGraph() + for i in range(5): + g.parse(data=data, format='trig') + data = g.serialize(format='trig') + + # output should only contain 1 mention of each resource/graph name + self.assertEqual(data.count('thing_a'), 1) + self.assertEqual(data.count('thing_b'), 1) + self.assertEqual(data.count('thing_c'), 1) + self.assertEqual(data.count('thing_d'), 1) + self.assertEqual(data.count('thing_e'), 1) + self.assertEqual(data.count('thing_f'), 1) + self.assertEqual(data.count('graph_a'), 1) + + def testDefaultGraphSerializesWithoutName(self): + data = """ +<http://example.com/thing#thing_a> <http://example.com/knows> <http://example.com/thing#thing_b> . + +{ <http://example.com/thing#thing_c> <http://example.com/knows> <http://example.com/thing#thing_d> . } +""" + g = rdflib.ConjunctiveGraph() + g.parse(data=data, format='trig') + data = g.serialize(format='trig') + + self.assertTrue('None' not in data) diff --git a/test/test_trig_export.py b/test/test_trig_export.py new file mode 100644 index 00000000..6cf82fde --- /dev/null +++ b/test/test_trig_export.py @@ -0,0 +1,23 @@ +from rdflib import URIRef, Literal, Graph, Dataset + +def trig_export_test(): + graphs = [(URIRef("urn:tg1"),"A"), (URIRef("urn:tg2"), "B")] + ds = Dataset() + for i, n in graphs: + g = ds.graph(i) + a = URIRef("urn:{}#S".format(n)) + b = URIRef("urn:{}#p".format(n)) + c = Literal('c') + g.add((a,b,c)) + + + # this generated two graphs, with a differnet namespace for the URIs inside. + # this tests that the prefix for each internal ns is different + + data = ds.serialize(format='trig') + print data + assert False + + +if __name__ == '__main__': + trig_export_test() |