コード例 #1
0
    def test_patch_trace(self, mock_patch_trace):
        trace_id = Trace.new_trace_id()
        trace = Trace.new(self.sdk, trace_id=trace_id)

        trace.end()
        mock_patch_trace.assert_called_once()
        mock_patch_trace.assert_called_with(trace)
コード例 #2
0
    def test_iadd_raises_ValueError(self):
        trace_id = Trace.new_trace_id()
        trace = Trace.new(self.sdk, trace_id=trace_id)

        span = trace.span()
        self.assertIn(span, trace.spans)

        self.assertRaises(ValueError, operator.iadd, trace, span)
コード例 #3
0
    def test_span_no_parent_with_root_span_id(self):
        trace_id = Trace.new_trace_id()
        trace = Trace.new(self.sdk, trace_id=trace_id, root_span_id=123)
        parent_span = None

        span = trace.span(parent_span=parent_span)
        self.assertIsInstance(span, Span)
        self.assertEqual(trace.spans, [span])
        self.assertEqual(span.parent_span_id, 123)
コード例 #4
0
    def test_span_parent(self):
        trace_id = Trace.new_trace_id()
        trace = Trace.new(self.sdk, trace_id=trace_id)
        parent_span = Span.new(trace, Span.new_span_id())

        span = trace.span(parent_span=parent_span)
        self.assertIsInstance(span, Span)
        self.assertEqual(trace.spans, [span])
        self.assertIs(span.parent_span_id, parent_span.span_id)
コード例 #5
0
    def test_init(self):
        trace_id = Trace.new_trace_id()

        trace = Trace.new(self.sdk, trace_id=trace_id, root_span_id=123)

        self.assertEqual(trace.trace_id, trace_id)
        self.assertEqual(trace.sdk, self.sdk)
        self.assertEqual(trace.spans, [])
        self.assertEqual(self.sdk.project_id, trace.project_id)
        self.assertEqual(trace.root_span_id, 123)
コード例 #6
0
    def test_len(self):
        trace_id = Trace.new_trace_id()
        trace = Trace.new(self.sdk, trace_id=trace_id)

        self.assertEqual(len(trace), 0)
        self.assertFalse(trace)

        l = 10
        trace._spans = range(l)
        self.assertEqual(len(trace), l)
コード例 #7
0
    def test_context_manager(self, mock_patch_trace):
        trace_id = Trace.new_trace_id()
        trace = Trace.new(self.sdk, trace_id=trace_id)

        with trace as t:
            self.assertIs(trace, t)
            mock_patch_trace.assert_not_called()

        mock_patch_trace.assert_called_once()
        mock_patch_trace.assert_called_with(trace)
コード例 #8
0
    def test_setters(self):
        trace_id = Trace.new_trace_id()

        trace = Trace.new(self.sdk, trace_id=trace_id, root_span_id=123)
        self.assertEqual(trace.root_span_id, 123)

        trace.root_span_id = 456
        self.assertEqual(trace.root_span_id, 456)

        trace.trace_id = 789
        self.assertEqual(trace.trace_id, 789)
コード例 #9
0
    def test_export_empty_spans(self):
        trace_id = Trace.new_trace_id()
        trace = Trace.new(self.sdk, trace_id=trace_id)

        for data in [trace.export(), json.loads(trace.json)]:
            self.assertIsInstance(data, {}.__class__)
            self.assertSetEqual(
                set(data.keys()),
                {'projectId', 'traceId', 'spans'},
            )
            self.assertEqual(data['projectId'], self.sdk.project_id)
            self.assertEqual(data['traceId'], trace_id)
            self.assertEqual(data['spans'], [])
コード例 #10
0
    def test_insert_raises_TypeError(self):
        current_trace = self.sdk.current_trace

        for i in [Trace(self.sdk), self.sdk, 123, 'abc']:
            self.assertRaises(TypeError, current_trace.insert, 0, i)
コード例 #11
0
 def test_set_item_raises_TypeError(self):
     for i in [Trace(self.sdk), self.sdk, 123, 'abc']:
         self.assertRaises(TypeError, operator.setitem, i, 0, i)
コード例 #12
0
    def test_iadd_raises_TypeError(self):
        trace_id = Trace.new_trace_id()
        trace = Trace.new(self.sdk, trace_id=trace_id)

        self.assertRaises(TypeError, operator.iadd, trace, 1)