Example #1
0
 def test_unsupported_arg(self):
     with self.assertRaises(SystemExit):
         with captured_stdio():
             parse_args([
                 'eggs',
                 '--port', '8888',
                 '--xyz', '123',
                 'spam.py',
             ])
    def test_exception_breakpoints(self):
        self.vsc.PRINT_RECEIVED_MESSAGES = True
        done, script = self._set_lock('h')
        self.lifecycle.requests = []  # Trigger capture.
        config = {
            'breakpoints': [],
            'excbreakpoints': [
                {
                    'filters': ['raised']
                },
            ],
        }
        with captured_stdio() as (stdout, _):
            with self.launched(config=config):
                with self.fix.hidden():
                    _, tid = self.get_threads(self.thread.name)
                with self.wait_for_event('stopped'):
                    done()
                with self.wait_for_event('continued'):
                    req_continue_last = self.send_request(
                        'continue', {
                            'threadId': tid,
                        })
                # Allow the script to run to completion.
                received = self.vsc.received
        out = stdout.getvalue()

        got = []
        for req, resp in self.lifecycle.requests:
            if req['command'] == 'setExceptionBreakpoints':
                got.append(req['arguments'])
            self.assertNotEqual(req['command'], 'setBreakpoints')
        self.assertEqual(got, config['excbreakpoints'])
        if sys.version_info >= (3, 7):
            description = "MyError('ka-boom')"
        else:
            description = "MyError('ka-boom',)"
        self.assert_contains(received, [
            self.new_event(
                'stopped',
                **dict(reason='exception',
                       threadId=tid,
                       text='MyError',
                       description=description)),
            self.new_response(req_continue_last),
            self.new_event('continued', **dict(threadId=tid, )),
        ])
        self.assertIn('2 4 4', out)
        self.assertIn('ka-boom', out)
Example #3
0
    def test_no_breakpoints(self):
        self.lifecycle.requests = []
        config = {
            'breakpoints': [],
            'excbreakpoints': [],
        }
        with captured_stdio() as (stdout, _):
            with self.launched(config=config):
                # Allow the script to run to completion.
                time.sleep(1.)
        out = stdout.getvalue()

        for req, _ in self.lifecycle.requests:
            self.assertNotEqual(req['command'], 'setBreakpoints')
            self.assertNotEqual(req['command'], 'setExceptionBreakpoints')
        self.assertIn('2 4 4', out)
        self.assertIn('ka-boom', out)
Example #4
0
    def test_breakpoints_single_file(self):
        done1, _ = self._set_lock('d')
        done2, script = self._set_lock('h')
        lineno = find_line(script, 'b')
        self.lifecycle.requests = []  # Trigger capture.
        config = {
            'breakpoints': [{
                'source': {
                    'path': self.filename
                },
                'breakpoints': [
                    {
                        'line': lineno
                    },
                ],
            }],
            'excbreakpoints': [],
        }
        with captured_stdio(out=True, err=True) as (stdout, stderr):
            #with self.wait_for_event('exited', timeout=3):
            with self.launched(config=config):
                with self.fix.hidden():
                    _, tid = self.get_threads(self.thread.name)
                with self.wait_for_event('stopped'):
                    done1()
                with self.wait_for_event('stopped'):
                    with self.wait_for_event('continued'):
                        req_continue1 = self.send_request(
                            'continue', {
                                'threadId': tid,
                            })
                with self.wait_for_event('stopped'):
                    with self.wait_for_event('continued'):
                        req_continue2 = self.send_request(
                            'continue', {
                                'threadId': tid,
                            })
                with self.wait_for_event('continued'):
                    req_continue_last = self.send_request(
                        'continue', {
                            'threadId': tid,
                        })

                # Allow the script to run to completion.
                received = self.vsc.received
                done2()
        out = stdout.getvalue()
        err = stderr.getvalue()

        got = []
        for req, resp in self.lifecycle.requests:
            if req['command'] == 'setBreakpoints':
                got.append(req['arguments'])
            self.assertNotEqual(req['command'], 'setExceptionBreakpoints')
        self.assertEqual(got, config['breakpoints'])

        self.assert_contains(received, [
            self.new_event(
                'stopped',
                reason='breakpoint',
                threadId=tid,
                text=None,
                description=None,
                preserveFocusHint=False,
            ),
            self.new_response(req_continue1, allThreadsContinued=True),
            self.new_event('continued', threadId=tid),
            self.new_event(
                'stopped',
                reason='breakpoint',
                threadId=tid,
                text=None,
                description=None,
                preserveFocusHint=False,
            ),
            self.new_response(req_continue2, allThreadsContinued=True),
            self.new_event('continued', threadId=tid),
            self.new_event(
                'stopped',
                reason='breakpoint',
                threadId=tid,
                text=None,
                description=None,
                preserveFocusHint=False,
            ),
            self.new_response(req_continue_last, allThreadsContinued=True),
            self.new_event('continued', threadId=tid),
        ])
        self.assertIn('2 4 4', out)
        self.assertIn('ka-boom', err)