Skip to content

Commit

Permalink
reformat and make sure it could pass lint check
Browse files Browse the repository at this point in the history
  • Loading branch information
zhihali committed Jun 6, 2024
1 parent b049e2a commit a317c5e
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2065,25 +2065,38 @@ def test_tracer_provider_init_default(self, resource_patch, sample_patch):


class TestRandomIdGenerator(unittest.TestCase):
_TRACE_ID_MAX_VALUE = 2 ** 128 - 1
_SPAN_ID_MAX_VALUE = 2 ** 64 - 1
_TRACE_ID_MAX_VALUE = 2**128 - 1
_SPAN_ID_MAX_VALUE = 2**64 - 1

@patch('random.getrandbits', side_effect=[span.INVALID_SPAN_ID, 0x00000000DEADBEF0])
@patch(
"random.getrandbits",
side_effect=[span.INVALID_SPAN_ID, 0x00000000DEADBEF0],
)
def test_generate_span_id_avoids_invalid(self, mock_getrandbits):
generator = RandomIdGenerator()
span_id = generator.generate_span_id()

self.assertNotEqual(span_id, span.INVALID_SPAN_ID)
self.assertGreater(span_id, span.INVALID_SPAN_ID)
self.assertLessEqual(span_id, self._SPAN_ID_MAX_VALUE)
self.assertEqual(mock_getrandbits.call_count, 2) # Ensure exactly two calls

@patch('random.getrandbits', side_effect=[span.INVALID_TRACE_ID, 0x000000000000000000000000DEADBEEF])
self.assertEqual(
mock_getrandbits.call_count, 2
) # Ensure exactly two calls

@patch(
"random.getrandbits",
side_effect=[
span.INVALID_TRACE_ID,
0x000000000000000000000000DEADBEEF,
],
)
def test_generate_trace_id_avoids_invalid(self, mock_getrandbits):
generator = RandomIdGenerator()
trace_id = generator.generate_trace_id()

self.assertNotEqual(trace_id, span.INVALID_TRACE_ID)
self.assertGreater(trace_id, span.INVALID_TRACE_ID)
self.assertLessEqual(trace_id, self._TRACE_ID_MAX_VALUE)
self.assertEqual(mock_getrandbits.call_count, 2) # Ensure exactly two calls
self.assertEqual(
mock_getrandbits.call_count, 2
) # Ensure exactly two calls

0 comments on commit a317c5e

Please sign in to comment.