Skip to content

ref: strptime -> fromisoformat in tests #82488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tests/sentry/api/endpoints/test_custom_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
UnsupportedSearchQueryReason,
get_rule_condition,
)
from sentry.models.dynamicsampling import CUSTOM_RULE_DATE_FORMAT, CustomDynamicSamplingRule
from sentry.models.dynamicsampling import CustomDynamicSamplingRule
from sentry.testutils.cases import APITestCase, TestCase


Expand Down Expand Up @@ -206,8 +206,8 @@ def test_create(self):

data = resp.data

start_date = datetime.strptime(data["startDate"], CUSTOM_RULE_DATE_FORMAT)
end_date = datetime.strptime(data["endDate"], CUSTOM_RULE_DATE_FORMAT)
start_date = datetime.fromisoformat(data["startDate"])
end_date = datetime.fromisoformat(data["endDate"])
assert end_date - start_date == timedelta(days=2)
projects = data["projects"]
assert projects == [self.project.id]
Expand Down Expand Up @@ -260,8 +260,8 @@ def test_updates_existing(self):
data = resp.data

rule_id = data["ruleId"]
start_date = datetime.strptime(data["startDate"], CUSTOM_RULE_DATE_FORMAT)
end_date = datetime.strptime(data["endDate"], CUSTOM_RULE_DATE_FORMAT)
start_date = datetime.fromisoformat(data["startDate"])
end_date = datetime.fromisoformat(data["endDate"])
assert end_date - start_date == timedelta(days=2)

