Author: semor Date: Tue Jan 27 22:47:00 2009 New Revision: 8686 URL: http://svn.gna.org/viewcvs/relax?rev=8686&view=rev Log: Added more unit tests and tried to debug what was uncovered by these tests. Still more work is needed for debugging... Modified: branches/relax_disp/prompt/relax_disp.py branches/relax_disp/specific_fns/relax_disp.py branches/relax_disp/test_suite/unit_tests/_prompt/test_relax_disp.py Modified: branches/relax_disp/prompt/relax_disp.py URL: http://svn.gna.org/viewcvs/relax/branches/relax_disp/prompt/relax_disp.py?rev=8686&r1=8685&r2=8686&view=diff ============================================================================== --- branches/relax_disp/prompt/relax_disp.py (original) +++ branches/relax_disp/prompt/relax_disp.py Tue Jan 27 22:47:00 2009 @@ -30,7 +30,7 @@ # relax module imports. import help -from relax_errors import RelaxNoneNumError, RelaxStrError +from relax_errors import RelaxNoneNumError, RelaxNumError, RelaxStrError from specific_fns.setup import relax_disp_obj @@ -47,7 +47,7 @@ self.__relax__ = relax - def calc_r2eff(self, exp_type='cpmg', id=None, delayT=None, int_cpmg=0, int_ref=0): + def calc_r2eff(self, exp_type='cpmg', id=None, delayT=None, int_cpmg=0.0, int_ref=0.0): """Calculate the effective transversal relaxation rate from the peak intensities. THIS FUNCTION IS NOT WRITTEN YET. @@ -80,9 +80,40 @@ Examples ~~~~~~~~ - - - """ + """ + + # Function intro text. + if self.__relax__.interpreter.intro: + text = sys.ps3 + "relax_disp.calc_r2eff(" + text = text + "exp_type=" + `exp_type` + text = text + ", id=" + `id` + text = text + ", delayT=" + `delayT` + text = text + ", int_cpmg=" + `int_cpmg` + text = text + ", int_ref=" + `int_ref` + ")" + print text + + # The exp_type argument. + if type(exp_type) != str: + raise RelaxStrError, ('exp_type', exp_type) + + # The id argument. + if type(id) != str: + raise RelaxStrError, ('experiment identification string', id) + + # The CPMG constant time delay (T). + if type(delayT) != float and type(delayT) != int and delayT != None: + raise RelaxNoneNumError, ('CPMG constant time delay (T)', delayT) + + # The CPMG peak intensity. + if type(int_cpmg) != float and type(delayT) != int: + raise RelaxNumError, ('int_cpmg', int_cpmg) + + # The reference peak intensity. + if type(int_ref) != float and type(delayT) != int: + raise RelaxNumError, ('int_ref', int_ref) + + # Execute the functional code. + relax_disp_obj.calc_r2eff(exp_type=exp_type, id=id, delayT=delayT, int_cpmg=int_cpmg, int_ref=int_ref) def cpmg_delayT(self, id=None, delayT=None): @@ -122,7 +153,7 @@ if type(delayT) != float and type(delayT) != int and delayT != None: raise RelaxNoneNumError, ('CPMG constant time delay (T)', delayT) - # Id string. + # The id argument. if type(id) != str: raise RelaxStrError, ('experiment identification string', id) @@ -182,13 +213,13 @@ relax_disp_obj.cpmg_frq(cpmg_frq=cpmg_frq, spectrum_id=spectrum_id) - def exp_type(self, exp='cpmg'): + def exp_type(self, exp_type='cpmg'): """Function for the selection of the relaxation dispersion experiments to analyse. Keyword Arguments ~~~~~~~~~~~~~~~~~ - exp: The type of relaxation dispersion experiment performed. + exp_type: The type of relaxation dispersion experiment performed. The preset experiments @@ -203,21 +234,21 @@ To pick the experiment type 'cpmg' for all selected spins, type: relax> relax_disp.exp_type('cpmg') - relax> relax_disp.exp_type(exp='cpmg') + relax> relax_disp.exp_type(exp_type='cpmg') """ # Function intro text. if self.__relax__.interpreter.intro: text = sys.ps3 + "relax_disp.exp_type(" - text = text + "exp=" + `exp` + ")" - print text - - # The exp argument. - if type(exp) != str: - raise RelaxStrError, ('exp', exp) - - # Execute the functional code. - relax_disp_obj.exp_type(exp=exp) + text = text + "exp_type=" + `exp_type` + ")" + print text + + # The exp_type argument. + if type(exp_type) != str: + raise RelaxStrError, ('exp_type', exp_type) + + # Execute the functional code. + relax_disp_obj.exp_type(exp_type=exp_type) def r2eff_read(self): @@ -278,7 +309,7 @@ To pick the model 'fast' for all selected spins, type: relax> relax_disp.select_model('fast') - relax> relax_disp.select_model(exp='fast') + relax> relax_disp.select_model(exp_type='fast') """ # Function intro text. Modified: branches/relax_disp/specific_fns/relax_disp.py URL: http://svn.gna.org/viewcvs/relax/branches/relax_disp/specific_fns/relax_disp.py?rev=8686&r1=8685&r2=8686&view=diff ============================================================================== --- branches/relax_disp/specific_fns/relax_disp.py (original) +++ branches/relax_disp/specific_fns/relax_disp.py Tue Jan 27 22:47:00 2009 @@ -241,7 +241,7 @@ return results[result_index] - def calc_r2eff(self, exp_type='cpmg', id=None, delayT=None, int_cpmg=0, int_ref=0): + def calc_r2eff(self, exp_type='cpmg', id=None, delayT=None, int_cpmg=0.0, int_ref=0.0): """Calculate the effective transversal relaxation rate from the peak intensities. The equation depends on the experiment type chosen, either 'cpmg' or 'r1rho'. @@ -600,7 +600,7 @@ spin.dw = param_vector[5] - def exp_type(self, exp='cpmg'): + def exp_type(self, exp_type='cpmg'): """Function for selecting the relaxation dispersion experiment type performed. @keyword exp: The relaxation dispersion experiment type. Can be one of 'cpmg' or 'r1rho'. @type exp: str @@ -622,18 +622,18 @@ raise RelaxNoSequenceError # CPMG relaxation dispersion experiments. - if exp == 'cpmg': + if exp_type == 'cpmg': print "CPMG relaxation dispersion experiments." cdp.exp_type = 'cpmg' # R1rho relaxation dispersion experiments. - elif exp == 'r1rho': + elif exp_type == 'r1rho': print "R1rho relaxation dispersion experiments." cdp.exp_type = 'r1rho' # Invalid relaxation dispersion experiment. else: - raise RelaxError, "The relaxation dispersion experiment '" + exp + "' is invalid." + raise RelaxError, "The relaxation dispersion experiment '" + exp_type + "' is invalid." def grid_search(self, lower=None, upper=None, inc=None, constraints=True, verbosity=1, sim_index=None): Modified: branches/relax_disp/test_suite/unit_tests/_prompt/test_relax_disp.py URL: http://svn.gna.org/viewcvs/relax/branches/relax_disp/test_suite/unit_tests/_prompt/test_relax_disp.py?rev=8686&r1=8685&r2=8686&view=diff ============================================================================== --- branches/relax_disp/test_suite/unit_tests/_prompt/test_relax_disp.py (original) +++ branches/relax_disp/test_suite/unit_tests/_prompt/test_relax_disp.py Tue Jan 27 22:47:00 2009 @@ -26,7 +26,7 @@ # relax module imports. from prompt.relax_disp import Relax_disp -from relax_errors import RelaxNoneNumError, RelaxStrError +from relax_errors import RelaxNoneNumError, RelaxNumError, RelaxStrError # Unit test imports. from data_types import DATA_TYPES @@ -38,6 +38,70 @@ # Instantiate the user function class. relax_disp_fns = Relax_disp(fake_relax.fake_instance()) + + + def test_relax_calc_r2eff_argfail_exp_type(self): + """The exp_type arg test of the relax_disp.relax_calc_r2eff() user function.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the str arguments, and skip them. + if data[0] == 'str': + continue + + # The argument test. + self.assertRaises(RelaxStrError, self.relax_disp_fns.calc_r2eff, exp_type=data[1]) + + def test_relax_calc_r2eff_argfail_id(self): + """The id arg test of the relax_disp.relax_calc_r2eff() user function.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the str arguments, and skip them. + if data[0] == 'str': + continue + + # The argument test. + self.assertRaises(RelaxStrError, self.relax_disp_fns.calc_r2eff, id=data[1]) + + + def test_relax_calc_r2eff_argfail_delayT(self): + """The delayT arg test of the relax_disp.relax_calc_r2eff() user function.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the float, int and None arguments, and skip them. + if data[0] == 'float' or data[0] == 'int' or data[0] == 'None': + continue + + # The argument test. + self.assertRaises(RelaxNoneNumError, self.relax_disp_fns.calc_r2eff, delayT=data[1]) + + + def test_relax_calc_r2eff_argfail_int_cpmg(self): + """The int_cpmg arg test of the relax_disp.relax_calc_r2eff() user function.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the float, int and None arguments, and skip them. + if data[0] == 'float' or data[0] == 'int': + continue + + # The argument test. + self.assertRaises(RelaxNumError, self.relax_disp_fns.calc_r2eff, int_cpmg=data[1]) + + + def test_relax_calc_r2eff_argfail_int_ref(self): + """The int_ref arg test of the relax_disp.relax_calc_r2eff() user function.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the float, int and None arguments, and skip them. + if data[0] == 'float' or data[0] == 'int': + continue + + # The argument test. + self.assertRaises(RelaxNumError, self.relax_disp_fns.calc_r2eff, int_ref=data[1]) def test_relax_cpmg_delayT_argfail_id(self): @@ -92,8 +156,8 @@ self.assertRaises(RelaxStrError, self.relax_disp_fns.cpmg_frq, spectrum_id=data[1]) - def test_relax_exp_type_argfail_exp(self): - """The exp arg test of the relax_disp.exp_type() user function.""" + def test_relax_exp_type_argfail_exp_type(self): + """The exp_type arg test of the relax_disp.exp_type() user function.""" # Loop over the data types. for data in DATA_TYPES: @@ -102,7 +166,7 @@ continue # The argument test. - self.assertRaises(RelaxStrError, self.relax_disp_fns.exp_type, exp=data[1]) + self.assertRaises(RelaxStrError, self.relax_disp_fns.exp_type, exp_type=data[1]) def test_relax_select_model_argfail_model(self):