from rdflib import Graph
from ktbs_bench.bnsparqlstore import SPARQLStore


class BenchableStore(Graph):
    def __init__(self, connect_args, create_func=None, create_args=[], *args, **kwargs):
        super(BenchableStore, self).__init__(*args, **kwargs)
        self.connect_args = connect_args
        self.create_func = create_func
        self.create_args = create_args

    def connect(self):
        if isinstance(self.connect_args, dict):
            self.open(**self.connect_args)
        else:
            raise TypeError("connect_args must be a dict.")

    def create(self):
        if self.create_func:
            self.create_func(*self.create_args)  # TODO gerer exception si db existe deja

    def destroy(self):
        """For SQL: destroy tables of the DB, not the DB itself."""
        if isinstance(self.store, SPARQLStore):
            self.sparql_destroy()
        else:
            super(BenchableStore, self).destroy(self.connect_args['configuration'])

    def sparql_destroy(self):
        """Try to destroy the graph as if the current store is a SPARQLStore."""
        # TODO improve destroy by using SPARQL CLEAR GRAPH if RDFLib supports it
        # or execute something on the command line
        for s, p, o in self:
            self.remove((s, p, o))

@@ -93,286 +93,343 @@
 tore
-(Graph):%0A    def __init__(self, connect_args, create_func=None, create_args=%5B%5D, *args, **kwargs):%0A        super(BenchableStore, self).__init__(*args, **kwargs)%0A        self.connect_args = connect_args%0A        self.create_func = create_func%0A        self.create_args = 
+:%0A    %22%22%22Allows to use a store/graph for benchmarks.%0A%0A    Contains a rdflib.Graph with setup and teardown.%0A    %22%22%22%0A%0A    def __init__(self, store, graph_id, store_config, store_create=False):%0A        self.graph = Graph(store=store, identifier=graph_id)%0A        self._store_config = store_config%0A        self._store_create = store_
 create
-_args
 %0A%0A  
@@ -450,409 +450,370 @@
 self
-):%0A        if isinstance(self.connect_args, dict):%0A            self.open(**self.connect_args)%0A        else:%0A            raise TypeError(%22connect_args must be a dict.%22)%0A%0A    def create(self):%0A        if self.create_func:%0A            self.create_func(*self.create_args)  # TODO gerer exception si db existe deja%0A%0A    def destroy(self):%0A        %22%22%22For SQL: destroy tables of the DB, not the DB itself.%22%22%22
+, store_create=None):%0A        if store_create:%0A            do_create = store_create%0A        else:%0A            do_create = self._store_create%0A        self.graph.open(self._store_config, create=do_create)%0A%0A    def close(self, commit_pending_transaction=False):%0A        self.graph.close(commit_pending_transaction=commit_pending_transaction)%0A%0A    def destroy(self):
 %0A   
@@ -836,16 +836,22 @@
 ce(self.
+graph.
 store, S
@@ -928,77 +928,44 @@
    s
-uper(BenchableStore, self).destroy(self.connect_args%5B'configuration'%5D
+elf.graph.destroy(self._store_config
 )%0A%0A 
@@ -1233,16 +1233,22 @@
  in self
+.graph
 :%0A      
@@ -1258,16 +1258,22 @@
    self.
+graph.
 remove((

Make Graph an attribute rather than an inheritance