コード例 #1
0
ファイル: core.py プロジェクト: melviso/python2-trepan
    def start(self, opts=None):
        """ We've already created a debugger object, but here we start
        debugging in earnest. We can also turn off debugging (but have
        the hooks suspended or not) using 'stop'.

        'opts' is a hash of every known value you might want to set when
        starting the debugger. See START_OPTS of module default.
        """

        # The below is our fancy equivalent of:
        #    sys.settrace(self._trace_dispatch)
        try:
            self.trace_hook_suspend = True
            get_option = lambda key: Mmisc.option_set(opts, key,
                                                      default.START_OPTS)

            add_hook_opts = get_option('add_hook_opts')

            # Has tracer been started?
            if not tracer.is_started() or get_option('force'):
                # FIXME: should filter out opts not for tracer
                # Also, if we use opts.copy we need to check for 'None'.
                tracer_start_opts = default.START_OPTS.copy()
                tracer_start_opts['trace_fn'] = self.trace_dispatch
                tracer_start_opts['add_hook_opts'] = add_hook_opts
                tracer.start(tracer_start_opts)
            elif not tracer.find_hook(self.trace_dispatch):
                tracer.add_hook(self.trace_dispatch, add_hook_opts)
                pass
            self.execution_status = 'Running'
        finally:
            self.trace_hook_suspend = False
        return
コード例 #2
0
ファイル: core.py プロジェクト: yssource/python3-trepan
    def start(self, opts=None):
        """ We've already created a debugger object, but here we start
        debugging in earnest. We can also turn off debugging (but have
        the hooks suspended or not) using 'stop'.

        'opts' is a hash of every known value you might want to set when
        starting the debugger. See START_OPTS of module default.
        """

        # The below is our fancy equivalent of:
        #    sys.settrace(self._trace_dispatch)
        try:
            self.trace_hook_suspend = True
            get_option = lambda key: Mmisc.option_set(opts, key,
                                                      default.START_OPTS)

            add_hook_opts = get_option('add_hook_opts')

            # Has tracer been started?
            if not tracer.is_started() or get_option('force'):
                # FIXME: should filter out opts not for tracer

                tracer_start_opts = default.START_OPTS.copy()
                if opts:
                    tracer_start_opts.update(opts.get('tracer_start', {}))
                tracer_start_opts['trace_fn'] = self.trace_dispatch
                tracer_start_opts['add_hook_opts'] = add_hook_opts
                tracer.start(tracer_start_opts)
            elif not tracer.find_hook(self.trace_dispatch):
                tracer.add_hook(self.trace_dispatch, add_hook_opts)
                pass
            self.execution_status = 'Running'
        finally:
            self.trace_hook_suspend = False
        return
コード例 #3
0
ファイル: test-basic.py プロジェクト: rocky/pytracer
    def test_basic(self):
        """Basic sanity and status testing."""
        tracer.HOOKS = []
        self.assertEqual(0, tracer.size())
        self.assertEqual(False, tracer.is_started())
        tracer.start()
        self.assertEqual(True, tracer.is_started())

        tracer.stop()
        self.assertEqual(False, tracer.is_started())
        self.assertEqual(1, tracer.add_hook(my_trace_dispatch,
                                            {'backlevel': 1}))
        self.assertEqual(0, len(trace_lines))

        tracer.start()
        self.assertEqual(0, len(trace_lines))
        self.assertEqual(True, tracer.is_started())
        self.assertEqual(
            0, tracer.remove_hook(my_trace_dispatch, stop_if_empty=True))
        self.assertEqual(False, tracer.is_started())
        self.assertEqual(
            1,
            tracer.add_hook(my_trace_dispatch, {
                'start': True,
                'backlevel': 1
            }))
        self.assertEqual(True, tracer.is_started())
        tracer.clear_hooks_and_stop()
        return
コード例 #4
0
 def test_add_hook(self):
     """Basic sanity and status testing."""
     self.assertEqual(0, tracer.size())
     self.assertEqual(1, tracer.add_hook(trace_dispatch1))
     self.assertEqual(2, tracer.add_hook(trace_dispatch2))
     self.assertEqual(trace_dispatch1, tracer.HOOKS[0][0])
     self.assertEqual(trace_dispatch2, tracer.HOOKS[1][0])
     self.assertEqual(3, tracer.add_hook(trace_dispatch3,
                                         {'position': 0}))
     self.assertEqual(trace_dispatch3, tracer.HOOKS[0][0])
     self.assertEqual(trace_dispatch1, tracer.HOOKS[1][0])
     self.assertEqual(trace_dispatch2, tracer.HOOKS[2][0])
     return
コード例 #5
0
ファイル: test-basic.py プロジェクト: rocky/pytracer
    def test_trace_filtering(self):
        """Test that trace hook is triggering event callbacks with filtering."""
        global ignore_filter
        ignore_filter = tracefilter.TraceFilter()
        tracer.clear_hooks_and_stop()
        self.assertEqual(
            1,
            tracer.add_hook(my_trace_dispatch, {
                'start': True,
                'event_set': frozenset(('call', ))
            }))

        def foo():
            pass

        foo()
        tracer.stop()
        global trace_lines
        import pprint
        #         for entry in trace_lines:
        #             print entry.event, entry.filename, entry.lineno, entry.name
        self.assertTrue(
            len(trace_lines) >= 2, 'Should have captured some trace output')
        for i, right in [(-1, (
                'call',
                'stop',
        )), (-2, (
                'call',
                'foo',
        ))]:
            self.assertEqual(right, (
                trace_lines[i].event,
                trace_lines[i].name,
            ))
        return
コード例 #6
0
ファイル: test-basic.py プロジェクト: rocky/pytracer
    def test_errors(self):
        """Test various error conditions."""
        # 5 is not a function
        self.assertRaises(TypeError, tracer.add_hook, *(5, ))

        # test_errors has the wrong number of args
        self.assertRaises(TypeError, tracer.add_hook, *(self.test_errors, ))

        def wrong_fn_args(a, b):
            pass

        self.assertRaises(TypeError, tracer.add_hook, *(wrong_fn_args, ))

        tracer.clear_hooks
        self.assertEqual(1, tracer.add_hook(self.method_trace_dispatch))
        return
コード例 #7
0
ファイル: test-basic.py プロジェクト: rocky/pytracer
    def test_trace(self):
        """Test that trace hook is triggering event callbacks without filtering."""
        tracer.clear_hooks_and_stop()
        self.assertEqual(
            1,
            tracer.add_hook(my_trace_dispatch, {
                'start': True,
                'backlevel': 1
            }))

        def squares():
            j = 1
            for i in range(5):
                j += j + 2
                pass
            return

        squares()
        tracer.stop()
        global trace_lines
        import pprint
        #         for entry in trace_lines:
        #            print entry.event, entry.filename, entry.lineno, entry.name
        self.assertTrue(
            len(trace_lines) >= 5, 'Should have captured some trace output')
        for i, right in [(-1, (
                'return',
                'squares',
        )), (-2, (
                'line',
                'squares',
        ))]:
            self.assertEqual(right, (
                trace_lines[i].event,
                trace_lines[i].name,
            ))
        return