Author: bugman Date: Tue Nov 24 10:32:01 2009 New Revision: 9894 URL: http://svn.gna.org/viewcvs/relax?rev=9894&view=rev Log: Created unit tests for the specific_fns API. This checks the consistency of methods across the API, using method names and arg checks. Only the frame order theories are currently checked. Added: 1.3/test_suite/unit_tests/_specific_fns/test_api.py - copied, changed from r9890, 1.3/test_suite/unit_tests/_generic_fns/_structure/test_api_base.py Copied: 1.3/test_suite/unit_tests/_specific_fns/test_api.py (from r9890, 1.3/test_suite/unit_tests/_generic_fns/_structure/test_api_base.py) URL: http://svn.gna.org/viewcvs/relax/1.3/test_suite/unit_tests/_specific_fns/test_api.py?p2=1.3/test_suite/unit_tests/_specific_fns/test_api.py&p1=1.3/test_suite/unit_tests/_generic_fns/_structure/test_api_base.py&r1=9890&r2=9894&rev=9894&view=diff ============================================================================== --- 1.3/test_suite/unit_tests/_generic_fns/_structure/test_api_base.py (original) +++ 1.3/test_suite/unit_tests/_specific_fns/test_api.py Tue Nov 24 10:32:01 2009 @@ -27,15 +27,14 @@ from unittest import TestCase # relax module imports. -from generic_fns.structure.api_base import Base_struct_API -from generic_fns.structure.internal import Internal -from generic_fns.structure.scientific import Scientific_data +from specific_fns.api_base import Base_API +from specific_fns.frame_order import Frame_order -class Test_api_base(TestCase): - """Unit tests for the structural API base class.""" +class Test_api(TestCase): + """Unit tests for the specific_fns API.""" - def format_method(self, name, args, varargs, varkw, defaults): + def __format_method(self, name, args, varargs, varkw, defaults): """Method for formatting the method.""" # Method start. @@ -71,22 +70,25 @@ return text - def test_Internal_method_args(self): - """The args of the public methods of the Internal structural object must be the same as the API base class.""" + def __check_method_args(self, analysis_obj): + """Check the args of all API methods. - # The base and internal objects. - base = Base_struct_API() - intern = Internal() + @param analysis_obj: The specific analysis object. + @type analysis_obj: instance + """ - # Loop over the objects in the internal object. - for name in dir(intern): + # The base object. + base = Base_API() + + # Loop over the objects of the specific analysis. + for name in dir(analysis_obj): # Skip anything starting with '_'. if search('^_', name): continue # Get the object in the two classes. obj_base = getattr(base, name) - obj_intern = getattr(intern, name) + obj = getattr(analysis_obj, name) # Skip non-method objects. if not isinstance(obj_base, types.MethodType): @@ -94,97 +96,55 @@ # Get the args and their default values. args_base, varargs_base, varkw_base, defaults_base = getargspec(obj_base) - args_intern, varargs_intern, varkw_intern, defaults_intern = getargspec(obj_intern) + args, varargs, varkw, defaults = getargspec(obj) # Check the args. - if args_base != args_intern or varargs_base != varargs_intern or varkw_base != varkw_intern or defaults_base != defaults_intern: + if args_base != args or varargs_base != varargs or varkw_base != varkw or defaults_base != defaults: # Get string representations of the methods. - doc_base = self.format_method(name, args_base, varargs_base, varkw_base, defaults_base) - doc_intern = self.format_method(name, args_intern, varargs_intern, varkw_intern, defaults_intern) + doc_base = self.__format_method(name, args_base, varargs_base, varkw_base, defaults_base) + doc = self.__format_method(name, args, varargs, varkw, defaults) print(doc_base) # Fail. - self.fail('The args of the method\n\t' + doc_intern + '\ndo not match those of the API method\n\t' + doc_base) + self.fail('The args of the method\n\t' + doc + '\ndo not match those of the API method\n\t' + doc_base) - def test_Internal_objects(self): - """Are the initial public objects of the Internal structural object all within the API base class?""" + def __check_objects(self, analysis_obj): + """Check the args of all API methods. - # The base and internal objects. - base = Base_struct_API() - internal = Internal() + @param analysis_obj: The specific analysis object. + @type analysis_obj: instance + """ + + # The base object. + base = Base_API() # The objects in the base class. base_names = dir(base) - # Loop over the objects in the internal object. - for name in dir(internal): + # Loop over the objects of the specific analysis. + for name in dir(analysis_obj): # Skip anything starting with '_'. if search('^_', name): continue # Get the object in the derived class. - obj = getattr(internal, name) + obj = getattr(analysis_obj, name) # Not present. if name not in base_names: - self.fail('The object ' + repr(name) + ' ' + repr(type(obj)) + ' cannot be found in the structural API base class.') + self.fail('The object ' + repr(name) + ' ' + repr(type(obj)) + ' cannot be found in the API base class.') - def test_Scientific_method_args(self): - """The args of the public methods of the Scientific structural object must be the same as the API base class.""" + def test_frame_order_method_args(self): + """The args of the public methods of the frame order object must be the same as the API base class.""" - # The base and Scientific objects. - base = Base_struct_API() - sci = Scientific_data() - - # Loop over the objects in the Scientific object. - for name in dir(sci): - # Skip anything starting with '_'. - if search('^_', name): - continue - - # Get the object in the two classes. - obj_base = getattr(base, name) - obj_sci = getattr(sci, name) - - # Skip non-method objects. - if not isinstance(obj_base, types.MethodType): - continue - - # Get the args and their default values. - args_base, varargs_base, varkw_base, defaults_base = getargspec(obj_base) - args_sci, varargs_sci, varkw_sci, defaults_sci = getargspec(obj_sci) - - # Check the args. - if args_base != args_sci or varargs_base != varargs_sci or varkw_base != varkw_sci or defaults_base != defaults_sci: - # Get string representations of the methods. - doc_base = self.format_method(name, args_base, varargs_base, varkw_base, defaults_base) - doc_sci = self.format_method(name, args_sci, varargs_sci, varkw_sci, defaults_sci) - - # Fail. - self.fail('The args of the method\n\t' + doc_sci + '\ndo not match those of the API method\n\t' + doc_base) + # Check. + self.__check_method_args(Frame_order()) - def test_Scientific_objects(self): - """Are the initial public objects of the Scientific structural object all within the API base class?""" + def test_frame_order_objects(self): + """Are the initial public objects of the frame order object all within the API base class?""" - # The base and Scientific objects. - base = Base_struct_API() - sci = Scientific_data() - - # The objects in the base class. - base_names = dir(base) - - # Loop over the objects in the Scientific object. - for name in dir(sci): - # Skip anything starting with '_'. - if search('^_', name): - continue - - # Get the object in the derived class. - obj = getattr(sci, name) - - # Not present. - if name not in base_names: - self.fail('The object ' + repr(name) + ' ' + repr(type(obj)) + ' cannot be found in the structural API base class.') + # Check. + self.__check_objects(Frame_order())