Commit 4d86026e authored by eric pellegrini's avatar eric pellegrini
Browse files

The unit tests have been updated

Bug fix related to pickle mechanism and User definitions
parent 11660543
......@@ -125,7 +125,7 @@ class ClassRegistry(abc.ABCMeta):
if moduleDir not in sys.path:
sys.path.append(moduleDir)
# Any error that may occur here has to be caught. In such case the module is skipped.
try:
__import__(moduleName, locals(), globals())
......
......@@ -35,7 +35,7 @@ import operator
import numpy
from MDANSE.Framework.UserDefinitionsStore import UD_STORE, UserDefinitionsStoreError
from MDANSE.Framework.UserDefinitionsStore import UD_STORE
from MDANSE.Framework.Configurators.IConfigurator import IConfigurator, ConfiguratorError
from MDANSE.Framework.AtomSelectionParser import AtomSelectionParser
......
......@@ -31,7 +31,7 @@ Created on May 22, 2015
'''
from MDANSE import REGISTRY
from MDANSE.Framework.UserDefinitionsStore import UD_STORE, UserDefinitionsStoreError
from MDANSE.Framework.UserDefinitionsStore import UD_STORE
from MDANSE.Framework.Configurators.IConfigurator import IConfigurator, ConfiguratorError
class QVectorsConfigurator(IConfigurator):
......
......@@ -343,9 +343,6 @@ class IJob(Configurable):
f.write('from MDANSE import REGISTRY\n\n')
f.write('class Test%s(UnitTest):\n\n' % cls.type.upper())
f.write(' def setUp(self):\n')
f.write(' from MDANSE import LOGGER\n')
f.write(' LOGGER.stop()\n\n')
f.write(' def test(self):\n')
......@@ -359,8 +356,8 @@ class IJob(Configurable):
f.write(' parameters[%r] = %r\n' % (k, v))
# Sets |analysis| variable to an instance analysis to save.
f.write(' job = REGISTRY[%r](%r)\n' % ('job',cls.type))
f.write(' self.assertNotRaises(job.run, parameters,False)\n\n')
f.write(' job = REGISTRY[%r][%r](status=False)\n' % ('job',cls.type))
f.write(' self.assertNotRaises(job.run, parameters)\n\n')
f.write('def suite():\n')
f.write(' loader = unittest.TestLoader()\n')
......
import os
import sys
sys.path.append(os.path.dirname(__file__))
\ No newline at end of file
......@@ -42,18 +42,15 @@ class UserDefinitionsStore(dict):
if not os.path.exists(UserDefinitionsStore.UD_PATH):
return
f = open(UserDefinitionsStore.UD_PATH, "rb")
UD = cPickle.load(f)
# Try to open the UD file.
try:
f = open(UserDefinitionsStore.UD_PATH, "rb")
UD = cPickle.load(f)
# If for whatever reason the pickle file loading failed do not even try to restore it
except:
return
else:
self.update(UD)
f.close()
......
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#6, rue Jules Horowitz
#38042 Grenoble Cedex 9
#France
#pellegrini[at]ill.fr
#goret[at]ill.fr
#aoun[at]ill.fr
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''
Created on May 29, 2015
@author: Eric C. Pellegrini
'''
import unittest
import os
import glob
def suite():
files = glob.glob('Test*.py')
modules = [__import__(os.path.splitext(f)[0],globals(),locals(),[],-1) for f in files]
test_suite = unittest.TestSuite()
for m in modules:
test_suite.addTests(m.suite())
return test_suite
def run_test():
unittest.TextTestRunner(verbosity=2).run(suite())
if __name__ == '__main__':
run_test()
from MDANSE import REGISTRY
for v in REGISTRY['job'].itervalues():
v.save("Test_%s.py" % v.type)
\ No newline at end of file
v.build_test("Test_%s.py" % v.type)
\ No newline at end of file
#!/usr/bin/python
########################################################
# This is an automatically generated MDANSE run script #
#######################################################
import unittest
from Tests.UnitTest import UnitTest
from MDANSE import REGISTRY
################################################################
# Job parameters #
################################################################
class TestAC(UnitTest):
parameters = {}
parameters['axis_selection'] = {'endpoint1': ('OW',), 'endpoint2': ('HW',), 'molecule': 'Water'}
parameters['frames'] = (0, 10, 1)
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['per_axis'] = False
parameters['running_mode'] = ('monoprocessor', 1)
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
def test(self):
parameters = {}
parameters['axis_selection'] = {'endpoint1': ('OW',), 'endpoint2': ('HW',), 'molecule': 'Water'}
parameters['frames'] = (0, 10, 1)
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['per_axis'] = False
parameters['running_mode'] = ('monoprocessor', 1)
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
job = REGISTRY['job']['ac'](status=False)
self.assertNotRaises(job.run, parameters)
################################################################
# Setup and run the analysis #
################################################################
def suite():
loader = unittest.TestLoader()
s = unittest.TestSuite()
s.addTest(loader.loadTestsFromTestCase(TestAC))
return s
job = REGISTRY['job']['ac'](status=False)
job.run(parameters)
\ No newline at end of file
if __name__ == '__main__':
unittest.main(verbosity=2)
#!/usr/bin/python
########################################################
# This is an automatically generated MDANSE run script #
#######################################################
import unittest
from Tests.UnitTest import UnitTest
from MDANSE import REGISTRY
################################################################
# Job parameters #
################################################################
class TestAPM(UnitTest):
parameters = {}
parameters['axis'] = ['a', 'b']
parameters['frames'] = (0, 10, 1)
parameters['name'] = 'DMPC'
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['running_mode'] = ('monoprocessor', 1)
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/dmpc_in_periodic_universe.nc'
def test(self):
parameters = {}
parameters['axis'] = ['a', 'b']
parameters['frames'] = (0, 10, 1)
parameters['name'] = 'DMPC'
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['running_mode'] = ('monoprocessor', 1)
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/dmpc_in_periodic_universe.nc'
job = REGISTRY['job']['apm'](status=False)
self.assertNotRaises(job.run, parameters)
################################################################
# Setup and run the analysis #
################################################################
def suite():
loader = unittest.TestLoader()
s = unittest.TestSuite()
s.addTest(loader.loadTestsFromTestCase(TestAPM))
return s
job = REGISTRY['job']['apm'](status=False)
job.run(parameters)
\ No newline at end of file
if __name__ == '__main__':
unittest.main(verbosity=2)
#!/usr/bin/python
########################################################
# This is an automatically generated MDANSE run script #
#######################################################
import unittest
from Tests.UnitTest import UnitTest
from MDANSE import REGISTRY
################################################################
# Job parameters #
################################################################
class TestBTT(UnitTest):
parameters = {}
parameters['atom_selection'] = 'all'
parameters['frames'] = (0, 10, 1)
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
def test(self):
parameters = {}
parameters['atom_selection'] = 'all'
parameters['frames'] = (0, 10, 1)
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
job = REGISTRY['job']['btt'](status=False)
self.assertNotRaises(job.run, parameters)
################################################################
# Setup and run the analysis #
################################################################
def suite():
loader = unittest.TestLoader()
s = unittest.TestSuite()
s.addTest(loader.loadTestsFromTestCase(TestBTT))
return s
job = REGISTRY['job']['btt'](status=False)
job.run(parameters)
\ No newline at end of file
if __name__ == '__main__':
unittest.main(verbosity=2)
#!/usr/bin/python
########################################################
# This is an automatically generated MDANSE run script #
#######################################################
import unittest
from Tests.UnitTest import UnitTest
from MDANSE import REGISTRY
################################################################
# Job parameters #
################################################################
class TestCASTEP(UnitTest):
parameters = {}
parameters['castep_file'] = '../../../Data/Trajectories/CASTEP/PBAnew.md'
parameters['output_file'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
def test(self):
parameters = {}
parameters['castep_file'] = '../../../Data/Trajectories/CASTEP/PBAnew.md'
parameters['output_file'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
job = REGISTRY['job']['castep'](status=False)
self.assertNotRaises(job.run, parameters)
################################################################
# Setup and run the analysis #
################################################################
def suite():
loader = unittest.TestLoader()
s = unittest.TestSuite()
s.addTest(loader.loadTestsFromTestCase(TestCASTEP))
return s
job = REGISTRY['job']['castep'](status=False)
job.run(parameters)
\ No newline at end of file
if __name__ == '__main__':
unittest.main(verbosity=2)
#!/usr/bin/python
########################################################
# This is an automatically generated MDANSE run script #
#######################################################
import unittest
from Tests.UnitTest import UnitTest
from MDANSE import REGISTRY
################################################################
# Job parameters #
################################################################
class TestCCF(UnitTest):
parameters = {}
parameters['atom_selection'] = 'all'
parameters['frames'] = (0, 10, 1)
parameters['instrument_resolution'] = ('gaussian', {'mu': 0.0, 'sigma': 10.0})
parameters['normalize'] = False
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['q_vectors'] = ('spherical_lattice', {'width': 0.1, 'n_vectors': 50, 'shells': (0, 5, 0.1)})
parameters['running_mode'] = ('monoprocessor', 1)
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
parameters['transmutated_atoms'] = None
parameters['weights'] = 'b_coherent'
def test(self):
parameters = {}
parameters['atom_selection'] = 'all'
parameters['frames'] = (0, 10, 1)
parameters['instrument_resolution'] = ('gaussian', {'mu': 0.0, 'sigma': 10.0})
parameters['normalize'] = False
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['q_vectors'] = ('spherical_lattice', {'width': 0.1, 'n_vectors': 50, 'shells': (0, 5, 0.1)})
parameters['running_mode'] = ('monoprocessor', 1)
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
parameters['transmutated_atoms'] = None
parameters['weights'] = 'b_coherent'
job = REGISTRY['job']['ccf'](status=False)
self.assertNotRaises(job.run, parameters)
################################################################
# Setup and run the analysis #
################################################################
def suite():
loader = unittest.TestLoader()
s = unittest.TestSuite()
s.addTest(loader.loadTestsFromTestCase(TestCCF))
return s
job = REGISTRY['job']['ccf'](status=False)
job.run(parameters)
\ No newline at end of file
if __name__ == '__main__':
unittest.main(verbosity=2)
#!/usr/bin/python
########################################################
# This is an automatically generated MDANSE run script #
#######################################################
import unittest
from Tests.UnitTest import UnitTest
from MDANSE import REGISTRY
################################################################
# Job parameters #
################################################################
class TestCHARMM(UnitTest):
parameters = {}
parameters['dcd_file'] = '../../../Data/Trajectories/CHARMM/2vb1.dcd'
parameters['fold'] = False
parameters['output_file'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['pdb_file'] = '../../../Data/Trajectories/CHARMM/2vb1.pdb'
def test(self):
parameters = {}
parameters['dcd_file'] = '../../../Data/Trajectories/CHARMM/2vb1.dcd'
parameters['fold'] = False
parameters['output_file'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['pdb_file'] = '../../../Data/Trajectories/CHARMM/2vb1.pdb'
job = REGISTRY['job']['charmm'](status=False)
self.assertNotRaises(job.run, parameters)
################################################################
# Setup and run the analysis #
################################################################
def suite():
loader = unittest.TestLoader()
s = unittest.TestSuite()
s.addTest(loader.loadTestsFromTestCase(TestCHARMM))
return s
job = REGISTRY['job']['charmm'](status=False)
job.run(parameters)
\ No newline at end of file
if __name__ == '__main__':
unittest.main(verbosity=2)
#!/usr/bin/python
########################################################
# This is an automatically generated MDANSE run script #
#######################################################
import unittest
from Tests.UnitTest import UnitTest
from MDANSE import REGISTRY
################################################################
# Job parameters #
################################################################
class TestCN(UnitTest):
parameters = {}
parameters['atom_selection'] = 'all'
parameters['frames'] = (0, 10, 1)
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['r_values'] = (0, 10, 1)
parameters['running_mode'] = ('monoprocessor', 1)
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
parameters['transmutated_atoms'] = None
def test(self):
parameters = {}
parameters['atom_selection'] = 'all'
parameters['frames'] = (0, 10, 1)
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['r_values'] = (0, 10, 1)
parameters['running_mode'] = ('monoprocessor', 1)
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
parameters['transmutated_atoms'] = None
job = REGISTRY['job']['cn'](status=False)
self.assertNotRaises(job.run, parameters)
################################################################
# Setup and run the analysis #
################################################################
def suite():
loader = unittest.TestLoader()
s = unittest.TestSuite()
s.addTest(loader.loadTestsFromTestCase(TestCN))
return s
job = REGISTRY['job']['cn'](status=False)
job.run(parameters)
\ No newline at end of file
if __name__ == '__main__':
unittest.main(verbosity=2)
#!/usr/bin/python
########################################################
# This is an automatically generated MDANSE run script #
#######################################################
import unittest
from Tests.UnitTest import UnitTest
from MDANSE import REGISTRY
################################################################
# Job parameters #
################################################################
class TestCOMT(UnitTest):
parameters = {}
parameters['atom_selection'] = 'all'
parameters['frames'] = (0, 1, 1)
parameters['grouping_level'] = 'atom'
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
def test(self):
parameters = {}
parameters['atom_selection'] = 'all'
parameters['frames'] = (0, 1, 1)
parameters['grouping_level'] = 'atom'
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
job = REGISTRY['job']['comt'](status=False)
self.assertNotRaises(job.run, parameters)
################################################################
# Setup and run the analysis #
################################################################
def suite():
loader = unittest.TestLoader()
s = unittest.TestSuite()
s.addTest(loader.loadTestsFromTestCase(TestCOMT))
return s
job = REGISTRY['job']['comt'](status=False)
job.run(parameters)
\ No newline at end of file
if __name__ == '__main__':
unittest.main(verbosity=2)
#!/usr/bin/python
########################################################
# This is an automatically generated MDANSE run script #
#######################################################
import unittest
from Tests.UnitTest import UnitTest
from MDANSE import REGISTRY
################################################################
# Job parameters #
################################################################
class TestCT(UnitTest):
parameters = {}
parameters['atom_selection'] = 'all'
parameters['frames'] = (0, 10, 1)
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
def test(self):
parameters = {}
parameters['atom_selection'] = 'all'
parameters['frames'] = (0, 10, 1)
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
job = REGISTRY['job']['ct'](status=False)
self.assertNotRaises(job.run, parameters)
################################################################
# Setup and run the analysis #
################################################################
def suite():
loader = unittest.TestLoader()
s = unittest.TestSuite()
s.addTest(loader.loadTestsFromTestCase(TestCT))
return s
job = REGISTRY['job']['ct'](status=False)
job.run(parameters)
\ No newline at end of file
if __name__ == '__main__':
unittest.main(verbosity=2)
#!/usr/bin/python
########################################################
# This is an automatically generated MDANSE run script #
#######################################################
import unittest
from Tests.UnitTest import UnitTest
from MDANSE import REGISTRY
################################################################
# Job parameters #
################################################################
class TestDACF(UnitTest):
parameters = {}
parameters['atom_charges'] = {0: 0.5, 1: 1.2, 2: -0.2}
parameters['atom_selection'] = 'atom_index 0,1,2'
parameters['frames'] = (0, 10, 1)
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['running_mode'] = ('monoprocessor', 1)
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
def test(self):
parameters = {}
parameters['atom_charges'] = {0: 0.5, 1: 1.2, 2: -0.2}
parameters['atom_selection'] = 'atom_index 0,1,2'
parameters['frames'] = (0, 10, 1)
parameters['output_files'] = ('/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs', 'output', ['netcdf'])
parameters['running_mode'] = ('monoprocessor', 1)
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
job = REGISTRY['job']['dacf'](status=False)
self.assertNotRaises(job.run, parameters)
################################################################
# Setup and run the analysis #
################################################################
def suite():
loader = unittest.TestLoader()
s = unittest.TestSuite()
s.addTest(loader.loadTestsFromTestCase(TestDACF))
return s
job = REGISTRY['job']['dacf'](status=False)