def test_trix_source(self): """ Test that we can load the datbase up from an XML file. """ f = tempfile.mkstemp() c = Configure() c['rdf.source'] = 'trix' c['rdf.store'] = 'default' c['trix_location'] = f[1] with open(f[1], 'w') as fo: fo.write(TD.TriX_data) connect(conf=c) c = config() try: g = c['rdf.graph'] b = g.query("ASK { ?S ?P ?O }") for x in b: self.assertTrue(x) except ImportError: pass finally: disconnect() os.unlink(f[1])
def test_translate_data_source_loader(self): with connect(p(self.testdir, '.pow', 'pow.conf')) as conn: with transaction.manager: # Create data sources ctx = Context(ident='http://example.org/context', conf=conn.conf) ctx(LFDS)( ident='http://example.org/lfds', file_name='Merged_Nuclei_Stained_Worm.zip', torrent_file_name='d9da5ce947c6f1c127dfcdc2ede63320.torrent') class DT(DataTranslator): class_context = ctx.identifier input_type = LFDS output_type = LFDS translator_identifier = 'http://example.org/trans1' def translate(source): print(source.full_path()) return source ctx.mapper.process_class(DT) dt = ctx(DT)() # Create a translator ctx_id = conn.conf['data_context_id'] DT.definition_context.save(conn.conf['rdf.graph']) main_ctx = Context(ident=ctx_id, conf=conn.conf) main_ctx.add_import(ctx) main_ctx.save_imports() ctx.save() # Do translation assertRegexpMatches( self.sh( 'pow translate http://example.org/trans1 http://example.org/lfds'), r'Merged_Nuclei_Stained_Worm.zip')
def test_translator_list(self): expected = URIRef('http://example.org/trans1') with connect(p(self.testdir, '.pow', 'pow.conf')) as conn: with transaction.manager: # Create data sources ctx = Context(ident='http://example.org/context', conf=conn.conf) class DT(DataTranslator): class_context = ctx.identifier translator_identifier = expected def translate(source): pass ctx.mapper.process_class(DT) DT.definition_context.save(conn.conf['rdf.graph']) # Create a translator dt = ctx(DT)() ctx_id = conn.conf['data_context_id'] main_ctx = Context(ident=ctx_id, conf=conn.conf) main_ctx.add_import(ctx) main_ctx.save_imports() ctx.save() # List translators assertRegexpMatches( self.sh('pow translator list'), re.compile('^' + expected.n3() + '$', flags=re.MULTILINE))
def test_l(self): """ Test that a property can be loaded when the owning object doesn't have any other values set This test is for many objects of the same kind """ disconnect() from random import random from time import time # Generate data sets from 10 to 10000 in size # query for properties print('starting testl') class _to(DataObject): def __init__(self, x=False): DataObject.__init__(self) DatatypeProperty('flexo', owner=self) if x: self.flexo(x) # feel free to add more if you have the time nums = [10, 1e2, 1e3] connect("tests/testl.conf") try: # for 1000, takes about 10 seconds... for x in nums: print( 'running ', x, 'sized test on a ', Configureable.default['rdf.graph'].store, 'store') v = values('zim') for z in range(int(x)): v.add(_to(random())) t0 = time() v.save() for _ in _to().flexo(): pass t1 = time() print("took", t1 - t0, "seconds") Configureable.default['rdf.graph'].remove((None, None, None)) except: traceback.print_exc() disconnect()
def test_l(self): """ Test that a property can be loaded when the owning object doesn't have any other values set This test is for many objects of the same kind """ disconnect() from random import random from time import time # Generate data sets from 10 to 10000 in size # query for properties print('starting testl') class _to(DataObject): def __init__(self, x=False): DataObject.__init__(self) DatatypeProperty('flexo', owner=self) if x: self.flexo(x) # feel free to add more if you have the time nums = [10, 1e2, 1e3] connect("tests/testl.conf") try: # for 1000, takes about 10 seconds... for x in nums: print('running ', x, 'sized test on a ', Configureable.default['rdf.graph'].store, 'store') v = values('zim') for z in range(int(x)): v.add(_to(random())) t0 = time() v.save() for _ in _to().flexo(): pass t1 = time() print("took", t1 - t0, "seconds") Configureable.default['rdf.graph'].remove((None, None, None)) except: traceback.print_exc() disconnect()
def setup(): connect(configFile='tests/data_integrity_test.conf')
def setUp(self): connect(configFile='tests/data_integrity_test.conf') self.g = config("rdf.graph")
from __future__ import print_function from PyOpenWorm import connect, config from PyOpenWorm.context import Context from PyOpenWorm.neuron import Neuron from PyOpenWorm.evidence import Evidence from PyOpenWorm.document import Document from PyOpenWorm.website import Website conn = connect(configFile="default.conf") print('the graph', conn.conf['rdf.graph']) def query_context(graph, qctx): trips = qctx.contents_triples() lctx = None for t in trips: ctxs = graph.contexts(t) if lctx is None: lctx = frozenset(ctxs) continue if len(lctx) == 0: return frozenset() else: lctx = frozenset(ctxs) & lctx if len(lctx) == 0: return lctx return frozenset() if lctx is None else lctx qctx = Context() qctx(Neuron)('AVAL').innexin('UNC-7')
def setUp(self): connect("tests/test.conf")
def setup(): global connection xfail_without_db() connection = connect(configFile='tests/data_integrity_test.conf')
from __future__ import print_function from PyOpenWorm import connect, config from PyOpenWorm.context import Context from PyOpenWorm.neuron import Neuron from PyOpenWorm.evidence import Evidence from PyOpenWorm.document import Document from PyOpenWorm.website import Website conn = connect(configFile="default.conf") print('the graph', conn.conf['rdf.graph']) def query_context(graph, qctx): trips = qctx.contents_triples() lctx = None for t in trips: ctxs = graph.contexts(t) if lctx is None: lctx = frozenset(ctxs) continue if len(lctx) == 0: return frozenset() else: lctx = frozenset(ctxs) & lctx if len(lctx) == 0: return lctx return frozenset() if lctx is None else lctx qctx = Context()