示例#1
0
文件: test.py 项目: caktus/tracerlib
    def test_incall(self):
        self.tracer.watch('testmod.a')

        with self.tm:
            self.assertFalse(self.tracer.incall)
            def test():
                self.assertTrue(self.tracer.incall)
            with mock.patch('testmod.b', test):
                testmod.a()
示例#2
0
    def test_incall(self):
        self.tracer.watch('testmod.a')

        with self.tm:
            self.assertFalse(self.tracer.incall)

            def test():
                self.assertTrue(self.tracer.incall)

            with mock.patch('testmod.b', test):
                testmod.a()
示例#3
0
文件: test.py 项目: caktus/tracerlib
    def test_child_tracer(self):
        t = mock.Mock()
        self.tracer.watch('testmod.a')
        child = tracerlib.Tracer(t, ['call'], ['testmod.b'], parent=self.tracer)
        self.tm.add(child)

        self.assertEqual(0, t.call_count, 'Tracer called before even enabling!')
        with self.tm:
            self.assertEqual(0, t.call_count, 'Tracer called before calling function!')
            testmod.b()
            self.assertEqual(0, t.call_count, 'Tracer called when parent was not in-call!')

        with self.tm:
            testmod.a()
            self.assertEqual(1, t.call_count)
示例#4
0
    def test_child_tracer(self):
        t = mock.Mock()
        self.tracer.watch('testmod.a')
        child = tracerlib.Tracer(t, ['call'], ['testmod.b'],
                                 parent=self.tracer)
        self.tm.add(child)

        self.assertEqual(0, t.call_count,
                         'Tracer called before even enabling!')
        with self.tm:
            self.assertEqual(0, t.call_count,
                             'Tracer called before calling function!')
            testmod.b()
            self.assertEqual(0, t.call_count,
                             'Tracer called when parent was not in-call!')

        with self.tm:
            testmod.a()
            self.assertEqual(1, t.call_count)