def test_executable(self): addr = (None, 8888) run_file(addr, 'spam.py', _run=self._run) self.assertEqual(self.argv, _get_args('--file', 'spam.py', prog=sys.argv[0])) self.assertEqual(self.addr, Address.as_server(*addr)) self.assertEqual(self.kwargs, {})
def test_server(self): addr = Address.as_server('10.0.1.1', 8888) run_file(addr, 'spam.py', _run=self._run, _prog='eggs') self.assertEqual(self.argv, _get_args('--file', 'spam.py')) self.assertEqual(self.addr, Address.as_server(*addr)) self.assertEqual(self.kwargs, {})
def test_run(self): pydevd = FakePyDevd('pydevd/pydevd.py', self._main) addr = (None, 8888) run_file(addr, 'spam.py', _pydevd=pydevd, _install=self._install) self.assertEqual(self.pydevd, pydevd) self.assertEqual(self.addr, Address.as_server(*addr)) self.assertEqual(self.kwargs, {}) self.assertEqual(self.maincalls, 1) self.assertEqual(sys.argv, _get_args('--file', 'spam.py', prog=sys.argv[0])) self.assertEqual(self.exitcode, -1)
def test_extra(self): addr = (None, 8888) run_file(addr, 'spam.py', '--vm_type', 'xyz', '--', '--DEBUG', _run=self._run, _prog='eggs') self.assertEqual(self.argv, _get_args( '--file', 'spam.py', '--DEBUG', ptvsd_extras=['--vm_type', 'xyz'])) self.assertEqual(self.addr, Address.as_server(*addr)) self.assertEqual(self.kwargs, {})
def test_remote_localhost(self): addr = Address.as_client(None, 8888) run_file(addr, 'spam.py', _run=self._run, _prog='eggs') self.assertEqual(self.argv, _get_args( '--file', 'spam.py', ptvsd_extras=['--client', 'localhost'])) self.assertEqual(self.addr, Address.as_client(*addr)) self.assertEqual(self.kwargs, { 'singlesession': True, })
def test_exit(self): self.mainexc = SystemExit(1) pydevd = FakePyDevd('pydevd/pydevd.py', self._main) addr = (None, 8888) with self.assertRaises(SystemExit): run_file(addr, 'spam.py', _pydevd=pydevd, _install=self._install) self.assertEqual(self.pydevd, pydevd) self.assertEqual(self.addr, Address.as_server(*addr)) self.assertEqual(self.kwargs, {}) self.assertEqual(self.maincalls, 1) self.assertEqual(sys.argv, _get_args('--file', 'spam.py', prog=sys.argv[0])) self.assertEqual(self.exitcode, 1)
def test_failure(self): self.mainexc = RuntimeError('boom!') pydevd = FakePyDevd('pydevd/pydevd.py', self._main) addr = (None, 8888) with self.assertRaises(RuntimeError) as cm: run_file(addr, 'spam.py', _pydevd=pydevd, _install=self._install) exc = cm.exception self.assertEqual(self.pydevd, pydevd) self.assertEqual(self.addr, Address.as_server(*addr)) self.assertEqual(self.kwargs, {}) self.assertEqual(self.maincalls, 1) self.assertEqual(sys.argv, _get_args('--file', 'spam.py', prog=sys.argv[0])) self.assertEqual(self.exitcode, -1) # TODO: Is this right? self.assertIs(exc, self.mainexc)
def test_installed(self): pydevd = FakePyDevd('pydevd/pydevd.py', self._main) addr = (None, 8888) run_file(addr, 'spam.py', _pydevd=pydevd) __main__ = sys.modules['__main__'] expected_server = ptvsd.pydevd_hooks.start_server expected_client = ptvsd.pydevd_hooks.start_client for mod in (pydevd_comm, pydevd, __main__): start_server = getattr(mod, 'start_server') if hasattr(start_server, 'orig'): start_server = start_server.orig start_client = getattr(mod, 'start_client') if hasattr(start_client, 'orig'): start_client = start_client.orig self.assertIs(start_server, expected_server, '(module {})'.format(mod.__name__)) self.assertIs(start_client, expected_client, '(module {})'.format(mod.__name__))