diff --git a/tests/helpers/debugadapter.py b/tests/helpers/debugadapter.py index c888dbb6..42ade8bc 100644 --- a/tests/helpers/debugadapter.py +++ b/tests/helpers/debugadapter.py @@ -10,16 +10,25 @@ class DebugAdapter(Closeable): PORT = 8888 @classmethod - def start(cls, argv, host='localhost', port=None, script=None): + def start(cls, argv, **kwargs): + def new_proc(argv, host, port): + argv = list(argv) + cls._ensure_addr(argv, host, port) + return Proc.start_python_module('ptvsd', argv) + return cls._start(new_proc, argv, **kwargs) + + @classmethod + def start_wrapper_script(cls, filename, argv, **kwargs): + def new_proc(argv, host, port): + return Proc.start_python_script(filename, argv) + return cls._start(new_proc, argv, **kwargs) + + @classmethod + def _start(cls, new_proc, argv, host='localhost', port=None): if port is None: port = cls.PORT addr = (host, port) - argv = list(argv) - cls._ensure_addr(argv, host, port) - if script is not None: - proc = Proc.start_python_script(script, argv) - else: - proc = Proc.start_python_module('ptvsd', argv) + proc = new_proc(argv, host, port) return cls(proc, addr, owned=True) @classmethod diff --git a/tests/helpers/debugclient.py b/tests/helpers/debugclient.py index ed459b49..e8efaab7 100644 --- a/tests/helpers/debugclient.py +++ b/tests/helpers/debugclient.py @@ -79,16 +79,22 @@ class _LifecycleClient(Closeable): if self._adapter is not None: self._adapter.close() - def _launch(self, argv, script=None, wait_for_attach=None, + def _launch(self, argv, script=None, wait_for_connect=None, detachable=True, **kwargs): - self._adapter = DebugAdapter.start( + if script is not None: + def start(*args, **kwargs): + return DebugAdapter.start_wrapper_script(script, + *args, **kwargs) + else: + start = DebugAdapter.start + self._adapter = start( argv, host='localhost' if detachable else None, port=self._port, - script=script, ) - if wait_for_attach: - wait_for_attach() + + if wait_for_connect: + wait_for_connect() else: self._attach(**kwargs) @@ -105,6 +111,7 @@ class DebugClient(_LifecycleClient): """A high-level abstraction of a debug client (i.e. editor).""" # TODO: Manage breakpoints, etc. + # TODO: Add debugger methods here (e.g. "pause"). class EasyDebugClient(DebugClient): @@ -140,12 +147,11 @@ class EasyDebugClient(DebugClient): warnings.warn('timed out waiting for connection') if self._session is None: raise RuntimeError('unable to connect') - # Close the adapter when the session closes. - self._session.manage_adapter(self._adapter) + # The adapter will close when the connection does. self._launch( argv, script=script, - wait_for_attach=wait, + wait_for_connect=wait, detachable=False, ) diff --git a/tests/helpers/debugsession.py b/tests/helpers/debugsession.py index c1545eee..bc7a7058 100644 --- a/tests/helpers/debugsession.py +++ b/tests/helpers/debugsession.py @@ -51,7 +51,7 @@ class DebugSessionConnection(Closeable): def connect(addr, timeout): server = create_server(addr) with socket_timeout(server, timeout): - client = server.accept() + client, _ = server.accept() return Connection(client, server) return cls._create(connect, addr, **kwargs)