@@ -40,21 +40,11 @@ def async_call(coro):
4040
4141class CheckSpanMixin :
4242 def check_span (self , span , expected_db_name = POSTGRES_DB_NAME ):
43- self .assertEqual (
44- span .attributes [DB_SYSTEM ], "postgresql"
45- )
46- self .assertEqual (
47- span .attributes [DB_NAME ], expected_db_name
48- )
49- self .assertEqual (
50- span .attributes [DB_USER ], POSTGRES_USER
51- )
52- self .assertEqual (
53- span .attributes [NET_PEER_NAME ], POSTGRES_HOST
54- )
55- self .assertEqual (
56- span .attributes [NET_PEER_PORT ], POSTGRES_PORT
57- )
43+ self .assertEqual (span .attributes [DB_SYSTEM ], "postgresql" )
44+ self .assertEqual (span .attributes [DB_NAME ], expected_db_name )
45+ self .assertEqual (span .attributes [DB_USER ], POSTGRES_USER )
46+ self .assertEqual (span .attributes [NET_PEER_NAME ], POSTGRES_HOST )
47+ self .assertEqual (span .attributes [NET_PEER_PORT ], POSTGRES_PORT )
5848
5949
6050class TestFunctionalAsyncPG (TestBase , CheckSpanMixin ):
@@ -84,9 +74,7 @@ def test_instrumented_execute_method_without_arguments(self, *_, **__):
8474 self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
8575 self .check_span (spans [0 ])
8676 self .assertEqual (spans [0 ].name , "SELECT" )
87- self .assertEqual (
88- spans [0 ].attributes [DB_STATEMENT ], "SELECT 42;"
89- )
77+ self .assertEqual (spans [0 ].attributes [DB_STATEMENT ], "SELECT 42;" )
9078
9179 def test_instrumented_execute_method_error (self , * _ , ** __ ):
9280 """Should create an error span for execute() with the database name as the span name."""
@@ -107,9 +95,7 @@ def test_instrumented_fetch_method_without_arguments(self, *_, **__):
10795 self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
10896 self .check_span (spans [0 ])
10997 self .assertEqual (spans [0 ].name , "SELECT" )
110- self .assertEqual (
111- spans [0 ].attributes [DB_STATEMENT ], "SELECT 42;"
112- )
98+ self .assertEqual (spans [0 ].attributes [DB_STATEMENT ], "SELECT 42;" )
11399
114100 def test_instrumented_fetch_method_empty_query (self , * _ , ** __ ):
115101 """Should create an error span for fetch() with the database name as the span name."""
@@ -129,9 +115,7 @@ def test_instrumented_fetchval_method_without_arguments(self, *_, **__):
129115 self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
130116 self .check_span (spans [0 ])
131117 self .assertEqual (spans [0 ].name , "SELECT" )
132- self .assertEqual (
133- spans [0 ].attributes [DB_STATEMENT ], "SELECT 42;"
134- )
118+ self .assertEqual (spans [0 ].attributes [DB_STATEMENT ], "SELECT 42;" )
135119
136120 def test_instrumented_fetchval_method_empty_query (self , * _ , ** __ ):
137121 """Should create an error span for fetchval() with the database name as the span name."""
@@ -151,9 +135,7 @@ def test_instrumented_fetchrow_method_without_arguments(self, *_, **__):
151135 self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
152136 self .check_span (spans [0 ])
153137 self .assertEqual (spans [0 ].name , "SELECT" )
154- self .assertEqual (
155- spans [0 ].attributes [DB_STATEMENT ], "SELECT 42;"
156- )
138+ self .assertEqual (spans [0 ].attributes [DB_STATEMENT ], "SELECT 42;" )
157139
158140 def test_instrumented_fetchrow_method_empty_query (self , * _ , ** __ ):
159141 """Should create an error span for fetchrow() with the database name as the span name."""
@@ -182,9 +164,7 @@ async def _cursor_execute():
182164
183165 self .check_span (spans [0 ])
184166 self .assertEqual (spans [0 ].name , "BEGIN;" )
185- self .assertEqual (
186- spans [0 ].attributes [DB_STATEMENT ], "BEGIN;"
187- )
167+ self .assertEqual (spans [0 ].attributes [DB_STATEMENT ], "BEGIN;" )
188168 self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
189169
190170 for span in spans [1 :- 1 ]:
@@ -198,9 +178,7 @@ async def _cursor_execute():
198178
199179 self .check_span (spans [- 1 ])
200180 self .assertEqual (spans [- 1 ].name , "COMMIT;" )
201- self .assertEqual (
202- spans [- 1 ].attributes [DB_STATEMENT ], "COMMIT;"
203- )
181+ self .assertEqual (spans [- 1 ].attributes [DB_STATEMENT ], "COMMIT;" )
204182
205183 def test_instrumented_cursor_execute_method_empty_query (self , * _ , ** __ ):
206184 """Should create spans for the transaction and cursor fetches with the database name as the span name."""
@@ -215,9 +193,7 @@ async def _cursor_execute():
215193 self .assertEqual (len (spans ), 3 )
216194
217195 self .check_span (spans [0 ])
218- self .assertEqual (
219- spans [0 ].attributes [DB_STATEMENT ], "BEGIN;"
220- )
196+ self .assertEqual (spans [0 ].attributes [DB_STATEMENT ], "BEGIN;" )
221197 self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
222198
223199 self .check_span (spans [1 ])
@@ -226,9 +202,7 @@ async def _cursor_execute():
226202 self .assertIs (StatusCode .UNSET , spans [1 ].status .status_code )
227203
228204 self .check_span (spans [2 ])
229- self .assertEqual (
230- spans [2 ].attributes [DB_STATEMENT ], "COMMIT;"
231- )
205+ self .assertEqual (spans [2 ].attributes [DB_STATEMENT ], "COMMIT;" )
232206
233207 def test_instrumented_remove_comments (self , * _ , ** __ ):
234208 """Should remove comments from the query and set the span name correctly."""
@@ -275,21 +249,15 @@ async def _transaction_execute():
275249 spans = self .memory_exporter .get_finished_spans ()
276250 self .assertEqual (3 , len (spans ))
277251 self .check_span (spans [0 ])
278- self .assertEqual (
279- spans [0 ].attributes [DB_STATEMENT ], "BEGIN;"
280- )
252+ self .assertEqual (spans [0 ].attributes [DB_STATEMENT ], "BEGIN;" )
281253 self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
282254
283255 self .check_span (spans [1 ])
284- self .assertEqual (
285- spans [1 ].attributes [DB_STATEMENT ], "SELECT 42;"
286- )
256+ self .assertEqual (spans [1 ].attributes [DB_STATEMENT ], "SELECT 42;" )
287257 self .assertIs (StatusCode .UNSET , spans [1 ].status .status_code )
288258
289259 self .check_span (spans [2 ])
290- self .assertEqual (
291- spans [2 ].attributes [DB_STATEMENT ], "COMMIT;"
292- )
260+ self .assertEqual (spans [2 ].attributes [DB_STATEMENT ], "COMMIT;" )
293261 self .assertIs (StatusCode .UNSET , spans [2 ].status .status_code )
294262
295263 def test_instrumented_failed_transaction_method (self , * _ , ** __ ):
@@ -306,9 +274,7 @@ async def _transaction_execute():
306274 self .assertEqual (3 , len (spans ))
307275
308276 self .check_span (spans [0 ])
309- self .assertEqual (
310- spans [0 ].attributes [DB_STATEMENT ], "BEGIN;"
311- )
277+ self .assertEqual (spans [0 ].attributes [DB_STATEMENT ], "BEGIN;" )
312278 self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
313279
314280 self .check_span (spans [1 ])
@@ -319,9 +285,7 @@ async def _transaction_execute():
319285 self .assertEqual (StatusCode .ERROR , spans [1 ].status .status_code )
320286
321287 self .check_span (spans [2 ])
322- self .assertEqual (
323- spans [2 ].attributes [DB_STATEMENT ], "ROLLBACK;"
324- )
288+ self .assertEqual (spans [2 ].attributes [DB_STATEMENT ], "ROLLBACK;" )
325289 self .assertIs (StatusCode .UNSET , spans [2 ].status .status_code )
326290
327291 def test_instrumented_method_doesnt_capture_parameters (self , * _ , ** __ ):
@@ -331,9 +295,7 @@ def test_instrumented_method_doesnt_capture_parameters(self, *_, **__):
331295 self .assertEqual (len (spans ), 1 )
332296 self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
333297 self .check_span (spans [0 ])
334- self .assertEqual (
335- spans [0 ].attributes [DB_STATEMENT ], "SELECT $1;"
336- )
298+ self .assertEqual (spans [0 ].attributes [DB_STATEMENT ], "SELECT $1;" )
337299
338300
339301class TestFunctionalAsyncPG_CaptureParameters (TestBase , CheckSpanMixin ):
@@ -366,9 +328,7 @@ def test_instrumented_execute_method_with_arguments(self, *_, **__):
366328
367329 self .check_span (spans [0 ])
368330 self .assertEqual (spans [0 ].name , "SELECT" )
369- self .assertEqual (
370- spans [0 ].attributes [DB_STATEMENT ], "SELECT $1;"
371- )
331+ self .assertEqual (spans [0 ].attributes [DB_STATEMENT ], "SELECT $1;" )
372332 self .assertEqual (
373333 spans [0 ].attributes ["db.statement.parameters" ], "('1',)"
374334 )
@@ -381,9 +341,7 @@ def test_instrumented_fetch_method_with_arguments(self, *_, **__):
381341
382342 self .check_span (spans [0 ])
383343 self .assertEqual (spans [0 ].name , "SELECT" )
384- self .assertEqual (
385- spans [0 ].attributes [DB_STATEMENT ], "SELECT $1;"
386- )
344+ self .assertEqual (spans [0 ].attributes [DB_STATEMENT ], "SELECT $1;" )
387345 self .assertEqual (
388346 spans [0 ].attributes ["db.statement.parameters" ], "('1',)"
389347 )
@@ -395,9 +353,7 @@ def test_instrumented_executemany_method_with_arguments(self, *_, **__):
395353 self .assertEqual (len (spans ), 1 )
396354 self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
397355 self .check_span (spans [0 ])
398- self .assertEqual (
399- spans [0 ].attributes [DB_STATEMENT ], "SELECT $1;"
400- )
356+ self .assertEqual (spans [0 ].attributes [DB_STATEMENT ], "SELECT $1;" )
401357 self .assertEqual (
402358 spans [0 ].attributes ["db.statement.parameters" ], "([['1'], ['2']],)"
403359 )
@@ -410,9 +366,7 @@ def test_instrumented_execute_interface_error_method(self, *_, **__):
410366 self .assertEqual (len (spans ), 1 )
411367 self .assertIs (StatusCode .ERROR , spans [0 ].status .status_code )
412368 self .check_span (spans [0 ])
413- self .assertEqual (
414- spans [0 ].attributes [DB_STATEMENT ], "SELECT 42;"
415- )
369+ self .assertEqual (spans [0 ].attributes [DB_STATEMENT ], "SELECT 42;" )
416370 self .assertEqual (
417371 spans [0 ].attributes ["db.statement.parameters" ], "(1, 2, 3)"
418372 )
0 commit comments