def test_init_no_rdf_store(self):
     """ Should be able to init without these values """
     c = Configure()
     Configureable.default = c
     d = Data()
     try:
         d.openDatabase()
     except Exception:
         self.fail("Bad state")
    def test_namespace_manager(self):
        c = Configure()
        c['rdf.source'] = 'default'
        c['rdf.store'] = 'default'
        Configureable.default = c
        d = Data()
        d.openDatabase()

        self.assertIsInstance(d['rdf.namespace_manager'], R.namespace.NamespaceManager)
예제 #3
0
 def test_read_from_file_success(self):
     """ Read configuration from a JSON file """
     try:
         d = Data.open("tests/test.conf")
         self.assertEqual("test_value", d["test_variable"])
     except Exception:
         self.fail("test.conf should exist and be valid JSON")
예제 #4
0
 def test_read_from_file_success(self):
     """ Read configuration from a JSON file """
     try:
         d = Data.open("tests/test.conf")
         self.assertEqual("test_value", d["test_variable"])
     except Exception:
         self.fail("test.conf should exist and be valid JSON")
예제 #5
0
    def _conf(self):
        from PyOpenWorm.data import Data
        dat = getattr(self, '_dat', None)
        if not dat or self._dat_file != self.config_file:
            dat = Data.open(self.config_file)
            stored_conf = dat.get('rdf.store_conf', None)

            if stored_conf and not isabs(stored_conf):
                dat['rdf.store_conf'] = abspath(pth_join(self.basedir, stored_conf))
            dat.init_database()
            self._dat = dat
            self._dat_file = self.config_file
        return dat
    def test_ZODB_persistence(self):
        """ Should be able to init without these values """
        c = Configure()
        fname = 'ZODB.fs'
        c['rdf.source'] = 'ZODB'
        c['rdf.store_conf'] = fname
        Configureable.default = c
        d = Data()
        try:
            d.openDatabase()
            g = make_graph(20)
            for x in g:
                d['rdf.graph'].add(x)
            d.closeDatabase()

            d.openDatabase()
            self.assertEqual(20, len(list(d['rdf.graph'])))
            d.closeDatabase()
        except Exception:
            traceback.print_exc()
            self.fail("Bad state")
        delete_zodb_data_store(fname)
예제 #7
0
    def _conf(self):
        from PyOpenWorm.data import Data
        dat = getattr(self, '_dat', None)
        if not dat or self._dat_file != self.config_file:
            dat = Data.open(self.config_file)
            stored_conf = dat.get('rdf.store_conf', None)

            if stored_conf and not isabs(stored_conf):
                dat['rdf.store_conf'] = abspath(
                    pth_join(self.basedir, stored_conf))
            dat.init_database()
            self._dat = dat
            self._dat_file = self.config_file
        return dat
    def test_Sleepycat_persistence(self):
        """ Should be able to init without these values """
        c = Configure()
        fname = 'Sleepycat_store'
        c['rdf.source'] = 'Sleepycat'
        c['rdf.store_conf'] = fname
        Configureable.default = c
        d = Data()
        try:
            d.openDatabase()
            g = make_graph(20)
            for x in g:
                d['rdf.graph'].add(x)
            d.closeDatabase()

            d.openDatabase()
            self.assertEqual(20, len(list(d['rdf.graph'])))
            d.closeDatabase()
        except Exception:
            traceback.print_exc()
            self.fail("Bad state")

        subprocess.call("rm -rf "+fname, shell=True)
예제 #9
0
 def setUp(self):
     # Set do_logging to True if you like walls of text
     self.TestConfig = Data.open(TEST_CONFIG)
     td = '__tempdir__'
     z = self.TestConfig['rdf.store_conf']
     if z.startswith(td):
         x = z[len(td):]
         h = tempfile.mkdtemp()
         self.TestConfig['rdf.store_conf'] = h + x
     self.delete_dir()
     self.connection = PyOpenWorm.connect(conf=self.TestConfig, do_logging=False)
     self.context = Context(ident='http://example.org/test-context',
                            conf=self.TestConfig)
     typ = type(self)
     if hasattr(typ, 'ctx_classes'):
         if isinstance(dict, typ.ctx_classes):
             self.ctx = self.context(typ.ctx_classes)
         else:
             self.ctx = self.context({x.__name__: x for x in typ.ctx_classes})
예제 #10
0
See: "Metadata in PyOpenWorm" for discussion on semantics of what giving
evidence for an object means.
"""

from __future__ import absolute_import
from __future__ import print_function
import PyOpenWorm as P
from PyOpenWorm.evidence import Evidence
from PyOpenWorm.neuron import Neuron
from PyOpenWorm.document import Document
from PyOpenWorm.data import Data
from PyOpenWorm.context import Context

# Create dummy database configuration.
d = Data()

# Connect to database with dummy configuration
conn = P.connect(conf=d)

ctx = Context(ident='http://example.org/data', conf=conn.conf)
evctx = Context(ident='http://example.org/meta', conf=conn.conf)

# Create a new Neuron object to work with
n = ctx(Neuron)(name='AVAL')

# Create a new Evidence object with `doi` and `pmid` fields populated.
# See `PyOpenWorm/evidence.py` for other available fields.
d = evctx(Document)(key='Anonymous2011',
                    doi='125.41.3/ploscompbiol',
                    pmid='12345678')
예제 #11
0
 def test_read_from_file_fail(self):
     """ Fail on attempt to read configuration from a non-JSON file """
     with self.assertRaises(ValueError):
         Data.open("tests/test_data/bad_test.conf")
예제 #12
0
 def test_read_from_file_fail(self):
     """ Fail on attempt to read configuration from a non-JSON file """
     with self.assertRaises(ValueError):
         Data.open("tests/test_data/bad_test.conf")
예제 #13
0
See: "Metadata in PyOpenWorm" for discussion on semantics of what giving
evidence for an object means.
"""

from __future__ import absolute_import
from __future__ import print_function
import PyOpenWorm as P
from PyOpenWorm.evidence import Evidence
from PyOpenWorm.neuron import Neuron
from PyOpenWorm.document import Document
from PyOpenWorm.data import Data
from PyOpenWorm.context import Context

# Create dummy database configuration.
d = Data({'rdf.source': 'ZODB'})

# Connect to database with dummy configuration
P.connect(conf=d)

ctx = Context(ident='http://example.org/data')
evctx = Context(ident='http://example.org/meta')

# Create a new Neuron object to work with
n = ctx(Neuron)(name='AVAL')

# Create a new Evidence object with `doi` and `pmid` fields populated.
# See `PyOpenWorm/evidence.py` for other available fields.
d = evctx(Document)(key='Anonymous2011',
                    doi='125.41.3/ploscompbiol',
                    pmid='12345678')