Beispiel #1
0
    def testRemoveTriple(self):
        g = Graph()
        g.addTriple(subject='u:ri', predicate='p:redicate', object='obj')
        g.addTriple(subject='u:ri', predicate='p:redicate', object='obj2')

        self.assertEquals(2, len(list(g.triples())))
        self.assertEquals(12, len(g._tripleDict))  # Whitebox no-leaking defaultdict entries on delete

        g.removeTriple(subject='u:ri', predicate='p:redicate', object='obj2')

        self.assertEquals(8, len(g._tripleDict))  # Whitebox no-leaking defaultdict entries on delete

        # Keep 1
        self.assertEquals(1, len(list(g.triples())))
        self.assertEquals(1, len(list(g.triples(None, None, None))))
        self.assertEquals(1, len(list(g.triples(None, None, 'obj'))))
        self.assertEquals(1, len(list(g.triples(None, 'p:redicate', None))))
        self.assertEquals(1, len(list(g.triples(None, 'p:redicate', 'obj'))))
        self.assertEquals(1, len(list(g.triples('u:ri', None, None))))
        self.assertEquals(1, len(list(g.triples('u:ri', None, 'obj'))))
        self.assertEquals(1, len(list(g.triples('u:ri', 'p:redicate', None))))
        self.assertEquals(1, len(list(g.triples('u:ri', 'p:redicate', 'obj'))))

        # Kill 1
        self.assertEquals(0, len(list(g.triples(None, None, 'obj2'))))
        self.assertEquals(0, len(list(g.triples(None, 'p:redicate', 'obj2'))))
        self.assertEquals(0, len(list(g.triples('u:ri', 'p:redicate', 'obj2'))))
Beispiel #2
0
    def testRemoveTripleOfNonExistingDoesNotLeak(self):
        g = Graph()

        self.assertEquals(0, len(list(g.triples())))
        self.assertEquals(0, len(g._tripleDict))  # Whitebox no-leaking defaultdict entries on delete

        g.removeTriple(subject='u:ri', predicate='p:redicate', object='obj2')

        self.assertEquals(0, len(g._tripleDict))  # Whitebox no-leaking defaultdict entries on delete