<commit_before>import unittest

from rdflib.Graph import Graph
from rdflib import URIRef

import gc
import itertools
from time import time
from random import random

from tempfile import mkdtemp

def random_uri():
    return URIRef("%s" % random())

class StoreTestCase(unittest.TestCase):
    """
    Test case for testing store performance... probably should be
    something other than a unit test... but for now we'll add it as a
    unit test.
    """
    backend = 'default'

    def setUp(self):
        print self.backend
        self.gcold = gc.isenabled()
        gc.collect()
        gc.disable()
        self.store = Graph(backend=self.backend)
        path = a_tmp_dir = mkdtemp()
        self.store.open(path)

    def tearDown(self):
        self.store.close()
        if self.gcold:
            gc.enable()
        # TODO: delete a_tmp_dir
        del self.store

    def testTime(self):
        number = 3
        it = itertools.repeat(None, number)        
	for i in it:
	    self._testTime()
        print "."

    def _testTime(self):
        number = 1000
        store = self.store

        def add_random():
	    s = random_uri()
	    p = random_uri()
	    o = random_uri()
            store.add((s, p, o))

        it = itertools.repeat(None, number)
        t0 = time()
        for _i in it:
	    add_random()
        t1 = time()
        print "%.3g" % (t1 - t0),


class MemoryStoreTestCase(StoreTestCase):
    backend = "Memory"

try:
    from rdflib.backends.Sleepycat import Sleepycat
    class SleepycatStoreTestCase(StoreTestCase):
        backend = "Sleepycat"
except ImportError, e:
    print "Can not test Sleepycat backend:", e

try:
    import persistent
    # If we can import persistent then test ZODB backend
    class ZODBStoreTestCase(StoreTestCase):
        backend = "ZODB"
except ImportError, e:<commit_msg>moved one of the prints<commit_after>import unittest

from rdflib.Graph import Graph
from rdflib import URIRef

import gc
import itertools
from time import time
from random import random

from tempfile import mkdtemp

def random_uri():
    return URIRef("%s" % random())

class StoreTestCase(unittest.TestCase):
    """
    Test case for testing store performance... probably should be
    something other than a unit test... but for now we'll add it as a
    unit test.
    """
    backend = 'default'

    def setUp(self):
        self.gcold = gc.isenabled()
        gc.collect()
        gc.disable()
        self.store = Graph(backend=self.backend)
        path = a_tmp_dir = mkdtemp()
        self.store.open(path)

    def tearDown(self):
        self.store.close()
        if self.gcold:
            gc.enable()
        # TODO: delete a_tmp_dir
        del self.store

    def testTime(self):
        number = 3
        it = itertools.repeat(None, number)        
	for i in it:
	    self._testTime()
        print "."

    def _testTime(self):
        number = 1000
        store = self.store

        def add_random():
	    s = random_uri()
	    p = random_uri()
	    o = random_uri()
            store.add((s, p, o))

        it = itertools.repeat(None, number)
        t0 = time()
        for _i in it:
	    add_random()
        t1 = time()
        print self.backend, "%.3g" % (t1 - t0),


class MemoryStoreTestCase(StoreTestCase):
    backend = "Memory"

try:
    from rdflib.backends.Sleepycat import Sleepycat
    class SleepycatStoreTestCase(StoreTestCase):
        backend = "Sleepycat"
except ImportError, e:
    print "Can not test Sleepycat backend:", e

try:
    import persistent
    # If we can import persistent then test ZODB backend
    class ZODBStoreTestCase(StoreTestCase):
        backend = "ZODB"
except ImportError, e:
{'fraction_non_alphanumeric': 0.0948905109489051, 'fraction_numerical': 0.005406866720735334, 'mean_word_length': 2.2685512367491167, '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': '4762283', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1119, 'n_words': 348}