Skip to content

Commit 952b3f6

Browse files
authored
Activate ANN001 on tests/integrations (#5590)
1 parent f55b0ec commit 952b3f6

File tree

11 files changed

+107
-49
lines changed

11 files changed

+107
-49
lines changed

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ ignore = [
174174
"tests/*test_*.py" = [
175175
"ANN201", # missing-return-type-undocumented-public-function: allow test_method to not declare their return type
176176
]
177-
178-
"tests/{parametric,appsec,debugger,remote_config,integrations}*/test_*.py" = [
177+
"tests/{parametric,appsec,debugger,remote_config}*/test_*.py" = [
179178
"ANN001", # missing-type-function-argument: TODO
180179
]
181180
"tests/*" = [

tests/integrations/crossed_integrations/test_kafka.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class _BaseKafka:
1515
buddy_interface: interfaces.LibraryInterfaceValidator
1616

1717
@classmethod
18-
def get_span(cls, interface, span_kind, topic) -> dict | None:
18+
def get_span(cls, interface: interfaces.LibraryInterfaceValidator, span_kind: str, topic: str) -> dict | None:
1919
logger.debug(f"Trying to find traces with span kind: {span_kind} and topic: {topic} in {interface}")
2020

2121
for data, trace in interface.get_traces():
@@ -36,7 +36,7 @@ def get_span(cls, interface, span_kind, topic) -> dict | None:
3636
return None
3737

3838
@staticmethod
39-
def get_topic(span) -> str | None:
39+
def get_topic(span: dict) -> str | None:
4040
"""Extracts the topic from a span by trying various fields"""
4141
topic = span["meta"].get("kafka.topic") # this is in python
4242
if topic is None:
@@ -131,7 +131,12 @@ def test_consume_trace_equality(self):
131131
assert consumer_span is not None
132132
assert producer_span["trace_id"] == consumer_span["trace_id"]
133133

134-
def validate_kafka_spans(self, producer_interface, consumer_interface, topic):
134+
def validate_kafka_spans(
135+
self,
136+
producer_interface: interfaces.LibraryInterfaceValidator,
137+
consumer_interface: interfaces.LibraryInterfaceValidator,
138+
topic: str,
139+
):
135140
"""Validates production/consumption of kafka message.
136141
It works the same for both test_produce and test_consume
137142
"""

tests/integrations/crossed_integrations/test_kinesis.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class _BaseKinesis:
1515
unique_id: str
1616

1717
@classmethod
18-
def get_span(cls, interface, span_kind, stream, operation) -> dict | None:
18+
def get_span(
19+
cls, interface: interfaces.LibraryInterfaceValidator, span_kind: list[str], stream: str, operation: str
20+
) -> dict | None:
1921
logger.debug(f"Trying to find traces with span kind: {span_kind} and stream: {stream} in {interface}")
2022

2123
for data, trace in interface.get_traces():
@@ -53,7 +55,7 @@ def get_span(cls, interface, span_kind, stream, operation) -> dict | None:
5355
return None
5456

5557
@staticmethod
56-
def get_stream(span) -> str | None:
58+
def get_stream(span: dict) -> str | None:
5759
"""Extracts the stream from a span by trying various fields"""
5860
stream = span["meta"].get("streamname", None) # this is in nodejs, java, python
5961

@@ -187,7 +189,12 @@ def test_consume_trace_equality(self):
187189
assert consumer_span is not None
188190
assert producer_span["trace_id"] == consumer_span["trace_id"]
189191

190-
def validate_kinesis_spans(self, producer_interface, consumer_interface, stream):
192+
def validate_kinesis_spans(
193+
self,
194+
producer_interface: interfaces.LibraryInterfaceValidator,
195+
consumer_interface: interfaces.LibraryInterfaceValidator,
196+
stream: str,
197+
):
191198
"""Validates production/consumption of Kinesis message.
192199
It works the same for both test_produce and test_consume
193200
"""

tests/integrations/crossed_integrations/test_rabbitmq.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ class _BaseRabbitMQ:
1919
buddy_interface: interfaces.LibraryInterfaceValidator
2020

2121
@classmethod
22-
def get_span(cls, interface, span_kind, queue, exchange, operation) -> dict | None:
22+
def get_span(
23+
cls,
24+
interface: interfaces.LibraryInterfaceValidator,
25+
span_kind: str,
26+
queue: str,
27+
exchange: str,
28+
operation: list[str],
29+
) -> dict | None:
2330
logger.debug(f"Trying to find traces with span kind: {span_kind} and queue: {queue} in {interface}")
2431

2532
for data, trace in interface.get_traces():
@@ -32,17 +39,17 @@ def get_span(cls, interface, span_kind, queue, exchange, operation) -> dict | No
3239

3340
operation_found = False
3441
for op in operation:
35-
if op.lower() in span.get("resource").lower() or op.lower() in span.get("name").lower():
42+
if op.lower() in span["resource"].lower() or op.lower() in span["name"].lower():
3643
operation_found = True
3744
break
3845

3946
if not operation_found:
4047
continue
4148

42-
meta = span.get("meta")
49+
meta: dict[str, str] = span["meta"]
4350
if (
44-
queue.lower() not in span.get("resource").lower()
45-
and exchange.lower() not in span.get("resource").lower()
51+
queue.lower() not in span["resource"].lower()
52+
and exchange.lower() not in span["resource"].lower()
4653
and queue.lower() not in meta.get("rabbitmq.routing_key", "").lower()
4754
# this is where we find the queue name in dotnet 👇
4855
and queue.lower() not in meta.get("amqp.routing_key", "").lower()
@@ -188,7 +195,13 @@ def test_consume_trace_equality(self):
188195
assert consumer_span is not None
189196
assert producer_span["trace_id"] == consumer_span["trace_id"]
190197

191-
def validate_rabbitmq_spans(self, producer_interface, consumer_interface, queue, exchange):
198+
def validate_rabbitmq_spans(
199+
self,
200+
producer_interface: interfaces.LibraryInterfaceValidator,
201+
consumer_interface: interfaces.LibraryInterfaceValidator,
202+
queue: str,
203+
exchange: str,
204+
):
192205
"""Validates production/consumption of RabbitMQ message.
193206
It works the same for both test_produce and test_consume
194207
"""

tests/integrations/crossed_integrations/test_sns_to_sqs.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ class _BaseSNS:
1717
unique_id: str
1818

1919
@classmethod
20-
def get_span(cls, interface, span_kind, queue, topic, operation) -> dict | None:
20+
def get_span(
21+
cls,
22+
interface: interfaces.LibraryInterfaceValidator,
23+
span_kind: list[str],
24+
queue: str,
25+
topic: str,
26+
operation: str,
27+
) -> dict | None:
2128
logger.debug(f"Trying to find traces with span kind: {span_kind} and queue: {queue} in {interface}")
2229
manual_span_found = False
2330

@@ -67,7 +74,7 @@ def get_span(cls, interface, span_kind, queue, topic, operation) -> dict | None:
6774
return None
6875

6976
@staticmethod
70-
def get_queue(span) -> str | None:
77+
def get_queue(span: dict) -> str | None:
7178
"""Extracts the queue from a span by trying various fields"""
7279
queue = span["meta"].get("queuename", None) # this is in nodejs, java, python
7380

@@ -83,7 +90,7 @@ def get_queue(span) -> str | None:
8390
return queue
8491

8592
@staticmethod
86-
def get_topic(span) -> str | None:
93+
def get_topic(span: dict) -> str | None:
8794
"""Extracts the topic from a span by trying various fields"""
8895
topic = span["meta"].get("topicname", None) # this is in nodejs, java, python
8996

@@ -217,7 +224,13 @@ def test_consume_trace_equality(self):
217224
assert consumer_span is not None
218225
assert producer_span["trace_id"] == consumer_span["trace_id"]
219226

220-
def validate_sns_spans(self, producer_interface, consumer_interface, queue, topic):
227+
def validate_sns_spans(
228+
self,
229+
producer_interface: interfaces.LibraryInterfaceValidator,
230+
consumer_interface: interfaces.LibraryInterfaceValidator,
231+
queue: str,
232+
topic: str,
233+
):
221234
"""Validates production/consumption of sns message.
222235
It works the same for both test_produce and test_consume
223236
"""

tests/integrations/crossed_integrations/test_sqs.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class _BaseSQS:
1515
unique_id: str
1616

1717
@classmethod
18-
def get_span(cls, interface, span_kind, queue, operation) -> dict | None:
18+
def get_span(
19+
cls, interface: interfaces.LibraryInterfaceValidator, span_kind: list[str], queue: str, operation: str
20+
) -> dict | None:
1921
logger.debug(f"Trying to find traces with span kind: {span_kind} and queue: {queue} in {interface}")
2022
manual_span_found = False
2123

@@ -66,7 +68,7 @@ def get_span(cls, interface, span_kind, queue, operation) -> dict | None:
6668
return None
6769

6870
@staticmethod
69-
def get_queue(span) -> str | None:
71+
def get_queue(span: dict) -> str | None:
7072
"""Extracts the queue from a span by trying various fields"""
7173
queue = span["meta"].get("queuename", None) # this is in nodejs, java, python
7274

@@ -200,7 +202,12 @@ def test_consume_trace_equality(self):
200202
assert consumer_span is not None
201203
assert producer_span["trace_id"] == consumer_span["trace_id"]
202204

203-
def validate_sqs_spans(self, producer_interface, consumer_interface, queue):
205+
def validate_sqs_spans(
206+
self,
207+
producer_interface: interfaces.LibraryInterfaceValidator,
208+
consumer_interface: interfaces.LibraryInterfaceValidator,
209+
queue: str,
210+
):
204211
"""Validates production/consumption of sqs message.
205212
It works the same for both test_produce and test_consume
206213
"""

tests/integrations/test_db_integrations_sql.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class _BaseDatadogDbIntegrationTestClass(BaseDbIntegrationsTestClass):
1212
Check integration spans status: https://docs.google.com/spreadsheets/d/1qm3B0tJ-gG11j_MHoEd9iMXf4_DvWAGCLwmBhWCxbA8/edit#gid=623219645
1313
"""
1414

15-
def get_spans(self, excluded_operations=(), operations=None):
15+
def get_spans(self, excluded_operations: tuple[str, ...] = (), operations: list[str] | None = None):
1616
"""Get the spans from tracer and agent generated by all requests"""
1717

1818
# yield the span from the tracer in first, as if it fails, there is a good chance that the one from the agent also fails
@@ -26,18 +26,18 @@ def get_spans(self, excluded_operations=(), operations=None):
2626
yield db_operation, self.get_span_from_agent(request)
2727

2828
# Tests methods
29-
def test_sql_traces(self, excluded_operations=()):
29+
def test_sql_traces(self, excluded_operations: tuple[str, ...] = ()):
3030
"""After make the requests we check that we are producing sql traces"""
3131
for _, span in self.get_spans(excluded_operations):
3232
assert span is not None
3333

3434
def test_resource(self):
3535
"""Usually the query"""
3636

37-
for db_operation, span in self.get_spans(excluded_operations=["procedure", "select_error"]):
37+
for db_operation, span in self.get_spans(excluded_operations=("procedure", "select_error")):
3838
assert db_operation in span["resource"].lower()
3939

40-
def test_sql_success(self, excluded_operations=()):
40+
def test_sql_success(self, excluded_operations: tuple[str, ...] = ()):
4141
"""We check all sql launched for the app work"""
4242

4343
for db_operation, span in self.get_spans(excluded_operations=excluded_operations + ("select_error",)):
@@ -49,7 +49,7 @@ def test_sql_success(self, excluded_operations=()):
4949
raise ValueError(f"Error found in {db_operation} operation, please check captured log call")
5050

5151
@irrelevant(library="python", reason="Python is using the correct span: db.system")
52-
def test_db_type(self, excluded_operations=()):
52+
def test_db_type(self, excluded_operations: tuple[str, ...] = ()):
5353
"""DEPRECATED!! Now it is db.system. An identifier for the database management system (DBMS) product being used.
5454
Must be one of the available values: https://datadoghq.atlassian.net/wiki/spaces/APM/pages/2357395856/Span+attributes#db.system
5555
"""
@@ -65,7 +65,7 @@ def test_db_name(self):
6565
for db_operation, span in self.get_spans():
6666
assert span["meta"]["db.name"] == db_container.db_instance, f"Test is failing for {db_operation}"
6767

68-
def test_span_kind(self, excluded_operations=()):
68+
def test_span_kind(self, excluded_operations: tuple[str, ...] = ()):
6969
"""Describes the relationship between the Span, its parents, and its children in a Trace."""
7070

7171
for _, span in self.get_spans(excluded_operations):
@@ -98,7 +98,7 @@ def test_db_connection_string(self):
9898
for db_operation, span in self.get_spans():
9999
assert span["meta"]["db.connection_string"].strip(), f"Test is failing for {db_operation}"
100100

101-
def test_db_user(self, excluded_operations=()):
101+
def test_db_user(self, excluded_operations: tuple[str, ...] = ()):
102102
"""Username for accessing the database."""
103103
db_container = context.get_container_by_dd_integration_name(self.db_service)
104104

@@ -107,7 +107,7 @@ def test_db_user(self, excluded_operations=()):
107107

108108
@missing_feature(library="python", reason="not implemented yet")
109109
@missing_feature(library="nodejs", reason="not implemented yet")
110-
def test_db_instance(self, excluded_operations=()):
110+
def test_db_instance(self, excluded_operations: tuple[str, ...] = ()):
111111
"""The name of the database being connected to. Database instance name. Formerly db.name"""
112112
db_container = context.get_container_by_dd_integration_name(self.db_service)
113113

@@ -120,12 +120,12 @@ def test_db_instance(self, excluded_operations=()):
120120
def test_db_statement_query(self):
121121
"""Usually the query"""
122122

123-
for db_operation, span in self.get_spans(excluded_operations=["procedure", "select_error"]):
123+
for db_operation, span in self.get_spans(excluded_operations=("procedure", "select_error")):
124124
assert db_operation in span["meta"]["db.statement"].lower()
125125

126126
@missing_feature(library="nodejs", reason="not implemented yet")
127127
@missing_feature(library="python", reason="not implemented yet")
128-
def test_db_operation(self, excluded_operations=()):
128+
def test_db_operation(self, excluded_operations: tuple[str, ...] = ()):
129129
"""The name of the operation being executed"""
130130

131131
for db_operation, span in self.get_spans(excluded_operations=excluded_operations + ("select_error",)):
@@ -144,7 +144,7 @@ def test_db_operation(self, excluded_operations=()):
144144
def test_db_sql_table(self):
145145
"""The name of the primary table that the operation is acting upon, including the database name (if applicable)."""
146146

147-
for db_operation, span in self.get_spans(excluded_operations=["procedure"]):
147+
for db_operation, span in self.get_spans(excluded_operations=("procedure",)):
148148
assert span["meta"]["db.sql.table"].strip(), f"Test is failing for {db_operation}"
149149

150150
@missing_feature(library="python", reason="not implemented yet")
@@ -158,7 +158,7 @@ def test_db_row_count(self):
158158
for _, span in self.get_spans(operations=["select"]):
159159
assert span["meta"]["db.row_count"] > 0, "Test is failing for select"
160160

161-
def test_db_password(self, excluded_operations=()):
161+
def test_db_password(self, excluded_operations: tuple[str, ...] = ()):
162162
"""The database password should not show in the traces"""
163163
db_container = context.get_container_by_dd_integration_name(self.db_service)
164164

@@ -214,7 +214,7 @@ def test_sql_query(self):
214214
db_operation in span["meta"]["sql.query"].lower()
215215
), f"sql.query span not found for operation {db_operation}"
216216

217-
def test_obfuscate_query(self, excluded_operations=()):
217+
def test_obfuscate_query(self, excluded_operations: tuple[str, ...] = ()):
218218
"""All queries come out obfuscated from agent"""
219219
for db_operation, request in self.get_requests(excluded_operations=excluded_operations):
220220
span = self.get_span_from_agent(request)
@@ -295,7 +295,7 @@ def test_db_system(self):
295295
def test_db_user(self):
296296
super().test_db_user()
297297

298-
def test_obfuscate_query(self, excluded_operations=()):
298+
def test_obfuscate_query(self, excluded_operations: tuple[str, ...] = ()):
299299
"""All queries come out obfuscated from agent"""
300300
for db_operation, request in self.get_requests(excluded_operations=excluded_operations):
301301
span = self.get_span_from_agent(request)

tests/integrations/test_dbm.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import re
88

99
from utils import weblog, interfaces, context, scenarios, features, irrelevant, flaky, bug, logger
10+
from utils._weblog import HttpResponse
1011

1112

12-
def remove_traceparent(s):
13+
def remove_traceparent(s: str) -> str:
1314
return re.sub(r",traceparent='[^']*'", "", s)
1415

1516

@@ -53,7 +54,7 @@ def weblog_trace_payload(self):
5354
]
5455
)
5556

56-
def _get_db_span(self, response):
57+
def _get_db_span(self, response: HttpResponse) -> dict:
5758
assert response.status_code == 200, f"Request: {context.scenario.name} wasn't successful."
5859

5960
spans = []
@@ -82,11 +83,11 @@ def _assert_spans_are_untagged(self):
8283
for request in self.requests:
8384
self._assert_span_is_untagged(self._get_db_span(request))
8485

85-
def _assert_span_is_untagged(self, span):
86+
def _assert_span_is_untagged(self, span: dict) -> None:
8687
meta = span.get("meta", {})
8788
assert self.META_TAG not in meta, f"{self.META_TAG} found in span meta: {json.dumps(span, indent=2)}"
8889

89-
def _assert_span_is_tagged(self, span):
90+
def _assert_span_is_tagged(self, span: dict) -> None:
9091
meta = span.get("meta", {})
9192
assert self.META_TAG in meta, f"{self.META_TAG} not found in span meta: {json.dumps(span, indent=2)}"
9293
tag_value = meta.get(self.META_TAG)

tests/integrations/test_dsm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
WEBLOG_VARIANT_SANITIZED = context.weblog_variant.replace(".", "_").replace(" ", "_").replace("/", "_")
5757

5858

59-
def get_message(test, system):
59+
def get_message(test: str, system: str) -> str:
6060
return f"[test_dsm.py::{test}] [{system.upper()}] Hello from {context.library.name} DSM test: {scenarios.integrations_aws.unique_id}"
6161

6262

@@ -636,14 +636,14 @@ def test_dsm_manual_checkpoint_inter_process(self):
636636

637637
class DsmHelper:
638638
@staticmethod
639-
def is_tags_included(actual_tags, expected_tags) -> bool:
639+
def is_tags_included(actual_tags: tuple, expected_tags: tuple) -> bool:
640640
assert isinstance(actual_tags, tuple)
641641
assert isinstance(expected_tags, tuple)
642642

643643
return all(expected_tag in actual_tags for expected_tag in expected_tags)
644644

645645
@staticmethod
646-
def assert_checkpoint_presence(hash_, parent_hash, tags) -> None:
646+
def assert_checkpoint_presence(hash_: int, parent_hash: int, tags: tuple) -> None:
647647
assert isinstance(tags, tuple)
648648

649649
logger.info(f"Look for {hash_}, {parent_hash}, {tags}")

0 commit comments

Comments
 (0)