Skip to content

Commit

Permalink
Corrected default.conf file in examples/
Browse files Browse the repository at this point in the history
- added option to skip loading of the datafile based on its relative
  newness compared to the database.
  • Loading branch information
mwatts15 committed Mar 31, 2015
1 parent 5d680f1 commit b1c3c97
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
22 changes: 15 additions & 7 deletions PyOpenWorm/__init__.py
Expand Up @@ -106,17 +106,26 @@ def disconnect(c=False):
m.connected = False


def loadData(data='OpenWormData/WormData.n3', dataFormat='n3'):
"""
def loadData(data='OpenWormData/WormData.n3', dataFormat='n3', skipIfNewer=False):
"""
Load data into the underlying database of this library.
XXX: This is only guaranteed to work with the ZODB database.
:param data: (Optional) Specify the file to load into the library
:param dataFormat: (Optional) Specify the file format to load into the library. Currently n3 is supported
:return:
:param skipIfNewer: (Optional) Skips loading of data if the database file is newer
than the data to be loaded in. This is determined by the modified time on the main
database file compared to the modified time on the data file.
"""
if data:
sys.stderr.write("[PyOpenWorm] Loading data into the graph; this may take several minutes!!\n")
config()['rdf.graph'].parse(data, format=dataFormat)
if skipIfNewer:
import os
data_file_time=os.path.getmtime(data)
db_file_time=os.path.getmtime(config('rdf.store_conf'))
if data_file_time < db_file_time:
return
sys.stderr.write("[PyOpenWorm] Loading data into the graph; this may take several minutes!!\n")
config('rdf.graph').parse(data, format=dataFormat)

def connect(configFile='PyOpenWorm/default.conf',
conf=False,
Expand All @@ -131,7 +140,6 @@ def connect(configFile='PyOpenWorm/default.conf',
:param do_logging: (Optional) If true, turn on debug level logging
:param data: (Optional) If provided, specify the file to load into the library
:param dataFormat: (Optional) If provided, specify the file format to load into the library. Currently n3 is supported
:return:
"""
import logging
import atexit
Expand Down
2 changes: 1 addition & 1 deletion examples/default.conf
@@ -1,4 +1,4 @@
{
"rdf.source" : "ZODB",
"rdf.store_conf" : "../worm.db",
"rdf.store_conf" : "../worm.db"
}
28 changes: 17 additions & 11 deletions tests/test.py
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-

import sys
sys.path.insert(0,".")
import unittest
import neuroml
import neuroml.writers as writers
import sys
sys.path.insert(0,".")
import PyOpenWorm
from PyOpenWorm import *
import test_data as TD
Expand Down Expand Up @@ -65,7 +65,7 @@ class ExampleRunnerTest(unittest.TestCase):
@classmethod
def setUpClass(self):
PyOpenWorm.connect()
PyOpenWorm.loadData()
PyOpenWorm.loadData(skipIfNewer=True)
PyOpenWorm.disconnect()
os.chdir('examples')

Expand All @@ -74,8 +74,12 @@ def tearDownClass(self):
os.chdir('..')

def execfile(self, example_file_name):
with open("/dev/null", "w") as out:
self.assertEqual(0, SP.call(["python", example_file_name], stdout=out, stderr=out))
fname = tempfile.mkstemp()[1]
with open(fname, 'w+') as out:
stat = SP.call(["python", example_file_name], stdout=out, stderr=out)
out.seek(0)
self.assertEqual(0, stat, out.read())
os.unlink(fname)

def test_run_NeuronBasicInfo(self):
self.execfile("NeuronBasicInfo.py")
Expand Down Expand Up @@ -1392,13 +1396,15 @@ def runTests(suite):
return unittest.TextTestRunner().run(suite)

all_tests = []
for x in glob("tests/test_*.conf"):
configs = glob("tests/test_*.conf")
if not has_bsddb:
configs = [x for x in configs if 'Sleepycat' not in x]
print "Testing with configs:",configs
for x in configs:
TEST_CONFIG = x
print "config", x
if not ((x == "tests/test_Sleepycat.conf") and (not has_bsddb)):
suite = unittest.TestSuite()
suite.addTests(getTests(x) for x in _DataTest.__subclasses__())
all_tests.append(suite)
suite = unittest.TestSuite()
suite.addTests(getTests(x) for x in _DataTest.__subclasses__())
all_tests.append(suite)

suite = unittest.TestSuite()
classes = filter(lambda x : isinstance(x, type), globals().values())
Expand Down

0 comments on commit b1c3c97

Please sign in to comment.