# Path: debugger/debugger_api.py
# class StartupInfo(object):
#     def __init__(self, cmd_arguments="", working_directory="", env_vars=None):
#         """
#         @type cmd_arguments: str
#         @type working_directory: str
#         @type env_vars: list of tuple of (str, str)
#         """
#         self.cmd_arguments = cmd_arguments
#         self.working_directory = working_directory
#         self.env_vars = env_vars if env_vars is not None else []
# 
#     def copy(self):
#         return StartupInfo(self.cmd_arguments,
#                            self.working_directory,
#                            list(self.env_vars))
# 
#     def __repr__(self):
#         return "StartupInfo: [{}, {}, {}]".format(
#             self.cmd_arguments, self.working_directory, self.env_vars
#         )
# 
# Path: tests/conftest.py
# def setup_debugger(debugger, binary, lines, on_state_change=None,
#                    startup_info=None, cont=True, wait=True):
#     assert debugger.load_binary("src/{}".format(binary))
# 
#     test_exception = []
# 
#     if not isinstance(lines, Iterable):
#         lines = [lines]
# 
#     for line in lines:
#         assert debugger.breakpoint_manager.add_breakpoint(
#             "src/{}.cpp".format(binary), line)
# 
#     if on_state_change:
#         def on_stop(state, data):
#             if state == ProcessState.Stopped:
#                 try:
#                     on_state_change()
#                     if cont:
#                         debugger.exec_continue()
#                 except Exception as exc:
#                     test_exception.append(traceback.format_exc(exc))
#                     debugger.quit_program()
# 
#         debugger.on_process_state_changed.subscribe(on_stop)
# 
#     assert debugger.launch(startup_info)
# 
#     if wait:
#         debugger.wait_for_exit()
# 
#     if len(test_exception) > 0:
#         pytest.fail(test_exception[0], pytrace=False)


import os
from debugger.debugger_api import StartupInfo
from tests.conftest import setup_debugger
# -*- coding: utf-8 -*-



TEST_FILE = "test_startup_info"
TEST_LINE = 15


def test_startup_info(debugger):
    """
    @type debugger: debugger.debugger_api.Debugger
    """
    env_value = "test test_env"
    startup_info = StartupInfo("test1 test2", os.getcwd(),
                               [("DEVI_ENV_TEST", env_value)])

    def test_startup_info_cb():
        lines = []

        for x in xrange(5):
            lines.append(debugger.io_manager.stdout.readline()[:-1])

        assert lines == [
            "3",
            os.path.abspath("src/{}".format(TEST_FILE)),
            "test1",
            "test2",
            env_value
        ]


# Path: debugger/debugger_api.py
# class StartupInfo(object):
#     def __init__(self, cmd_arguments="", working_directory="", env_vars=None):
#         """
#         @type cmd_arguments: str
#         @type working_directory: str
#         @type env_vars: list of tuple of (str, str)
#         """
#         self.cmd_arguments = cmd_arguments
#         self.working_directory = working_directory
#         self.env_vars = env_vars if env_vars is not None else []
# 
#     def copy(self):
#         return StartupInfo(self.cmd_arguments,
#                            self.working_directory,
#                            list(self.env_vars))
# 
#     def __repr__(self):
#         return "StartupInfo: [{}, {}, {}]".format(
#             self.cmd_arguments, self.working_directory, self.env_vars
#         )
# 
# Path: tests/conftest.py
# def setup_debugger(debugger, binary, lines, on_state_change=None,
#                    startup_info=None, cont=True, wait=True):
#     assert debugger.load_binary("src/{}".format(binary))
# 
#     test_exception = []
# 
#     if not isinstance(lines, Iterable):
#         lines = [lines]
# 
#     for line in lines:
#         assert debugger.breakpoint_manager.add_breakpoint(
#             "src/{}.cpp".format(binary), line)
# 
#     if on_state_change:
#         def on_stop(state, data):
#             if state == ProcessState.Stopped:
#                 try:
#                     on_state_change()
#                     if cont:
#                         debugger.exec_continue()
#                 except Exception as exc:
#                     test_exception.append(traceback.format_exc(exc))
#                     debugger.quit_program()
# 
#         debugger.on_process_state_changed.subscribe(on_stop)
# 
#     assert debugger.launch(startup_info)
# 
#     if wait:
#         debugger.wait_for_exit()
# 
#     if len(test_exception) > 0:
#         pytest.fail(test_exception[0], pytrace=False)


# Path: tests/test_mi_startup_info.py
import os
from debugger.debugger_api import StartupInfo
from tests.conftest import setup_debugger

# -*- coding: utf-8 -*-



TEST_FILE = "test_startup_info"
TEST_LINE = 15


def test_startup_info(debugger):
    """
    @type debugger: debugger.debugger_api.Debugger
    """
    env_value = "test test_env"
    startup_info = StartupInfo("test1 test2", os.getcwd(),
                               [("DEVI_ENV_TEST", env_value)])

    def test_startup_info_cb():
        lines = []

        for x in xrange(5):
            lines.append(debugger.io_manager.stdout.readline()[:-1])

        assert lines == [
            "3",
            os.path.abspath("src/{}".format(TEST_FILE)),
            "test1",
            "test2",
            env_value
        ]


    setup_debugger(debugger, TEST_FILE, TEST_LINE,