Skip to content

Commit

Permalink
test: Refactor to use appropriate UT assertions where available
Browse files Browse the repository at this point in the history
Signed-off-by: Ferenc Géczi <ferenc.geczi@ibm.com>
  • Loading branch information
Ferenc- committed May 7, 2024
1 parent c68595b commit 7dfb921
Show file tree
Hide file tree
Showing 8 changed files with 352 additions and 352 deletions.
288 changes: 144 additions & 144 deletions tests/clients/test_couchbase.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/clients/test_google-cloud-pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_publish(self):
origin="instana")
time.sleep(2.0) # for sanity
result = future.result()
assert isinstance(result, six.string_types)
self.assertIsInstance(result, six.string_types)

spans = self.recorder.queued_spans()
gcps_span, test_span = spans[0], spans[1]
Expand All @@ -76,7 +76,7 @@ def test_publish_as_root_exit_span(self):
origin="instana")
time.sleep(2.0) # for sanity
result = future.result()
assert isinstance(result, six.string_types)
self.assertIsInstance(result, six.string_types)

spans = self.recorder.queued_spans()
self.assertEqual(1, len(spans))
Expand Down
60 changes: 30 additions & 30 deletions tests/frameworks/test_aiohttp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ async def test():
self.assertTrue(type(aiohttp_span.stack) is list)
self.assertTrue(len(aiohttp_span.stack) > 1)

assert "X-INSTANA-T" in response.headers
self.assertIn("X-INSTANA-T", response.headers)
self.assertEqual(response.headers["X-INSTANA-T"], traceId)
assert "X-INSTANA-S" in response.headers
self.assertIn("X-INSTANA-S", response.headers)
self.assertEqual(response.headers["X-INSTANA-S"], wsgi_span.s)
assert "X-INSTANA-L" in response.headers
self.assertIn("X-INSTANA-L", response.headers)
self.assertEqual(response.headers["X-INSTANA-L"], '1')
assert "Server-Timing" in response.headers
self.assertIn("Server-Timing", response.headers)
self.assertEqual(
response.headers["Server-Timing"], "intid;desc=%s" % traceId)

Expand Down Expand Up @@ -127,13 +127,13 @@ async def test():
self.assertTrue(type(aiohttp_span.stack) is list)
self.assertTrue(len(aiohttp_span.stack) > 1)

assert "X-INSTANA-T" in response.headers
self.assertIn("X-INSTANA-T", response.headers)
self.assertEqual(response.headers["X-INSTANA-T"], traceId)
assert "X-INSTANA-S" in response.headers
self.assertIn("X-INSTANA-S", response.headers)
self.assertEqual(response.headers["X-INSTANA-S"], wsgi_span2.s)
assert "X-INSTANA-L" in response.headers
self.assertIn("X-INSTANA-L", response.headers)
self.assertEqual(response.headers["X-INSTANA-L"], '1')
assert "Server-Timing" in response.headers
self.assertIn("Server-Timing", response.headers)
self.assertEqual(
response.headers["Server-Timing"], "intid;desc=%s" % traceId)

Expand Down Expand Up @@ -177,13 +177,13 @@ async def test():
self.assertTrue(type(aiohttp_span.stack) is list)
self.assertTrue(len(aiohttp_span.stack) > 1)

assert "X-INSTANA-T" in response.headers
self.assertIn("X-INSTANA-T", response.headers)
self.assertEqual(response.headers["X-INSTANA-T"], traceId)
assert "X-INSTANA-S" in response.headers
self.assertIn("X-INSTANA-S", response.headers)
self.assertEqual(response.headers["X-INSTANA-S"], wsgi_span.s)
assert "X-INSTANA-L" in response.headers
self.assertIn("X-INSTANA-L", response.headers)
self.assertEqual(response.headers["X-INSTANA-L"], '1')
assert "Server-Timing" in response.headers
self.assertIn("Server-Timing", response.headers)
self.assertEqual(
response.headers["Server-Timing"], "intid;desc=%s" % traceId)

Expand Down Expand Up @@ -229,13 +229,13 @@ async def test():
self.assertTrue(type(aiohttp_span.stack) is list)
self.assertTrue(len(aiohttp_span.stack) > 1)

assert "X-INSTANA-T" in response.headers
self.assertIn("X-INSTANA-T", response.headers)
self.assertEqual(response.headers["X-INSTANA-T"], traceId)
assert "X-INSTANA-S" in response.headers
self.assertIn("X-INSTANA-S", response.headers)
self.assertEqual(response.headers["X-INSTANA-S"], wsgi_span.s)
assert "X-INSTANA-L" in response.headers
self.assertIn("X-INSTANA-L", response.headers)
self.assertEqual(response.headers["X-INSTANA-L"], '1')
assert "Server-Timing" in response.headers
self.assertIn("Server-Timing", response.headers)
self.assertEqual(
response.headers["Server-Timing"], "intid;desc=%s" % traceId)

