Example #1
0
    def test_to_dict(self, mock_time):
        pt = tracer.TracePoint("import_line", level=2)
        pt_child = tracer.TracePoint("import_child")
        pt.add_child(pt_child)
        pt.start()
        pt_child.start()
        pt_child.stop()
        pt.stop()

        expected_pt_child_dict = {
            "started_at": 2,
            "finished_at": 3,
            "duration": 1000,
            "import_line": "import_child",
            "level": 3,
            "children": []
        }

        exepected_pt_dict = {
            "started_at": 1,
            "finished_at": 4,
            "duration": 3000,
            "import_line": "import_line",
            "level": 2,
            "children": [expected_pt_child_dict]
        }

        self.assertEqual(expected_pt_child_dict, pt_child.to_dict())
        self.assertEqual(exepected_pt_dict, pt.to_dict())
Example #2
0
 def test_init(self):
     pt = tracer.TracePoint("some_import_line", level=10)
     self.assertEqual(0, pt.started_at)
     self.assertEqual(0, pt.finished_at)
     self.assertEqual("some_import_line", pt.import_line)
     self.assertEqual(10, pt.level)
     self.assertEqual([], pt.children)
Example #3
0
    def test_add_child(self):
        pt = tracer.TracePoint("import_line")
        pt_child1 = tracer.TracePoint("import_line")
        pt_child11 = tracer.TracePoint("import_line")
        pt_child12 = tracer.TracePoint("import_line")
        pt_child2 = tracer.TracePoint("import_line")

        pt.add_child(pt_child1)
        pt_child1.add_child(pt_child11)
        pt_child1.add_child(pt_child12)
        pt.add_child(pt_child2)

        self.assertEqual([pt_child11, pt_child12], pt_child1.children)
        self.assertEqual([pt_child1, pt_child2], pt.children)

        self.assertEqual(0, pt.level)
        self.assertEqual(1, pt_child1.level)
        self.assertEqual(1, pt_child2.level)
        self.assertEqual(2, pt_child11.level)
        self.assertEqual(2, pt_child12.level)
Example #4
0
 def test_stop(self, mock_time):
     pt = tracer.TracePoint("import_line")
     pt.stop()
     self.assertEqual(10, pt.finished_at)
Example #5
0
    def test_context(self, mock_time):
        with tracer.TracePoint("some_import_line") as pt:
            self.assertEqual(1, pt.started_at)

        self.assertEqual(2, pt.finished_at)