Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 66faf91

Browse files
types: make TA notification payload generic (#1142)
1 parent 5ee2810 commit 66faf91

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

services/test_results.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from dataclasses import dataclass
33
from hashlib import sha256
4-
from typing import Sequence
4+
from typing import Generic, Sequence, TypeVar
55

66
from shared.django_apps.codecov_auth.models import Plan
77
from shared.plan.constants import TierName
@@ -119,12 +119,15 @@ def generate_test_id(repoid, testsuite, name, flags_hash):
119119
).hexdigest()
120120

121121

122+
T = TypeVar("T", str, bytes)
123+
124+
122125
@dataclass
123-
class TestResultsNotificationFailure:
126+
class TestResultsNotificationFailure(Generic[T]):
124127
failure_message: str
125128
display_name: str
126129
envs: list[str]
127-
test_id: str
130+
test_id: T
128131
duration_seconds: float
129132
build_url: str | None = None
130133

@@ -136,17 +139,17 @@ class FlakeInfo:
136139

137140

138141
@dataclass
139-
class TACommentInDepthInfo:
140-
failures: list[TestResultsNotificationFailure]
141-
flaky_tests: dict[str, FlakeInfo]
142+
class TACommentInDepthInfo(Generic[T]):
143+
failures: list[TestResultsNotificationFailure[T]]
144+
flaky_tests: dict[T, FlakeInfo]
142145

143146

144147
@dataclass
145-
class TestResultsNotificationPayload:
148+
class TestResultsNotificationPayload(Generic[T]):
146149
failed: int
147150
passed: int
148151
skipped: int
149-
info: TACommentInDepthInfo | None = None
152+
info: TACommentInDepthInfo[T] | None = None
150153

151154

152155
@dataclass
@@ -199,7 +202,7 @@ def display_duration(f: float) -> str:
199202

200203

201204
def generate_failure_info(
202-
fail: TestResultsNotificationFailure,
205+
fail: TestResultsNotificationFailure[T],
203206
):
204207
if fail.failure_message is not None:
205208
failure_message = fail.failure_message
@@ -220,7 +223,7 @@ def generate_view_test_analytics_line(commit: Commit) -> str:
220223

221224

222225
def messagify_failure(
223-
failure: TestResultsNotificationFailure,
226+
failure: TestResultsNotificationFailure[T],
224227
) -> str:
225228
test_name = wrap_in_code(failure.display_name.replace("\x1f", " "))
226229
formatted_duration = display_duration(failure.duration_seconds)
@@ -233,7 +236,7 @@ def messagify_failure(
233236

234237

235238
def messagify_flake(
236-
flaky_failure: TestResultsNotificationFailure,
239+
flaky_failure: TestResultsNotificationFailure[T],
237240
flake_info: FlakeInfo,
238241
) -> str:
239242
test_name = wrap_in_code(flaky_failure.display_name.replace("\x1f", " "))
@@ -276,8 +279,8 @@ def specific_error_message(error: ErrorPayload) -> str:
276279

277280

278281
@dataclass
279-
class TestResultsNotifier(BaseNotifier):
280-
payload: TestResultsNotificationPayload | None = None
282+
class TestResultsNotifier(BaseNotifier, Generic[T]):
283+
payload: TestResultsNotificationPayload[T] | None = None
281284
error: ErrorPayload | None = None
282285

283286
def build_message(self) -> str:

0 commit comments

Comments
 (0)