<commit_before>import unittest

from rdflib import *

class GraphTestCase(unittest.TestCase):
    backend = 'default'
    
    def setUp(self):
        self.store = Graph(backend=self.backend)
        self.store.open("store")
        self.michel = URIRef(u'michel')
        self.tarek = URIRef(u'tarek')
        self.bob = URIRef(u'bob')
        self.likes = URIRef(u'likes')
        self.hates = URIRef(u'hates')
        self.pizza = URIRef(u'pizza')
        self.cheese = URIRef(u'cheese')

    def addStuff(self):
        tarek = self.tarek
        michel = self.michel
        bob = self.bob
        likes = self.likes
        hates = self.hates
        pizza = self.pizza
        cheese = self.cheese

        self.store.add((tarek, likes, pizza))
        self.store.add((tarek, likes, cheese))
        self.store.add((michel, likes, pizza))
        self.store.add((michel, likes, cheese))
        self.store.add((bob, likes, cheese))
        self.store.add((bob, hates, pizza))
        self.store.add((bob, hates, michel)) # gasp!        

    def removeStuff(self):
        tarek = self.tarek
        michel = self.michel
        bob = self.bob
        likes = self.likes
        hates = self.hates
        pizza = self.pizza
        cheese = self.cheese

        self.store.remove((tarek, likes, pizza))
        self.store.remove((tarek, likes, cheese))
        self.store.remove((michel, likes, pizza))
        self.store.remove((michel, likes, cheese))
        self.store.remove((bob, likes, cheese))
        self.store.remove((bob, hates, pizza))
        self.store.remove((bob, hates, michel)) # gasp!

    def testAdd(self):
        self.addStuff()

    def testRemove(self):
        self.addStuff()
        self.removeStuff()

    def testTriples(self):
        tarek = self.tarek
        michel = self.michel
        bob = self.bob
        likes = self.likes
        hates = self.hates
        pizza = self.pizza
        cheese = self.cheese
        asserte = self.assertEquals
        triples = self.store.triples
        Any = None

        self.addStuff()

        # unbound subjects
        asserte(len(list(triples((Any, likes, pizza)))), 2)
        asserte(len(list(triples((Any, hates, pizza)))), 1)
        asserte(len(list(triples((Any, likes, cheese)))), 3)
        asserte(len(list(triples((Any, hates, cheese)))), 0)

        # unbound objects
        asserte(len(list(triples((michel, likes, Any)))), 2)
        asserte(len(list(triples((tarek, likes, Any)))), 2)
        asserte(len(list(triples((bob, hates, Any)))), 2)
        asserte(len(list(triples((bob, likes, Any)))), 1)

        # unbound predicates
        asserte(len(list(triples((michel, Any, cheese)))), 1)
        asserte(len(list(triples((tarek, Any, cheese)))), 1)
        asserte(len(list(triples((bob, Any, pizza)))), 1)
        asserte(len(list(triples((bob, Any, michel)))), 1)

        # unbound subject, objects
        asserte(len(list(triples((Any, hates, Any)))), 2)
        asserte(len(list(triples((Any, likes, Any)))), 5)

        # unbound predicates, objects
        asserte(len(list(triples((michel, Any, Any)))), 2)
        asserte(len(list(triples((bob, Any, Any)))), 3)
        asserte(len(list(triples((tarek, Any, Any)))), 2)        

        # unbound subjects, predicates
        asserte(len(list(triples((Any, Any, pizza)))), 3)
        asserte(len(list(triples((Any, Any, cheese)))), 3)
        asserte(len(list(triples((Any, Any, michel)))), 1)        

        # all unbound
        asserte(len(list(triples((Any, Any, Any)))), 7)
        self.removeStuff()
        asserte(len(list(triples((Any, Any, Any)))), 0)

class MemoryGraphTestCase(GraphTestCase):
    backend = "Memory"

class SleepycatGraphTestCase(GraphTestCase):
    backend = "Sleepycat"

try:
    import persistent
    # If we can import persistent then test ZODB backend
    class ZODBGraphTestCase(GraphTestCase):
        backend = "ZODB"
except ImportError:
    pass


if __name__ == '__main__':
    unittest.main()    <commit_msg>only test Sleepycat backend if Sleepycat is installed<commit_after>import unittest

from rdflib import *

