Skip to content

Commit 96de0d7

Browse files
committed
Adding a test for length of a graph after a call to add with a duplicate triple
1 parent 42f5008 commit 96de0d7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

test/graph_case.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,37 +338,51 @@ def test_type_add(self):
338338
trip = (URIRef('http://example.org#type-add'), RDF.type, URIRef('http://example.org/cra'))
339339
self.graph.add(trip)
340340
self.graph.add(trip)
341+
# No exception raised
341342

342343
def test_type_addn(self):
343344
quad = (URIRef('http://example.org#type-addn'), RDF.type, URIRef('http://example.org/cra'), self.graph)
344345
self.graph.addN([quad, quad])
346+
# No exception raised
345347

346348
def test_add(self):
347349
trip = (URIRef('http://example.org#add'), URIRef('http://example.org/blah'), URIRef('http://example.org/cra'))
348350
self.graph.add(trip)
349351
self.graph.add(trip)
352+
# No exception raised
350353

351354
def test_addn(self):
352355
quad = (URIRef('http://example.org#addn'),
353356
URIRef('http://example.org/blah'),
354357
URIRef('http://example.org/cra'),
355358
self.graph)
356359
self.graph.addN([quad, quad])
360+
# No exception raised
357361

358362
def test_namespace_change_prefix_binding(self):
359363
nm = self.graph.namespace_manager
360364
nm.bind('change_binding', URIRef('http://example.org/change-binding-1#'),
361365
replace=True)
362366
nm.bind('change_binding', URIRef('http://example.org/change-binding-2#'),
363367
replace=True)
364-
assert ('change_binding',
365-
URIRef('http://example.org/change-binding-2#')) in list(nm.namespaces())
368+
self.assertIn(
369+
('change_binding', URIRef('http://example.org/change-binding-2#')),
370+
list(nm.namespaces())
371+
)
366372

367373
def test_namespace_rebind_prefix(self):
368374
nm = self.graph.namespace_manager
369375
nm.bind('rebind', URIRef('http://example.org/rebind#'))
370376
nm.bind('rebind', URIRef('http://example.org/rebind#'))
371377

378+
def test_add_duplicate_length(self):
379+
'''
380+
Test that adding duplicate triples doesn't increase the length of the graph
381+
'''
382+
trip = (URIRef('http://example.org#add'), URIRef('http://example.org/blah'), URIRef('http://example.org/cra'))
383+
self.graph.add(trip)
384+
self.graph.add(trip)
385+
self.assertEqual(len(self.graph), 1)
372386
# additional tests
373387
# - add "duplicate" triples and query -- ensure the graph length counts only distinct
374388
# triples

0 commit comments

Comments
 (0)