Ejemplo n.º 1
0
 def parse(self, params_def, params_str, params):
     """Helper method to test parameters parsing. To be used with
     insertTest decorator.
     """
     p = ParamParser(params_def)
     result = p.parse(params_str)
     msg = "Parsing failed (result: %r; expected: %r)" % \
           (result, params)
     self.assertListEqual(result, params, msg)
Ejemplo n.º 2
0
 def parse(self, params_def, params_str, params):
     """Helper method to test parameters parsing. To be used with
     insertTest decorator.
     """
     p = ParamParser(params_def)
     result = p.parse(params_str)
     msg = "Parsing failed (result: %r; expected: %r)" % \
           (result, params)
     self.assertListEqual(result, params, msg)
Ejemplo n.º 3
0
def split_macro_parameters(parameters_s, params_def):
    """Split string with macro parameters into a list with macro parameters.
    Whitespaces are the separators between the parameters.

    Repeat parameters are encapsulated in square brackets and its internal
    repetitions, if composed from more than one item are also encapsulated
    in brackets. In this case the output list contains lists internally.

    :param parameters_s: input string containing parameters
    :type parameters_s: string
    :return:  parameters represented as a list (may contain internal lists
    :rtype: list
    """
    parser = ParamParser(params_def)
    return parser.parse(parameters_s)
Ejemplo n.º 4
0
def split_macro_parameters(parameters_s, params_def):
    """Split string with macro parameters into a list with macro parameters.
    Whitespaces are the separators between the parameters.

    Repeat parameters are encapsulated in square brackets and its internal
    repetitions, if composed from more than one item are also encapsulated
    in brackets. In this case the output list contains lists internally.

    :param parameters_s: input string containing parameters
    :type parameters_s: string
    :return:  parameters represented as a list (may contain internal lists
    :rtype: list
    """
    parser = ParamParser(params_def)
    return parser.parse(parameters_s)
Ejemplo n.º 5
0
 def runMacro(self):
     '''execute the macro with the current arguments'''
     if self.door is None:
         return
     param_defs = self.door.macro_server.getMacroInfoObj(
         self.macro_name).parameters
     parser = ParamParser(param_defs)
     parameters = parser.parse(" ".join(self.macro_args))
     try:
         self.door.runMacro(self.macro_name, parameters)
         sec_xml = self.door.getRunningXML()
         # get the id of the current running macro
         self.macro_id = sec_xml[0].get("id")
     except Exception as e:
         self.ui.button.setChecked(False)
         raise e
Ejemplo n.º 6
0
 def verifyXML(self, macro_name, param_def, param_str, expected_xml_rep):
     """
     Helper to verify the generated XML of a macroNode
     :param macro_name: (str) name of the macro
     :param param_def:   (list<dict>) macro parameters definition
     :param param_value: (list<str>) list of strins representing macro
         parameters values
     :param expected_xml_rep: "pretty print" string representation of a XML
         macroNode
     """
     param_parser = ParamParser(param_def)
     param_value = param_parser.parse(param_str)
     # Create the MacroNide with the inputs
     macronode = createMacroNode(macro_name, param_def, param_value)
     # Get the MacroNode equivalent XML tree
     macronode_xml = macronode.toXml()
     # Create a XML tree
     expected_xml = etree.fromstring(expected_xml_rep)
     # Validate the XML tree
     self._validateXML(macronode_xml, expected_xml)
Ejemplo n.º 7
0
 def verifyXML(self, macro_name, param_def, param_str, expected_xml_rep):
     """
     Helper to verify the generated XML of a macroNode
     :param macro_name: (str) name of the macro
     :param param_def:   (list<dict>) macro parameters definition
     :param param_value: (list<str>) list of strins representing macro
         parameters values
     :param expected_xml_rep: "pretty print" string representation of a XML
         macroNode
     """
     param_parser = ParamParser(param_def)
     param_value = param_parser.parse(param_str)
     # Create the MacroNide with the inputs
     macronode = createMacroNode(macro_name, param_def, param_value)
     # Get the MacroNode equivalent XML tree
     macronode_xml = macronode.toXml()
     # Create a XML tree
     expected_xml = etree.fromstring(expected_xml_rep)
     # Validate the XML tree
     self._validateXML(macronode_xml, expected_xml)
Ejemplo n.º 8
0
 def fromPlainText(self, plainTextMacros, macroInfos):
     for plainTextMacro, macroInfo in zip(plainTextMacros, macroInfos):
         macro = MacroNode(self, macro_info=macroInfo)
         self.insertChild(macro)
         # ignore the macro name and if there are parameters parse them
         try:
             plainTextParams = plainTextMacro.split(" ", 1)[1]
         except IndexError:
             continue
         paramsDef = macroInfo.parameters
         try:
             macroParams = ParamParser(paramsDef).parse(plainTextParams)
         except ParseError as e:
             msg = "{0} can not be parsed ({1})".format(plainTextMacro, e)
             # TODO: think of using `raise from` syntax
             raise ValueError(msg)
         macro.fromList(macroParams)