Expand Down Expand Up @@ -280,13 +280,13 @@ async def test():
self.assertTrue(type(aiohttp_span.stack) is list)
self.assertTrue(len(aiohttp_span.stack) > 1)

assert "X-INSTANA-T" in response.headers
self.assertIn("X-INSTANA-T", response.headers)
self.assertEqual(response.headers["X-INSTANA-T"], traceId)
assert "X-INSTANA-S" in response.headers
self.assertIn("X-INSTANA-S", response.headers)
self.assertEqual(response.headers["X-INSTANA-S"], wsgi_span.s)
assert "X-INSTANA-L" in response.headers
self.assertIn("X-INSTANA-L", response.headers)
self.assertEqual(response.headers["X-INSTANA-L"], '1')
assert "Server-Timing" in response.headers
self.assertIn("Server-Timing", response.headers)
self.assertEqual(
response.headers["Server-Timing"], "intid;desc=%s" % traceId)

Expand Down Expand Up @@ -332,13 +332,13 @@ async def test():
self.assertTrue(type(aiohttp_span.stack) is list)
self.assertTrue(len(aiohttp_span.stack) > 1)

assert "X-INSTANA-T" in response.headers
self.assertIn("X-INSTANA-T", response.headers)
self.assertEqual(response.headers["X-INSTANA-T"], traceId)
assert "X-INSTANA-S" in response.headers
self.assertIn("X-INSTANA-S", response.headers)
self.assertEqual(response.headers["X-INSTANA-S"], wsgi_span.s)
assert "X-INSTANA-L" in response.headers
self.assertIn("X-INSTANA-L", response.headers)
self.assertEqual(response.headers["X-INSTANA-L"], '1')
assert "Server-Timing" in response.headers
self.assertIn("Server-Timing", response.headers)
self.assertEqual(
response.headers["Server-Timing"], "intid;desc=%s" % traceId)

Expand Down Expand Up @@ -384,16 +384,16 @@ async def test():
self.assertTrue(type(aiohttp_span.stack) is list)
self.assertTrue(len(aiohttp_span.stack) > 1)

assert "X-Capture-This" in aiohttp_span.data["http"]["header"]
self.assertIn("X-Capture-This", aiohttp_span.data["http"]["header"])
self.assertEqual("Ok", aiohttp_span.data["http"]["header"]["X-Capture-This"])

assert "X-INSTANA-T" in response.headers
self.assertIn("X-INSTANA-T", response.headers)
self.assertEqual(response.headers["X-INSTANA-T"], traceId)
assert "X-INSTANA-S" in response.headers
self.assertIn("X-INSTANA-S", response.headers)
self.assertEqual(response.headers["X-INSTANA-S"], wsgi_span.s)
assert "X-INSTANA-L" in response.headers
self.assertIn("X-INSTANA-L", response.headers)
self.assertEqual(response.headers["X-INSTANA-L"], '1')
assert "Server-Timing" in response.headers
self.assertIn("Server-Timing", response.headers)
self.assertEqual(response.headers["Server-Timing"], "intid;desc=%s" % traceId)

agent.options.extra_http_headers = original_extra_http_headers
Expand Down Expand Up @@ -435,7 +435,7 @@ async def test():
aiohttp_span.data["http"]["url"])
self.assertEqual("GET", aiohttp_span.data["http"]["method"])
self.assertIsNotNone(aiohttp_span.data["http"]["error"])
assert(len(aiohttp_span.data["http"]["error"]))
self.assertTrue(len(aiohttp_span.data["http"]["error"]))
self.assertIsNotNone(aiohttp_span.stack)
self.assertTrue(type(aiohttp_span.stack) is list)
self.assertTrue(len(aiohttp_span.stack) > 1)
Expand Down
52 changes: 26 additions & 26 deletions tests/frameworks/test_aiohttp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ async def test():
self.assertTrue(type(aioclient_span.stack) is list)
self.assertTrue(len(aioclient_span.stack) > 1)

assert "X-INSTANA-T" in response.headers
self.assertIn("X-INSTANA-T", response.headers)
self.assertEqual(response.headers["X-INSTANA-T"], traceId)
assert "X-INSTANA-S" in response.headers
self.assertIn("X-INSTANA-S", response.headers)
self.assertEqual(response.headers["X-INSTANA-S"], aioserver_span.s)
assert "X-INSTANA-L" in response.headers
self.assertIn("X-INSTANA-L", response.headers)
self.assertEqual(response.headers["X-INSTANA-L"], '1')
assert "Server-Timing" in response.headers
self.assertIn("Server-Timing", response.headers)
self.assertEqual(
response.headers["Server-Timing"], "intid;desc=%s" % traceId)