request_data = {
Expand All @@ -275,8 +275,8 @@ def test_updates_existing(self):
assert resp.status_code == 200
data = resp.data

start_date = datetime.strptime(data["startDate"], CUSTOM_RULE_DATE_FORMAT)
end_date = datetime.strptime(data["endDate"], CUSTOM_RULE_DATE_FORMAT)
start_date = datetime.fromisoformat(data["startDate"])
end_date = datetime.fromisoformat(data["endDate"])
assert end_date - start_date >= timedelta(days=2)

projects = data["projects"]
Expand Down
4 changes: 2 additions & 2 deletions tests/sentry/api/endpoints/test_group_ai_autofix.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_ai_autofix_get_endpoint_with_autofix(self, mock_get_autofix_state):
mock_get_autofix_state.return_value = AutofixState(
run_id=123,
request={"project_id": 456, "issue": {"id": 789}},
updated_at=datetime.strptime("2023-07-18T12:00:00Z", "%Y-%m-%dT%H:%M:%SZ"),
updated_at=datetime.fromisoformat("2023-07-18T12:00:00Z"),
status=AutofixStatus.PROCESSING,
)

Expand Down Expand Up @@ -64,7 +64,7 @@ def test_ai_autofix_get_endpoint_repositories(
mock_get_autofix_state.return_value = AutofixState(
run_id=123,
request={"project_id": 456, "issue": {"id": 789}},
updated_at=datetime.strptime("2023-07-18T12:00:00Z", "%Y-%m-%dT%H:%M:%SZ"),
updated_at=datetime.fromisoformat("2023-07-18T12:00:00Z"),
status=AutofixStatus.PROCESSING,
)

Expand Down
50 changes: 23 additions & 27 deletions tests/sentry/issues/test_escalating_issues_alg.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from datetime import datetime
from typing import Any

from sentry.issues.escalating_issues_alg import generate_issue_forecast
from sentry.tasks.weekly_escalating_forecast import GroupCount

START_TIME = datetime.strptime("2022-07-27T00:00:00+00:00", "%Y-%m-%dT%H:%M:%S%f%z")
START_TIME = datetime.fromisoformat("2022-07-27T00:00:00+00:00")

SEVEN_DAY_INPUT_INTERVALS: list[Any] = [
SEVEN_DAY_INPUT_INTERVALS = [
"2022-07-20T00:00:00+00:00",
"2022-07-20T01:00:00+00:00",
"2022-07-20T02:00:00+00:00",
Expand Down Expand Up @@ -177,7 +175,7 @@
"2022-07-26T23:00:00+00:00",
]

SIX_DAY_INPUT_INTERVALS: list[Any] = [
SIX_DAY_INPUT_INTERVALS = [
"2022-07-21T00:00:00+00:00",
"2022-07-21T01:00:00+00:00",
"2022-07-21T02:00:00+00:00",
Expand Down Expand Up @@ -324,7 +322,7 @@
"2022-07-26T23:00:00+00:00",
]

SEVEN_DAY_ERROR_EVENTS: list[Any] = [
SEVEN_DAY_ERROR_EVENTS = [
74,
532,
670,
Expand Down Expand Up @@ -497,10 +495,10 @@


def test_spike_case() -> None:
start_time = datetime.strptime("2022-07-27T00:00:00+00:00", "%Y-%m-%dT%H:%M:%S%f%z")
data: GroupCount = {"intervals": SEVEN_DAY_INPUT_INTERVALS, "data": SEVEN_DAY_ERROR_EVENTS}

ceilings_list = generate_issue_forecast(data, start_time)
start_time = datetime.fromisoformat("2022-07-27T00:00:00+00:00")
ceilings_list = generate_issue_forecast(
{"intervals": SEVEN_DAY_INPUT_INTERVALS, "data": SEVEN_DAY_ERROR_EVENTS}, start_time
)
ceilings = [x["forecasted_value"] for x in ceilings_list]

assert ceilings == [6987] * 14, "Ceilings are incorrect"
Expand Down Expand Up @@ -583,20 +581,18 @@ def test_bursty_case() -> None:
7627,
] + [0] * 95

data: GroupCount = {"intervals": SEVEN_DAY_INPUT_INTERVALS, "data": error_events}

ceilings_list = generate_issue_forecast(data, START_TIME)
ceilings_list = generate_issue_forecast(
{"intervals": SEVEN_DAY_INPUT_INTERVALS, "data": error_events}, START_TIME
)
ceilings = [x["forecasted_value"] for x in ceilings_list]

assert ceilings == [16580] * 14, "Ceilings are incorrect"


def test_empty_input() -> None:
error_events: list[int] = []

data: GroupCount = {"intervals": SEVEN_DAY_INPUT_INTERVALS, "data": error_events}

ceilings_list = generate_issue_forecast(data, START_TIME)
ceilings_list = generate_issue_forecast(
{"intervals": SEVEN_DAY_INPUT_INTERVALS, "data": []}, START_TIME
)
ceilings = [x["forecasted_value"] for x in ceilings_list]

assert ceilings == [], "Empty Input"
Expand Down Expand Up @@ -655,9 +651,9 @@ def test_less_than_week_data() -> None:
7627,
] + [0] * 95

data: GroupCount = {"intervals": SIX_DAY_INPUT_INTERVALS, "data": error_events}

ceilings_list = generate_issue_forecast(data, START_TIME)
ceilings_list = generate_issue_forecast(
{"intervals": SIX_DAY_INPUT_INTERVALS, "data": error_events}, START_TIME
)
ceilings = [x["forecasted_value"] for x in ceilings_list]

assert ceilings == [82900] * 14, "Ceilings are incorrect"
Expand All @@ -666,18 +662,18 @@ def test_less_than_week_data() -> None:
def test_low_freq_events() -> None:
error_events = [6] * 168

data: GroupCount = {"intervals": SEVEN_DAY_INPUT_INTERVALS, "data": error_events}

ceilings_list = generate_issue_forecast(data, START_TIME)
ceilings_list = generate_issue_forecast(
{"intervals": SEVEN_DAY_INPUT_INTERVALS, "data": error_events}, START_TIME
)
ceilings = [x["forecasted_value"] for x in ceilings_list]

assert ceilings == [36] * 14, "Ceilings are incorrect"


def test_output() -> None:
data: GroupCount = {"intervals": SEVEN_DAY_INPUT_INTERVALS, "data": SEVEN_DAY_ERROR_EVENTS}

ceilings_list = generate_issue_forecast(data, START_TIME)
ceilings_list = generate_issue_forecast(
{"intervals": SEVEN_DAY_INPUT_INTERVALS, "data": SEVEN_DAY_ERROR_EVENTS}, START_TIME
)

assert ceilings_list == [
{"forecasted_date": "2022-07-27", "forecasted_value": 6987},
Expand Down
Loading