Ejemplo n.º 1
0
    def parseLine(self, line):
        self.__keyword = None
        self.__comment_index = -1
        self.__text = line
        self.__arguments_index = -1
        self.__arguments = []

        comment_match = re.match(ConfigurationLineParser.COMMENT_PATTERN, line)
        if comment_match is not None:
            self.__comment_index = comment_match.start(1)
            line = line[0:comment_match.start(1)]

        keyword_match = re.match(ConfigurationLineParser.KEYWORD_PATTERN, line)
        if keyword_match is not None:
            self.__keyword = Keyword(keyword_match.start(1),
                                     keyword_match.end(1), line)
            self.__arguments_index = keyword_match.end(1)

        if self.hasKeyword():
            argument_match = ConfigurationLineParser.ARGUMENT_PATTERN.finditer(
                line)

            for match in argument_match:
                self.__arguments.append(
                    Argument(match.start(1), match.end(1), line))
Ejemplo n.º 2
0
    def __matchArguments(self, keyword, arg_defs, args):
        """
         @type keyword: Keyword
         @type arg_defs: list of ArgumentDefinition
         @type args: list of Argument
         @rtype: list of Argument
        """
        arg_def_count = len(arg_defs)
        arg_count = len(args)

        if arg_count > arg_def_count:
            # merge last input arguments

            last_arg_def = arg_defs[len(arg_defs) - 1]

            if last_arg_def.consumeRestOfLine():
                from_arg = args[arg_def_count - 1]
                to_arg = args[arg_count - 1]

                last_argument = Argument(from_arg.fromIndex(),
                                         to_arg.toIndex(), keyword.line())
                args = args[0:arg_def_count]
                args[len(args) - 1] = last_argument

            else:
                from_arg = args[arg_def_count]
                to_arg = args[arg_count - 1]

                last_argument = Argument(from_arg.fromIndex(),
                                         to_arg.toIndex(), keyword.line())
                args = args[0:arg_def_count]
                args.append(last_argument)

        if arg_count < arg_def_count:
            # pad with empty arguments
            line = keyword.line()

            for index in range(arg_def_count - arg_count):
                empty_argument = Argument(len(line), len(line), line)
                args.append(empty_argument)

        for index in range(len(args)):
            if index < len(arg_defs):
                args[index].setArgumentDefinition(arg_defs[index])

        return args
Ejemplo n.º 3
0
    def test_configuration_line(self):

        keyword_def = KeywordDefinition("KEYWORD")
        arg1_def = StringArgument()

        line = "KEYWORD string 2"
        keyword = Keyword(0, 7, line)
        self.assertEqual(keyword.value(), "KEYWORD")

        keyword.setKeywordDefinition(keyword_def)

        arg1 = Argument(8, 14, line)
        self.assertEqual(arg1.value(), "string")
        arg1.setArgumentDefinition(arg1_def)

        arg2 = Argument(15, 16, line)
        self.assertEqual(arg2.value(), "2")

        cl = ConfigurationLine(
            keyword=keyword,
            arguments=[arg1, arg2],
            documentation_link="help",
            group="test_group",
            required=True,
        )

        self.assertTrue(cl.keyword().hasKeywordDefinition())
        self.assertEqual(cl.keyword().keywordDefinition(), keyword_def)

        self.assertEqual(len(cl.arguments()), 2)

        self.assertEqual(cl.arguments()[0], arg1)
        self.assertTrue(cl.arguments()[0].hasArgumentDefinition())
        self.assertEqual(cl.arguments()[0].argumentDefinition(), arg1_def)

        self.assertEqual(cl.arguments()[1], arg2)
        self.assertFalse(cl.arguments()[1].hasArgumentDefinition())
        self.assertIsNone(cl.arguments()[1].argumentDefinition())

        self.assertFalse(cl.validationStatusForToken(keyword))
        self.assertTrue(cl.validationStatusForToken(arg1))
        self.assertFalse(cl.validationStatusForToken(arg2))
Ejemplo n.º 4
0
    def test_configuration_line_creation(self):
        line = "KEYWORD arg1"
        keyword = Keyword(0, 7, line)
        argument = Argument(8, 12, line)
        cl = ConfigurationLine(keyword=keyword,
                               arguments=[argument],
                               documentation_link="help/link",
                               group="group",
                               required=True)

        self.assertEqual(cl.keyword(), keyword)
        self.assertEqual(cl.arguments()[0], argument)

        self.assertEqual(cl.documentationLink(), "help/link")
        self.assertEqual(cl.group(), "group")
        self.assertTrue(cl.isRequired())

        self.assertFalse(cl.validationStatusForToken(keyword))
        self.assertFalse(cl.validationStatusForToken(argument))
Ejemplo n.º 5
0
    def test_argument(self):
        text = "KEYWORD arg1 arg2"

        arg1 = Argument(8, 12, text)
        arg1.setArgumentDefinition(StringArgument())

        arg2 = Argument(13, 17, text)

        self.assertEqual(arg1.value(), "arg1")
        self.assertEqual(arg2.value(), "arg2")

        self.assertEqual(arg2.line(), text)

        self.assertTrue(arg1.hasArgumentDefinition())
        self.assertIsInstance(arg1.argumentDefinition(), StringArgument)

        self.assertFalse(arg2.hasArgumentDefinition())
        self.assertIsNone(arg2.argumentDefinition())