Expand Down Expand Up @@ -146,13 +146,13 @@ async def test():
self.assertTrue(isinstance(aioclient_span.stack, list))
self.assertTrue(len(aioclient_span.stack) > 1)

assert "X-INSTANA-T" in response.headers
self.assertIn("X-INSTANA-T", response.headers)
self.assertEqual(response.headers["X-INSTANA-T"], trace_id)
assert "X-INSTANA-S" in response.headers
self.assertIn("X-INSTANA-S", response.headers)
self.assertEqual(response.headers["X-INSTANA-S"], aioserver_span.s)
assert "X-INSTANA-L" in response.headers
self.assertIn("X-INSTANA-L", response.headers)
self.assertEqual(response.headers["X-INSTANA-L"], '1')
assert "Server-Timing" in response.headers
self.assertIn("Server-Timing", response.headers)
self.assertEqual(
response.headers["Server-Timing"], "intid;desc=%s" % trace_id)

Expand Down Expand Up @@ -230,13 +230,13 @@ async def test():
self.assertTrue(type(aioclient_span.stack) is list)
self.assertTrue(len(aioclient_span.stack) > 1)

assert "X-INSTANA-T" in response.headers
self.assertIn("X-INSTANA-T", response.headers)
self.assertEqual(response.headers["X-INSTANA-T"], traceId)
assert "X-INSTANA-S" in response.headers
self.assertIn("X-INSTANA-S", response.headers)
self.assertEqual(response.headers["X-INSTANA-S"], aioserver_span.s)
assert "X-INSTANA-L" in response.headers
self.assertIn("X-INSTANA-L", response.headers)
self.assertEqual(response.headers["X-INSTANA-L"], '1')
assert "Server-Timing" in response.headers
self.assertIn("Server-Timing", response.headers)
self.assertEqual(
response.headers["Server-Timing"], "intid;desc=%s" % traceId)

Expand Down Expand Up @@ -299,19 +299,19 @@ async def test():
self.assertTrue(type(aioclient_span.stack) is list)
self.assertTrue(len(aioclient_span.stack) > 1)

assert "X-INSTANA-T" in response.headers
self.assertIn("X-INSTANA-T", response.headers)
self.assertEqual(response.headers["X-INSTANA-T"], traceId)
assert "X-INSTANA-S" in response.headers
self.assertIn("X-INSTANA-S", response.headers)
self.assertEqual(response.headers["X-INSTANA-S"], aioserver_span.s)
assert "X-INSTANA-L" in response.headers
self.assertIn("X-INSTANA-L", response.headers)
self.assertEqual(response.headers["X-INSTANA-L"], '1')
assert "Server-Timing" in response.headers
self.assertIn("Server-Timing", response.headers)
self.assertEqual(
response.headers["Server-Timing"], "intid;desc=%s" % traceId)

assert "X-Capture-This" in aioserver_span.data["http"]["header"]
self.assertIn("X-Capture-This", aioserver_span.data["http"]["header"])
self.assertEqual("this", aioserver_span.data["http"]["header"]["X-Capture-This"])
assert "X-Capture-That" in aioserver_span.data["http"]["header"]
self.assertIn("X-Capture-That", aioserver_span.data["http"]["header"])
self.assertEqual("that", aioserver_span.data["http"]["header"]["X-Capture-That"])

def test_server_get_401(self):
Expand Down Expand Up @@ -361,13 +361,13 @@ async def test():
self.assertTrue(type(aioclient_span.stack) is list)
self.assertTrue(len(aioclient_span.stack) > 1)

assert "X-INSTANA-T" in response.headers
self.assertIn("X-INSTANA-T", response.headers)
self.assertEqual(response.headers["X-INSTANA-T"], traceId)
assert "X-INSTANA-S" in response.headers
self.assertIn("X-INSTANA-S", response.headers)
self.assertEqual(response.headers["X-INSTANA-S"], aioserver_span.s)
assert "X-INSTANA-L" in response.headers
self.assertIn("X-INSTANA-L", response.headers)
self.assertEqual(response.headers["X-INSTANA-L"], '1')
assert "Server-Timing" in response.headers
self.assertIn("Server-Timing", response.headers)
self.assertEqual(
response.headers["Server-Timing"], "intid;desc=%s" % traceId)

Expand Down Expand Up @@ -420,13 +420,13 @@ async def test():
self.assertTrue(type(aioclient_span.stack) is list)
self.assertTrue(len(aioclient_span.stack) > 1)

