Example #1
0
    def process_tests(self):
        """
        Iterates over test cases within the test script and parses each test case.
        """
        tests = self.raw_data.get("tests")
        test_list = []
        if tests is None:
            self.script.set_tests(test_list)
            self.valid_script = False
            return

        # Build event list
        for curr_test in tests:
            instruction_list = []
            test = Test()
            commands = curr_test["instructions"]
            default_index = -1
            for _, command in enumerate(commands):
                data = command.get("data")
                args = None if data is None else data.get("args")
                args = self.sanitize_args(args)
                if args is not None:
                    command["args"] = args

                if "function" in command:
                    params = None if command is None else command.get("params")
                    params = self.sanitize_args(params)
                    if params is not None:
                        command["params"] = params

                    inline_commands = self.resolve_function(command["function"], command["params"], self.functions)
                    if inline_commands is None:
                        log.error("Failed to process test case due to the error(s) above. Skipping {}".format(
                            curr_test["case_number"]
                        ))
                        instruction_list = []
                        break
                    if not inline_commands:
                        log.error("No commands in function {}".format(command["function"]))
                        continue
                    if "wait" in command:
                        function_call_delay = command["wait"]
                    else:
                        function_call_delay = 1.0

                    function_disabled = bool(command.get('disabled', False))
                    for c_index, c_inline in enumerate(inline_commands):
                        delay = 0
                        if "wait" in c_inline.keys():
                            delay = c_inline["wait"]
                        if c_index == 0:
                            delay += function_call_delay
                        disabled = function_disabled or bool(c_inline.get('disabled', False))
                        instruction_list.append(Instruction(delay, c_inline, len(test_list), default_index, disabled))
                else:
                    delay = 0
                    if "wait" in command.keys():
                        delay = command["wait"]
                    disabled = bool(command.get('disabled', False))
                    instruction_list.append(Instruction(delay, command, len(test_list), default_index, disabled))

            for i, _ in enumerate(instruction_list):
                instruction_list[i].command_index = i

            test.test_info = {"test_case": curr_test["case_number"], "description": curr_test["description"]}
            test.instructions = instruction_list
            test_list.append(test)
        self.script.set_tests(test_list)
Example #2
0
    def process_tests(self):
        cur_time = 0.0
        tests = self.raw_data.get("tests")
        test_list = []
        if tests is None:
            self.script.tests = test_list
            self.valid_script = False
            return

        # Build event list
        for curr_test in tests:
            event_list = []
            test = Test()
            commands = curr_test["instructions"]
            for index, command in enumerate(commands):
                data = command.get("data")
                args = None if data is None else data.get("args")
                args = self.sanitize_args(args)
                if args is not None:
                    command["args"] = args

                if "function" in command:
                    params = None if command is None else command.get("params")
                    params = self.sanitize_args(params)
                    if params is not None:
                        command["params"] = params

                    inline_commands = self.resolve_function(
                        command["function"], command["params"], self.functions)
                    if inline_commands is None:
                        log.error(
                            "Failed to process test case due to the error(s) above. Skipping {}"
                            .format(curr_test["case_number"]))
                        event_list = []
                        break
                    if not commands:
                        log.error("No commands in function {}".format(
                            command["function"]))
                        continue
                    if "wait" in command:
                        function_call_delay = command["wait"]
                    else:
                        function_call_delay = 1.0

                    disabled = bool(command.get('disabled', False))
                    for c_index, c in enumerate(inline_commands):
                        # Set the default delay value of 0
                        # then obtain wait value from test script
                        delay = 0
                        if "wait" in c.keys():
                            delay = c["wait"]
                        if c_index == 0:
                            delay += function_call_delay
                        disabled |= bool(c.get('disabled', False))
                        event_list.append(
                            Command(delay, c, len(test_list), -1, disabled))
                else:
                    delay = 0
                    if "wait" in command.keys():
                        delay = command["wait"]
                    disabled = bool(command.get('disabled', False))
                    event_list.append(
                        Command(delay, command, len(test_list), -1, disabled))

            for i in range(len(event_list)):
                event_list[i].command_index = i

            test.test_info = {
                "test_case": curr_test["case_number"],
                "description": curr_test["description"]
            }
            test.event_list = event_list
            test_list.append(test)
        self.script.tests = test_list