예제 #1
0
    def __init__(self, s, debug):
        threading.Thread.__init__(self)
        self.daemon = True
        self._debug = debug
        self._socket = s
        self._write_queue = queue.Queue()
        self.configuration_done = threading.Event()
        self.terminated = threading.Event()

        log = get_log()
        if debug:
            log.debug("Patching execution context...")

            from robotframework_debug_adapter.debugger_impl import (
                patch_execution_context,
            )

            try:
                import robot
            except ImportError:
                # If unable to import robot, don't error here (proceed as if
                # it was without debugging -- it should fail later on when
                # about to run the code, at which point the actual DAP is
                # in place).
                self._debugger_impl = None
            else:
                debugger_impl = patch_execution_context()
                debugger_impl.busy_wait.before_wait.append(self._notify_stopped)

                log.debug("Finished patching execution context.")
                self._debugger_impl = debugger_impl
        else:
            self._debugger_impl = None
예제 #2
0
def test_debugger_core_for(debugger_api, run_robot_cli, data_regression):
    from robotframework_debug_adapter.debugger_impl import patch_execution_context
    from robotframework_debug_adapter.debugger_impl import RobotBreakpoint

    debugger_impl = patch_execution_context()
    target = debugger_api.get_dap_case_file(
        "case_control_flow/case_control_flow_for.robot"
    )
    line = debugger_api.get_line_index_with_content("Break 1", target)
    debugger_impl.set_breakpoints(target, RobotBreakpoint(line))

    busy_wait = DummyBusyWait(debugger_impl)
    debugger_impl.busy_wait = busy_wait
    busy_wait.on_wait = [
        debugger_impl.step_in,
        debugger_impl.step_in,
        debugger_impl.step_in,
        debugger_impl.step_continue,
    ]

    code = run_robot_cli(target)

    assert busy_wait.waited == 4
    assert busy_wait.proceeded == 4
    assert len(busy_wait.stack) == 4

    data_regression.check(stack_frames_repr(busy_wait))
    assert code == 0
예제 #3
0
def test_debugger_core_with_setup_teardown(
    debugger_api, run_robot_cli, data_regression
):
    from robotframework_debug_adapter.debugger_impl import patch_execution_context
    from robotframework_debug_adapter.debugger_impl import RobotBreakpoint

    debugger_impl = patch_execution_context()
    target = debugger_api.get_dap_case_file("case_setup_teardown.robot")
    debugger_impl.set_breakpoints(
        target,
        (
            RobotBreakpoint(
                debugger_api.get_line_index_with_content("Suite Setup", target)
            ),
            RobotBreakpoint(
                debugger_api.get_line_index_with_content("Suite Teardown", target)
            ),
        ),
    )

    busy_wait = DummyBusyWait(debugger_impl)
    debugger_impl.busy_wait = busy_wait
    busy_wait.on_wait = [debugger_impl.step_continue, debugger_impl.step_continue]

    code = run_robot_cli(target)

    assert busy_wait.waited == 2
    assert busy_wait.proceeded == 2
    assert len(busy_wait.stack) == 2

    data_regression.check(stack_frames_repr(busy_wait))

    assert code == 0
예제 #4
0
def test_debugger_core_step_out(debugger_api, run_robot_cli):
    from robotframework_debug_adapter.debugger_impl import patch_execution_context
    from robotframework_debug_adapter.debugger_impl import RobotBreakpoint

    debugger_impl = patch_execution_context()
    target = debugger_api.get_dap_case_file("case_step_out.robot")
    line = debugger_api.get_line_index_with_content("Break 1", target)
    debugger_impl.set_breakpoints(target, RobotBreakpoint(line))

    busy_wait = DummyBusyWait(debugger_impl)
    debugger_impl.busy_wait = busy_wait
    busy_wait.on_wait = [debugger_impl.step_out, debugger_impl.step_continue]

    code = run_robot_cli(target)

    assert busy_wait.waited == 2
    assert busy_wait.proceeded == 2
    assert len(busy_wait.stack) == 2
    assert [x.name for x in busy_wait.stack[0].dap_frames] == [
        "Should Be Equal",
        "My Equal Redefined",
        "TestCase: Can use resource keywords",
        "TestSuite: Case Step Out",
    ]
    assert [x.name for x in busy_wait.stack[1].dap_frames] == [
        "Yet Another Equal Redefined",
        "TestCase: Can use resource keywords",
        "TestSuite: Case Step Out",
    ]
    assert code == 0
예제 #5
0
def test_debugger_core(debugger_api, run_robot_cli):
    from robotframework_debug_adapter.debugger_impl import patch_execution_context
    from robotframework_debug_adapter.debugger_impl import RobotBreakpoint

    debugger_impl = patch_execution_context()
    target = debugger_api.get_dap_case_file("case_log.robot")
    debugger_api.target = target
    line = debugger_api.get_line_index_with_content("check that log works")
    debugger_impl.set_breakpoints(target, RobotBreakpoint(line))

    busy_wait = DummyBusyWait(debugger_impl)
    debugger_impl.busy_wait = busy_wait
    busy_wait.on_wait = [debugger_impl.step_continue]

    code = run_robot_cli(target)
    assert busy_wait.waited == 1
    assert busy_wait.proceeded == 1
    assert len(busy_wait.stack) == 1
    assert code == 0