class GraphTestCase(unittest.TestCase):
    backend = 'default'
    
    def setUp(self):
        self.store = Graph(backend=self.backend)
        self.store.open("store")
        self.michel = URIRef(u'michel')
        self.tarek = URIRef(u'tarek')
        self.bob = URIRef(u'bob')
        self.likes = URIRef(u'likes')
        self.hates = URIRef(u'hates')
        self.pizza = URIRef(u'pizza')
        self.cheese = URIRef(u'cheese')

    def addStuff(self):
        tarek = self.tarek
        michel = self.michel
        bob = self.bob
        likes = self.likes
        hates = self.hates
        pizza = self.pizza
        cheese = self.cheese

        self.store.add((tarek, likes, pizza))
        self.store.add((tarek, likes, cheese))
        self.store.add((michel, likes, pizza))
        self.store.add((michel, likes, cheese))
        self.store.add((bob, likes, cheese))
        self.store.add((bob, hates, pizza))
        self.store.add((bob, hates, michel)) # gasp!        

    def removeStuff(self):
        tarek = self.tarek
        michel = self.michel
        bob = self.bob
        likes = self.likes
        hates = self.hates
        pizza = self.pizza
        cheese = self.cheese

        self.store.remove((tarek, likes, pizza))
        self.store.remove((tarek, likes, cheese))
        self.store.remove((michel, likes, pizza))
        self.store.remove((michel, likes, cheese))
        self.store.remove((bob, likes, cheese))
        self.store.remove((bob, hates, pizza))
        self.store.remove((bob, hates, michel)) # gasp!

    def testAdd(self):
        self.addStuff()

    def testRemove(self):
        self.addStuff()
        self.removeStuff()

    def testTriples(self):
        tarek = self.tarek
        michel = self.michel
        bob = self.bob
        likes = self.likes
        hates = self.hates
        pizza = self.pizza
        cheese = self.cheese
        asserte = self.assertEquals
        triples = self.store.triples
        Any = None

        self.addStuff()

        # unbound subjects
        asserte(len(list(triples((Any, likes, pizza)))), 2)
        asserte(len(list(triples((Any, hates, pizza)))), 1)
        asserte(len(list(triples((Any, likes, cheese)))), 3)
        asserte(len(list(triples((Any, hates, cheese)))), 0)

        # unbound objects
        asserte(len(list(triples((michel, likes, Any)))), 2)
        asserte(len(list(triples((tarek, likes, Any)))), 2)
        asserte(len(list(triples((bob, hates, Any)))), 2)
        asserte(len(list(triples((bob, likes, Any)))), 1)

        # unbound predicates
        asserte(len(list(triples((michel, Any, cheese)))), 1)
        asserte(len(list(triples((tarek, Any, cheese)))), 1)
        asserte(len(list(triples((bob, Any, pizza)))), 1)
        asserte(len(list(triples((bob, Any, michel)))), 1)

        # unbound subject, objects
        asserte(len(list(triples((Any, hates, Any)))), 2)
        asserte(len(list(triples((Any, likes, Any)))), 5)

        # unbound predicates, objects
        asserte(len(list(triples((michel, Any, Any)))), 2)
        asserte(len(list(triples((bob, Any, Any)))), 3)
        asserte(len(list(triples((tarek, Any, Any)))), 2)        

        # unbound subjects, predicates
        asserte(len(list(triples((Any, Any, pizza)))), 3)
        asserte(len(list(triples((Any, Any, cheese)))), 3)
        asserte(len(list(triples((Any, Any, michel)))), 1)        

        # all unbound
        asserte(len(list(triples((Any, Any, Any)))), 7)
        self.removeStuff()
        asserte(len(list(triples((Any, Any, Any)))), 0)

class MemoryGraphTestCase(GraphTestCase):
    backend = "Memory"

 try:
     import backends.Sleepycat
     class SleepycatGraphTestCase(GraphTestCase):
         backend = "Sleepycat"
 except ImportError:
     pass

try:
    import persistent
    # If we can import persistent then test ZODB backend
    class ZODBGraphTestCase(GraphTestCase):
        backend = "ZODB"
except ImportError:
    pass


if __name__ == '__main__':
    unittest.main()    
{'fraction_non_alphanumeric': 0.14424019607843136, 'fraction_numerical': 0.005392156862745098, 'mean_word_length': 2.4772049424797613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6835271', 'n_tokens_mistral': 2842, 'n_tokens_neox': 2665, 'n_words': 555}