Exemplo n.º 1
0
    def decode(self,
               params_def,
               params_raw,
               expected_params=None,
               expected_exception=None):
        """Test decoding of macro parameters using ParamDecoder class by
        comparing the result with either of the expected_params or the
        expcted_exception result, not both of them.

        :param params_def: list(dict) where each dict represents one parameter
            definition (required keys: name, type, default_value, description
            and min & max in case of the repeat parameters)
        :param params_raw: list of parameter values or XML strucutre with
            parameter values
        :param expected_params: list of the expected parameter values after the
            decoding process
        :param expected_exception: expected exception class
        """
        if expected_params is None and expected_exception is None:
            raise ValueError("missing expected_params or expected_exception")
        if not expected_params is None and not expected_exception is None:
            raise ValueError("too many expected expected values")
        exception = None
        try:
            param_decoder = ParamDecoder(self.type_manager, params_def,
                                         params_raw)
        except Exception, e:
            exception = e
Exemplo n.º 2
0
    def decode(self,
               params_def,
               params_raw,
               expected_params=None,
               expected_exception=None):
        """Test decoding of macro parameters using ParamDecoder class by
        comparing the result with either of the expected_params or the
        expcted_exception result, not both of them.

        :param params_def: list(dict) where each dict represents one parameter
            definition (required keys: name, type, default_value, description
            and min & max in case of the repeat parameters)
        :param params_raw: list of parameter values or XML strucutre with
            parameter values
        :param expected_params: list of the expected parameter values after the
            decoding process
        :param expected_exception: expected exception class
        """
        if expected_params is None and expected_exception is None:
            raise ValueError("missing expected_params or expected_exception")
        if not expected_params is None and not expected_exception is None:
            raise ValueError("too many expected expected values")
        exception = None
        try:
            param_decoder = ParamDecoder(self.type_manager, params_def,
                                         params_raw)
        except Exception as e:
            exception = e
        if expected_params:
            exception_message = getattr(exception, "message", None)
            msg = "unexpected exception: %s (%s)" % (exception,
                                                     exception_message)
            self.assertIsNone(exception, msg)
            params = param_decoder.getParamList()
            msg = ("decoding result (%s) does not match with the expected"
                   " result (%s)" % (params, expected_params))
            self.assertListEqual(params, expected_params, msg)
        if expected_exception:
            msg = ("decoding exception type (%s) does not match with the"
                   " expected exception type (%s)" %
                   (type(exception), expected_exception))
            self.assertIsInstance(exception, expected_exception, msg)
Exemplo n.º 3
0
 def decodeControllerParameters(self, in_par_list):
     if len(in_par_list) == 0:
         raise RuntimeError('Controller name not specified')
     controller_name_or_klass = in_par_list[0]
     controller_class = controller_name_or_klass
     if type(controller_class) in types.StringTypes:
         controller_class = self.getControllerClass(controller_class)
     if controller_class is None:
         raise UnknownController("Unknown controller %s" % controller_name_or_klass)
     from sardana.macroserver.msparameter import ParamDecoder
     out_par_list = ParamDecoder(controller_class, in_par_list)
     return controller_class, in_par_list, out_par_list