diff --git a/PyOpenWorm/__init__.py b/PyOpenWorm/__init__.py index b42ed63d7..571f5903b 100644 --- a/PyOpenWorm/__init__.py +++ b/PyOpenWorm/__init__.py @@ -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, @@ -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 diff --git a/examples/default.conf b/examples/default.conf index 6d5746416..484182ac1 100644 --- a/examples/default.conf +++ b/examples/default.conf @@ -1,4 +1,4 @@ { "rdf.source" : "ZODB", - "rdf.store_conf" : "../worm.db", + "rdf.store_conf" : "../worm.db" } diff --git a/tests/test.py b/tests/test.py index f5383687c..15975bc92 100644 --- a/tests/test.py +++ b/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 @@ -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') @@ -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") @@ -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())