assert "X-INSTANA-T" in response.headers
self.assertIn("X-INSTANA-T", response.headers)
self.assertEqual(response.headers["X-INSTANA-T"], traceId)
assert "X-INSTANA-S" in response.headers
self.assertIn("X-INSTANA-S", response.headers)
self.assertEqual(response.headers["X-INSTANA-S"], aioserver_span.s)
assert "X-INSTANA-L" in response.headers
self.assertIn("X-INSTANA-L", response.headers)
self.assertEqual(response.headers["X-INSTANA-L"], '1')
assert "Server-Timing" in response.headers
self.assertIn("Server-Timing", response.headers)
self.assertEqual(
response.headers["Server-Timing"], "intid;desc=%s" % traceId)

Expand Down
56 changes: 28 additions & 28 deletions tests/frameworks/test_grpcio.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def test_unary_one_to_one(self):
client_span = get_first_span_by_name(spans, 'rpc-client')
test_span = get_first_span_by_name(spans, 'sdk')

assert(server_span)
assert(client_span)
assert(test_span)
self.assertTrue(server_span)
self.assertTrue(client_span)
self.assertTrue(test_span)

# Same traceId
self.assertEqual(server_span.t, client_span.t)
Expand Down Expand Up @@ -126,9 +126,9 @@ def test_streaming_many_to_one(self):
client_span = get_first_span_by_name(spans, 'rpc-client')
test_span = get_first_span_by_name(spans, 'sdk')

assert(server_span)
assert(client_span)
assert(test_span)
self.assertTrue(server_span)
self.assertTrue(client_span)
self.assertTrue(test_span)

# Same traceId
self.assertEqual(server_span.t, client_span.t)
Expand Down Expand Up @@ -189,9 +189,9 @@ def test_streaming_one_to_many(self):
client_span = get_first_span_by_name(spans, 'rpc-client')
test_span = get_first_span_by_name(spans, 'sdk')

assert(server_span)
assert(client_span)
assert(test_span)
self.assertTrue(server_span)
self.assertTrue(client_span)
self.assertTrue(test_span)

# Same traceId
self.assertEqual(server_span.t, client_span.t)
Expand Down Expand Up @@ -251,9 +251,9 @@ def test_streaming_many_to_many(self):
client_span = get_first_span_by_name(spans, 'rpc-client')
test_span = get_first_span_by_name(spans, 'sdk')

assert(server_span)
assert(client_span)
assert(test_span)
self.assertTrue(server_span)
self.assertTrue(client_span)
self.assertTrue(test_span)

# Same traceId
self.assertEqual(server_span.t, client_span.t)
Expand Down Expand Up @@ -309,9 +309,9 @@ def test_unary_one_to_one_with_call(self):
client_span = get_first_span_by_name(spans, 'rpc-client')
test_span = get_first_span_by_name(spans, 'sdk')

assert(server_span)
assert(client_span)
assert(test_span)
self.assertTrue(server_span)
self.assertTrue(client_span)
self.assertTrue(test_span)

# Same traceId
self.assertEqual(server_span.t, client_span.t)
Expand Down Expand Up @@ -368,9 +368,9 @@ def test_streaming_many_to_one_with_call(self):
client_span = get_first_span_by_name(spans, 'rpc-client')
test_span = get_first_span_by_name(spans, 'sdk')

assert(server_span)
assert(client_span)
assert(test_span)
self.assertTrue(server_span)
self.assertTrue(client_span)
self.assertTrue(test_span)

# Same traceId
self.assertEqual(server_span.t, client_span.t)
Expand Down Expand Up @@ -431,9 +431,9 @@ def process_response(future):
client_span = get_first_span_by_name(spans, 'rpc-client')
test_span = get_first_span_by_name(spans, 'sdk')

assert(server_span)
assert(client_span)
assert(test_span)
self.assertTrue(server_span)
self.assertTrue(client_span)
self.assertTrue(test_span)

# Same traceId
self.assertEqual(server_span.t, client_span.t)
Expand Down Expand Up @@ -496,9 +496,9 @@ def process_response(future):
client_span = get_first_span_by_name(spans, 'rpc-client')
test_span = get_first_span_by_name(spans, 'sdk')

assert(server_span)
assert(client_span)
assert(test_span)
self.assertTrue(server_span)
self.assertTrue(client_span)
self.assertTrue(test_span)

# Same traceId
self.assertEqual(server_span.t, client_span.t)
Expand Down Expand Up @@ -557,10 +557,10 @@ def test_server_error(self):
client_span = get_first_span_by_name(spans, 'rpc-client')
test_span = get_first_span_by_name(spans, 'sdk')

assert(log_span)
assert(server_span)
assert(client_span)
assert(test_span)
self.assertTrue(log_span)
self.assertTrue(server_span)
self.assertTrue(client_span)
self.assertTrue(test_span)

# Same traceId
self.assertEqual(server_span.t, client_span.t)
Expand Down
Loading

0 comments on commit 7dfb921

Please sign in to comment.