<s> import sys <EOL> import os <EOL> from tempfile import mkdtemp , mkstemp <EOL> from rdflib import RDF , RDFS , URIRef , BNode , Variable , plugin <EOL> from rdflib . graph import QuotedGraph , ConjunctiveGraph <EOL> implies = URIRef ( "<STR_LIT>" ) <EOL> testN3 = """<STR_LIT>""" <EOL> from nose . tools import nottest <EOL> from nose . exc import SkipTest <EOL> @ nottest <EOL> def testFormulaStore ( store = "<STR_LIT:default>" , configString = None ) : <EOL> try : <EOL> g = ConjunctiveGraph ( store = store ) <EOL> except ImportError : <EOL> raise SkipTest ( "<STR_LIT>" % store ) <EOL> if configString : <EOL> g . destroy ( configString ) <EOL> g . open ( configString ) <EOL> else : <EOL> if store == '<STR_LIT>' : <EOL> _ , path = mkstemp ( prefix = '<STR_LIT:test>' , dir = '<STR_LIT>' , suffix = '<STR_LIT>' ) <EOL> g . open ( path , create = True ) <EOL> else : <EOL> g . open ( mkdtemp ( ) , create = True ) <EOL> g . parse ( data = testN3 , format = "<STR_LIT>" ) <EOL> try : <EOL> for s , p , o in g . triples ( ( None , implies , None ) ) : <EOL> formulaA = s <EOL> formulaB = o <EOL> assert type ( formulaA ) == QuotedGraph and type ( formulaB ) == QuotedGraph <EOL> b = URIRef ( '<STR_LIT>' ) <EOL> c = URIRef ( '<STR_LIT>' ) <EOL> d = URIRef ( '<STR_LIT>' ) <EOL> v = Variable ( '<STR_LIT:y>' ) <EOL> universe = ConjunctiveGraph ( g . store ) <EOL> assert len ( list ( universe . triples ( ( formulaA , implies , formulaB ) ) ) ) == <NUM_LIT:1> <EOL> assert len ( list ( formulaB . triples ( ( None , None , v ) ) ) ) == <NUM_LIT:1> <EOL> for s , p , o in formulaB . triples ( ( None , d , None ) ) : <EOL> if o != c : <EOL> assert isinstance ( o , Variable ) <EOL> assert o == v <EOL> s = list ( universe . subjects ( RDF . type , RDFS . Class ) ) [ <NUM_LIT:0> ] <EOL> assert isinstance ( s , BNode ) <EOL> assert len ( list ( universe . triples ( ( None , implies , None ) ) ) ) == <NUM_LIT:1> <EOL> assert len ( list ( universe . triples ( ( None , RDF . type , None ) ) ) ) == <NUM_LIT:1> <EOL> assert len ( list ( formulaA . triples ( ( None , RDF . type , None ) ) ) ) == <NUM_LIT:1> <EOL> assert len ( list ( formulaA . triples ( ( None , None , None ) ) ) ) == <NUM_LIT:2> <EOL> assert len ( list ( formulaB . triples ( ( None , None , None ) ) ) ) == <NUM_LIT:2> <EOL> assert len ( list ( universe . triples ( ( None , None , None ) ) ) ) == <NUM_LIT:3> <EOL> assert len ( list ( formulaB . triples ( <EOL> ( None , URIRef ( '<STR_LIT>' ) , None ) ) ) ) == <NUM_LIT:2> <EOL> assert len ( list ( universe . triples ( <EOL> ( None , URIRef ( '<STR_LIT>' ) , None ) ) ) ) == <NUM_LIT:1> <EOL> universe . remove ( ( None , implies , None ) ) <EOL> assert len ( list ( universe . triples ( ( None , implies , None ) ) ) ) == <NUM_LIT:0> <EOL> assert len ( list ( formulaA . triples ( ( None , None , None ) ) ) ) == <NUM_LIT:2> <EOL> assert len ( list ( formulaB . triples ( ( None , None , None ) ) ) ) == <NUM_LIT:2> <EOL> formulaA . remove ( ( None , b , None ) ) <EOL> assert len ( list ( formulaA . triples ( ( None , None , None ) ) ) ) == <NUM_LIT:1> <EOL> formulaA . remove ( ( None , RDF . type , None ) ) <EOL> assert len ( list ( formulaA . triples ( ( None , None , None ) ) ) ) == <NUM_LIT:0> <EOL> universe . remove ( ( None , RDF . type , RDFS . Class ) ) <EOL> universe . remove_context ( formulaB ) <EOL> assert len ( list ( universe . triples ( ( None , RDF . type , None ) ) ) ) == <NUM_LIT:0> <EOL> assert len ( universe ) == <NUM_LIT:1> <EOL> assert len ( formulaB ) == <NUM_LIT:0> <EOL> universe . remove ( ( None , None , None ) ) <EOL> assert len ( universe ) == <NUM_LIT:0> <EOL> g . close ( ) <EOL> if store == '<STR_LIT>' : <EOL> os . unlink ( path ) <EOL> else : <EOL> g . store . destroy ( configString ) <EOL> except : <EOL> g . close ( ) <EOL> if store == '<STR_LIT>' : <EOL> os . unlink ( path ) <EOL> else : <EOL> g . store . destroy ( configString ) <EOL> raise <EOL> def testFormulaStores ( ) : <EOL> pluginname = None <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if len ( sys . argv ) > <NUM_LIT:1> : <EOL> pluginname = sys . argv [ <NUM_LIT:1> ] <EOL> for s in plugin . plugins ( pluginname , plugin . Store ) : <EOL> if s . name in ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ) : <EOL> continue <EOL> if not s . getClass ( ) . formula_aware : <EOL> continue <EOL> yield testFormulaStore , s . name <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import nose <EOL> nose . main ( defaultTest = sys . argv [ <NUM_LIT:0> ] ) </s>
