Skip to content

Commit c81a645

Browse files
committed
Changes based on codeql
1 parent 41dc8c2 commit c81a645

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

qa/L0_trace/opentelemetry_unittest.py

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions
@@ -28,9 +28,11 @@
2828

2929
sys.path.append("../common")
3030

31-
import test_util as tu
32-
import unittest
3331
import json
32+
import unittest
33+
34+
import test_util as tu
35+
3436

3537
class OpenTelemetryTest(tu.TestResultCollector):
3638

@@ -113,7 +115,10 @@ def _check_parent(self, child_span, parent_span):
113115
# Check that child and parent span have the same trace_id
114116
# and child's `parent_span_id` is the same as parent's `span_id`
115117
self.assertEqual(child_span['trace_id'], parent_span['trace_id'])
116-
self.assertTrue('parent_span_id' in child_span)
118+
self.assertIn(
119+
'parent_span_id',
120+
child_span,
121+
"child span does not have parent span id specified")
117122
self.assertEqual(child_span['parent_span_id'], parent_span['span_id'])
118123

119124
def test_spans(self):
@@ -127,13 +132,13 @@ def test_spans(self):
127132

128133
# There should be 6 spans in total:
129134
# 3 for http request and 3 for grpc request.
130-
self.assertTrue(len(self.spans) == 6)
135+
self.assertEqual(len(self.spans), 6)
131136
# We should have 2 compute spans
132-
self.assertTrue(parsed_spans.count("compute"), 2)
137+
self.assertEqual(parsed_spans.count("compute"), 2)
133138
# 2 request spans (named simple - same as our model name)
134-
self.assertTrue(parsed_spans.count(self.model_name), 2)
139+
self.assertEqual(parsed_spans.count(self.model_name), 2)
135140
# 2 root spans
136-
self.assertTrue(parsed_spans.count(self.root_span), 2)
141+
self.assertEqual(parsed_spans.count(self.root_span), 2)
137142

138143
def test_nested_spans(self):
139144

@@ -146,15 +151,21 @@ def test_nested_spans(self):
146151
self._check_parent(child, parent)
147152

148153
# root_span should not have `parent_span_id` field
149-
self.assertFalse('parent_span_id' in self.spans[2])
154+
self.assertNotIn(
155+
'parent_span_id',
156+
self.spans[2],
157+
"root span has a parent_span_id specified")
150158

151159
# Last 3 spans in `self.spans` belong to GRPC request
152160
# Order of spans and their relationship described earlier
153161
for child, parent in zip(self.spans[3:], self.spans[4:]):
154162
self._check_parent(child, parent)
155163

156164
# root_span should not have `parent_span_id` field
157-
self.assertFalse('parent_span_id' in self.spans[5])
165+
self.assertNotIn(
166+
'parent_span_id',
167+
self.spans[5],
168+
"root span has a parent_span_id specified")
158169

159170

160171
if __name__ == '__main__':

0 commit comments

Comments
 (0)