Hi Troels, As the unit test is calling other parts of the relax code, you should convert it to a system test. Unit tests should be stand-alone and not rely on any other parts of the code base for setting up the test. I.e. if the unit test fails, it can only be because there is a problem in that function it tests. In this case, if mol_res_spin.create_spin() fails, for example, then so does this unit test. That should not happen, hence why this is more of a system test - it can have multiple points of failure. To properly set up such a unit test, you would have to provide dummy data structures with dummy data, but this is too much effort.
Cheers, Edward On 18 August 2014 16:20, <tlin...@nmr-relax.com> wrote: > Author: tlinnet > Date: Mon Aug 18 16:20:33 2014 > New Revision: 25048 > > URL: http://svn.gna.org/viewcvs/relax?rev=25048&view=rev > Log: > Added a "check" function, what will determine if R1 data is missing for a > model to analyse. > > Also added corresponding unit tests, to test the functionality. > > Modified: > trunk/specific_analyses/relax_disp/checks.py > trunk/test_suite/unit_tests/_specific_analyses/_relax_disp/test_checks.py > > Modified: trunk/specific_analyses/relax_disp/checks.py > URL: > http://svn.gna.org/viewcvs/relax/trunk/specific_analyses/relax_disp/checks.py?rev=25048&r1=25047&r2=25048&view=diff > ============================================================================== > --- trunk/specific_analyses/relax_disp/checks.py (original) > +++ trunk/specific_analyses/relax_disp/checks.py Mon Aug 18 16:20:33 > 2014 > @@ -30,7 +30,7 @@ > from dep_check import C_module_exp_fn > from lib.errors import RelaxError, RelaxFuncSetupError, > RelaxNoPeakIntensityError > import specific_analyses > -from specific_analyses.relax_disp.variables import EXP_TYPE_LIST_CPMG, > EXP_TYPE_LIST_R1RHO > +from specific_analyses.relax_disp.variables import EXP_TYPE_LIST_CPMG, > EXP_TYPE_LIST_R1RHO, MODEL_LIST_R1RHO_W_R1_ONLY > > > def check_c_modules(): > @@ -178,6 +178,30 @@ > raise > RelaxFuncSetupError(specific_analyses.setup.get_string(function_type)) > > > +def check_missing_r1(model=None): > + """Check if R1 data is missing for the model. > + > + @keyword model: The model to test for. > + @type model: str > + @return: Return True if R1 data is not available for the model. > + @rtype: bool > + """ > + > + # Check that the model uses R1 data. > + if model in MODEL_LIST_R1RHO_W_R1_ONLY: > + # If R1 ids are present. > + if hasattr(cdp, 'ri_ids'): > + return False > + > + # If not present. > + else: > + return True > + > + # If model does not need R1. > + else: > + return False > + > + > def check_relax_times(): > """Check if the spectrometer frequencies have been set up. > > > Modified: > trunk/test_suite/unit_tests/_specific_analyses/_relax_disp/test_checks.py > URL: > http://svn.gna.org/viewcvs/relax/trunk/test_suite/unit_tests/_specific_analyses/_relax_disp/test_checks.py?rev=25048&r1=25047&r2=25048&view=diff > ============================================================================== > --- trunk/test_suite/unit_tests/_specific_analyses/_relax_disp/test_checks.py > (original) > +++ trunk/test_suite/unit_tests/_specific_analyses/_relax_disp/test_checks.py > Mon Aug 18 16:20:33 2014 > @@ -25,8 +25,10 @@ > > # relax module imports. > from data_store import Relax_data_store; ds = Relax_data_store() > -from pipe_control import state > -from specific_analyses.relax_disp.checks import get_times > +from pipe_control import mol_res_spin, pipes, relax_data, spectrometer, state > +from specific_analyses.relax_disp.checks import check_missing_r1, get_times > +from specific_analyses.relax_disp.data import set_exp_type > +from specific_analyses.relax_disp.variables import MODEL_DPL94, MODEL_R2EFF > from status import Status; status = Status() > from test_suite.unit_tests.base_classes import UnitTestCase > > @@ -39,6 +41,74 @@ > > # Create a dispersion data pipe. > ds.add(pipe_name='orig', pipe_type='relax_disp') > + > + > + def set_up_spins(self, pipe_name=None): > + """Function for setting up a few spins for the given pipe.""" > + > + # Alias the pipe. > + pipe = pipes.get_pipe(pipe_name) > + > + # Path to file. > + data_path = status.install_path + > sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' > + > + # File with spins. > + file = open(data_path+sep+'R1_fitted_values.txt') > + lines = file.readlines() > + file.close() > + > + for i, line in enumerate(lines): > + # Make the string test > + line_split = line.split() > + > + if line_split[0] == "#": > + continue > + > + mol_name = line_split[0] > + mol_name = None > + res_num = int(line_split[1]) > + res_name = line_split[2] > + spin_num = line_split[3] > + spin_num = None > + spin_name = line_split[4] > + > + # Create the spin. > + mol_res_spin.create_spin(spin_num=spin_num, spin_name=spin_name, > res_num=res_num, res_name=res_name, mol_name=mol_name, pipe=pipe_name) > + > + > + def test_check_missing_r1(self): > + """Unit test of the check_missing_r1() function.""" > + > + # Set up some spins. > + self.set_up_spins(pipe_name='orig') > + > + # Set variables. > + exp_type = 'R1rho' > + frq = 800.1 * 1E6 > + > + # Set an experiment type to the pipe. > + set_exp_type(spectrum_id='test', exp_type=exp_type) > + > + # Set a frequency to loop through. > + spectrometer.set_frequency(id='test', frq=frq, units='Hz') > + > + # Check R1 for DPL94. > + check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) > + self.assertEqual(check_missing_r1_return, True) > + > + # Check R1 for R2eff. > + check_missing_r1_return = check_missing_r1(model=MODEL_R2EFF) > + self.assertEqual(check_missing_r1_return, False) > + > + # The path to the data files. > + data_path = status.install_path + > sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' > + > + # Now load some R1 data. > + relax_data.read(ri_id='R1', ri_type='R1', > frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, > mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, > spin_name_col=5, data_col=6, error_col=7) > + > + # Check R1. > + check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) > + self.assertEqual(check_missing_r1_return, False) > > > def test_get_times_cpmg(self): > > > _______________________________________________ > relax (http://www.nmr-relax.com) > > This is the relax-commits mailing list > relax-comm...@gna.org > > To unsubscribe from this list, get a password > reminder, or change your subscription options, > visit the list information page at > https://mail.gna.org/listinfo/relax-commits _______________________________________________ relax (http://www.nmr-relax.com) This is the relax-devel mailing list relax-devel@gna.org To unsubscribe from this list, get a password reminder, or change your subscription options, visit the list information page at https://mail.gna.org/listinfo/relax-devel