Ejemplo n.º 1
0
    def test_ValueAccumulator(self):

        events = []
        with EventCatcher(events):
            ac = ValueAccumulator(name="ac")
            THREAD_DISPATCHER.add_listener(ac)

            try:
                value("s1", 1, auto_add_counter=False)
                value("s1", 2, auto_add_counter=False)
                value("s2", 5, auto_add_counter=False)

                ac.raise_value_events()

            finally:
                THREAD_DISPATCHER.remove_listener(ac)

        self.assertEqual(events,
                [
                    ("s1", "value", 1),
                    ("s1", "value", 2),
                    ("s2", "value", 5),
                    ("ac.s2", "value", 5),
                    ("ac.s1", "value", 3),
                ]
            )
Ejemplo n.º 2
0
    def test_ThreadTimeCategorizer(self):
        tc = ThreadTimeCategorizer("tc", ["cat1", "cat2", "f"], timer_class=FakeTimer)
        THREAD_DISPATCHER.add_listener(tc)

        try:
            @report_start_end("cat1")
            def cat1():
                pass

            @report_start_end("cat2")
            def cat2():
                pass

            @report_start_end()
            def multicat():
                cat1()
                cat2()

            def f():
                with report_start_end("f"):
                    multicat()
                    cat1()

            f()

            events = []
            with EventCatcher(events):
                tc.raise_value_events()

            self.assertEqual(events,
                [
                    ("tc.cat1", "value", 2.0),
                    ("tc.cat2", "value", 1.0),
                    ("tc.f", "value", 4.0),
                ]
            )

        finally:
            THREAD_DISPATCHER.remove_listener(tc)
Ejemplo n.º 3
0
 def __exit__(self,exc_type, exc_value, traceback):
     THREAD_DISPATCHER.remove_listener(self.event_trace)
Ejemplo n.º 4
0
 def __enter__(self):
     self.event_trace = self.create_listener(self.event_store)
     THREAD_DISPATCHER.add_listener(self.event_trace)