예제 #1
0
def create(args):
    caseFile, caseDirs = find_cases(args.cases)

    for caseDir in caseDirs:
        exp = Expander(caseDir)
        for test in exp.expand('utf-8', caseFile):
            if args.out:
                try:
                    test_file = os.path.join(args.out, test.file_name)
                    test_mtime = os.path.getmtime(test_file)

                    if args.no_clobber:
                        print_error(
                            'Refusing to overwrite file: ' + test.file_name)
                        exit(1)

                    if not args.regenerate:
                        source_files = test.source_file_names
                        if all(test_mtime > os.path.getmtime(f) for f in source_files):
                            continue

                    existing = Test(test_file)
                    existing.load()
                    if not existing.is_generated():
                        print_error(
                            'Refusing to overwrite non-generated file: ' +
                            test.file_name)
                        exit(1)
                except (OSError, IOError):
                    pass

                test.write(args.out, parents=args.parents)
            else:
                print(test.to_string())
예제 #2
0
def create(args):
    caseFile, caseDirs = find_cases(args.cases)

    for caseDir in caseDirs:
        exp = Expander(caseDir)
        for test in exp.expand('utf-8', caseFile):
            if args.out:
                try:
                    existing = Test(test.file_name)
                    existing.load(args.out)

                    if args.no_clobber:
                        print_error('Refusing to overwrite file: ' +
                                    test.file_name)
                        exit(1)

                    if not existing.is_generated():
                        print_error(
                            'Refusing to overwrite non-generated file: ' +
                            test.file_name)
                        exit(1)
                except IOError:
                    pass

                test.write(args.out, parents=args.parents)
            else:
                print(test.to_string())
예제 #3
0
def create(args):
    caseFile, caseDirs = find_cases(args.cases)

    for caseDir in caseDirs:
        exp = Expander(caseDir)
        for test in exp.expand('utf-8', caseFile):
            if args.out:
                try:
                    existing = Test(test.file_name)
                    existing.load(args.out)

                    if args.no_clobber:
                        print_error(
                            'Refusing to overwrite file: ' + test.file_name)
                        exit(1)

                    if not existing.is_generated():
                        print_error(
                            'Refusing to overwrite non-generated file: ' +
                            test.file_name)
                        exit(1)
                except IOError:
                    pass

                test.write(args.out, parents=args.parents)
            else:
                print(test.to_string())
예제 #4
0
def clean(args):
    for (subdir, _, fileNames) in os.walk(args.directory):
        for fileName in map(lambda x: os.path.join(subdir, x), fileNames):
            test = Test(fileName)
            test.load()
            if test.is_generated():
                print('Deleting file "' + fileName + '"...')
                os.remove(fileName)
예제 #5
0
def clean(args):
    for (subdir, _, fileNames) in os.walk(args.directory):
        for fileName in map(lambda x: os.path.join(subdir, x), fileNames):
            test = Test(fileName)
            test.load()
            if test.is_generated():
                print('Deleting file "' + fileName + '"...')
                os.remove(fileName)
예제 #6
0
def _test_instance_inited():
    Global.set_time_manager(Mock())
    test = Test()
    status_manager = StatusManager(port=None)
    script_reader = JSONScriptReader(
        'functional_tests/cfe_6_7_tests/cfe_tests/CfeEsTest.json')
    script_reader.process_tests()
    script_list = [script_reader.script]
    status_manager.set_scripts(script_list)

    instructions = script_reader.script.tests[0].instructions
    test.instructions = instructions

    status_manager.start()
    test.status_manager = status_manager
    return test
예제 #7
0
def input_test() -> Test:
    print('Введите тест. Когда тест закончится, введите пустую строку.')
    input_text = list(iter(input, '')).join('\n')

    print('Введите ответ. Когда ответ закончится, введите пустую строку.')
    output_text = list(iter(input, '')).join('\n')

    return Test(input_text=input_text.strip(), output_text=output_text.strip())
예제 #8
0
    def run(self):
        Test.run(self)

        connection2 = Telnet()
        connection2.connect()
        connection2.expect("Welcome\n")
        message1 = "MESSAGE1"
        message2 = "MESSAGE2"

        connection2.send(message1)
        result1 = self.connection.expect(message1 + "\r")

        self.connection.send(message2)
        result2 = connection2.expect(message2 + "\r")

        connection2.close()
        return result1 and result2
예제 #9
0
def test_test_init_warning(utils):
    """
    test Test class constructor -- warning
    """
    utils.clear_log()
    with patch("lib.ctf_global.Global.config") as mock_config:
        mock_config.get.return_value = None
        test = Test()
        assert utils.has_log_level('WARNING')
예제 #10
0
파일: local.py 프로젝트: karpp/tester
def _text_to_test(text: str) -> Test:
    input_text, output_text = text.split('\n\n')

    return Test(input_text=input_text.strip(), output_text=output_text.strip())
예제 #11
0
 def run(self):
     Test.run(self)
     message = "MESSAGE"
     self.connection.send(message)
     self.connection.close()
     sleep(0.05)
예제 #12
0
def test_test_process_command_delay(test_instance):
    """
    test Test class static  method: process_command_delay
    Utilize the current CTF time manager to wait a specific amount of time before executing a CTF Test Instruction
    """
    assert Test.process_command_delay(1) is None
예제 #13
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
예제 #14
0
 def run(self):
     return Test.run(self)
예제 #15
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)
예제 #16
0
def load_tests(url, contest, problem):
    return [
        Test(input_text, output_text) for row_contest, row_problem, input_text,
        output_text, *_ in csv.reader(io.StringIO(requests.get(url).text))
        if row_contest == contest and row_problem == problem
    ]
예제 #17
0
def _test_instance():
    return Test()