From 8512c9b028b35e6f650f9cbab65b1d562504e1ec Mon Sep 17 00:00:00 2001 From: Jeremy Stein Date: Mon, 20 Jan 2025 11:01:30 +0000 Subject: [PATCH] ruff fixes resulting from Python version change --- pixl_core/src/core/patient_queue/subscriber.py | 2 +- pixl_core/src/core/uploader/base.py | 4 ++-- pixl_core/tests/conftest.py | 4 ++-- pixl_core/tests/uploader/test_ftps.py | 8 ++++---- pixl_imaging/tests/test_imaging_processing.py | 10 +++++----- pytest-pixl/src/pytest_pixl/helpers.py | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pixl_core/src/core/patient_queue/subscriber.py b/pixl_core/src/core/patient_queue/subscriber.py index dd43737c1..62708efb9 100644 --- a/pixl_core/src/core/patient_queue/subscriber.py +++ b/pixl_core/src/core/patient_queue/subscriber.py @@ -34,9 +34,9 @@ if TYPE_CHECKING: from collections.abc import Awaitable, Callable + from typing import Self from aio_pika.abc import AbstractIncomingMessage - from typing_extensions import Self from core.patient_queue.message import Message from core.token_buffer.tokens import TokenBucket diff --git a/pixl_core/src/core/uploader/base.py b/pixl_core/src/core/uploader/base.py index 887776513..58c6cf01d 100644 --- a/pixl_core/src/core/uploader/base.py +++ b/pixl_core/src/core/uploader/base.py @@ -16,7 +16,7 @@ from __future__ import annotations from abc import ABC, abstractmethod -from datetime import datetime, timezone +from datetime import UTC, datetime from typing import TYPE_CHECKING, Any, Optional from loguru import logger @@ -77,7 +77,7 @@ def upload_dicom_and_update_database(self, study_id: str) -> None: study_tags.pseudo_anon_image_id, ) - update_exported_at(study_tags.pseudo_anon_image_id, datetime.now(tz=timezone.utc)) + update_exported_at(study_tags.pseudo_anon_image_id, datetime.now(tz=UTC)) @abstractmethod def _upload_dicom_image( diff --git a/pixl_core/tests/conftest.py b/pixl_core/tests/conftest.py index 77325b985..5bae7029f 100644 --- a/pixl_core/tests/conftest.py +++ b/pixl_core/tests/conftest.py @@ -163,7 +163,7 @@ def rows_in_session(db_session) -> Session: mrn="mrn", study_uid="1.2.3", extract=extract, - exported_at=datetime.datetime.now(tz=datetime.timezone.utc), + exported_at=datetime.datetime.now(tz=datetime.UTC), pseudo_study_uid=generate_uid(entropy_srcs=["already_exported"]), ) image_not_exported = Image( @@ -221,5 +221,5 @@ def mock_message() -> Message: project_name="test project", extract_generated_timestamp=datetime.datetime.strptime( "Dec 7 2023 2:08PM", "%b %d %Y %I:%M%p" - ).replace(tzinfo=datetime.timezone.utc), + ).replace(tzinfo=datetime.UTC), ) diff --git a/pixl_core/tests/uploader/test_ftps.py b/pixl_core/tests/uploader/test_ftps.py index 6a18f54c2..cbd5956dd 100644 --- a/pixl_core/tests/uploader/test_ftps.py +++ b/pixl_core/tests/uploader/test_ftps.py @@ -16,7 +16,7 @@ import filecmp import os from collections.abc import Generator -from datetime import datetime, timezone +from datetime import UTC, datetime from pathlib import Path import pandas as pd @@ -92,7 +92,7 @@ def test_send_via_ftps( def test_update_exported_and_save(rows_in_session) -> None: """Tests that the exported_at field is updated when a file is uploaded""" # ARRANGE - expected_export_time = datetime.now(tz=timezone.utc) + expected_export_time = datetime.now(tz=UTC) # ACT update_exported_at(generate_uid(entropy_srcs=["not_yet_exported"]), expected_export_time) @@ -101,7 +101,7 @@ def test_update_exported_and_save(rows_in_session) -> None: .filter(Image.pseudo_study_uid == generate_uid(entropy_srcs=["not_yet_exported"])) .one() ) - actual_export_time = new_row.exported_at.replace(tzinfo=timezone.utc) + actual_export_time = new_row.exported_at.replace(tzinfo=UTC) # ASSERT assert actual_export_time == expected_export_time @@ -119,7 +119,7 @@ def parquet_export(export_dir) -> ParquetExport: """ return ParquetExport( project_name_raw="i-am-a-project", - extract_datetime=datetime.now(tz=timezone.utc), + extract_datetime=datetime.now(tz=UTC), export_dir=export_dir, ) diff --git a/pixl_imaging/tests/test_imaging_processing.py b/pixl_imaging/tests/test_imaging_processing.py index b4821960e..17bcfa1a9 100644 --- a/pixl_imaging/tests/test_imaging_processing.py +++ b/pixl_imaging/tests/test_imaging_processing.py @@ -63,7 +63,7 @@ def message() -> Message: accession_number=ACCESSION_NUMBER, study_uid=STUDY_UID, study_date=datetime.datetime.strptime("01/01/1234 01:23:45", "%d/%m/%Y %H:%M:%S").replace( - tzinfo=datetime.timezone.utc + tzinfo=datetime.UTC ), procedure_occurrence_id=234, project_name="test project", @@ -79,7 +79,7 @@ def no_uid_message() -> Message: accession_number=ACCESSION_NUMBER, study_uid="", study_date=datetime.datetime.strptime("01/01/1234 01:23:45", "%d/%m/%Y %H:%M:%S").replace( - tzinfo=datetime.timezone.utc + tzinfo=datetime.UTC ), procedure_occurrence_id=234, project_name="test project", @@ -95,7 +95,7 @@ def pacs_message() -> Message: accession_number=PACS_ACCESSION_NUMBER, study_uid=PACS_STUDY_UID, study_date=datetime.datetime.strptime("01/01/1234 01:23:45", "%d/%m/%Y %H:%M:%S").replace( - tzinfo=datetime.timezone.utc + tzinfo=datetime.UTC ), procedure_occurrence_id=234, project_name="test project", @@ -111,7 +111,7 @@ def pacs_no_uid_message() -> Message: accession_number=PACS_ACCESSION_NUMBER, study_uid="ialsodontexist", study_date=datetime.datetime.strptime("01/01/1234 01:23:45", "%d/%m/%Y %H:%M:%S").replace( - tzinfo=datetime.timezone.utc + tzinfo=datetime.UTC ), procedure_occurrence_id=234, project_name="test project", @@ -127,7 +127,7 @@ def missing_message() -> Message: accession_number=MISSING_ACCESSION_NUMBER, study_uid=MISSING_STUDY_UID, study_date=datetime.datetime.strptime("01/01/1234 01:23:45", "%d/%m/%Y %H:%M:%S").replace( - tzinfo=datetime.timezone.utc + tzinfo=datetime.UTC ), procedure_occurrence_id=345, project_name="test project", diff --git a/pytest-pixl/src/pytest_pixl/helpers.py b/pytest-pixl/src/pytest_pixl/helpers.py index dc59b3779..2f9e07242 100644 --- a/pytest-pixl/src/pytest_pixl/helpers.py +++ b/pytest-pixl/src/pytest_pixl/helpers.py @@ -17,10 +17,10 @@ import subprocess from time import sleep -from typing import TYPE_CHECKING, Callable, Optional +from typing import TYPE_CHECKING, Optional if TYPE_CHECKING: - from collections.abc import Sequence + from collections.abc import Callable, Sequence from pathlib import Path from loguru import logger