From 6d179bd57ff7ec3da9fa895e5c2ea7e18d0c07fd Mon Sep 17 00:00:00 2001 From: David Wikler Date: Tue, 31 Dec 2024 09:00:26 +0100 Subject: [PATCH] Correct lint errors --- tdwii_plus_examples/cstorehandler.py | 36 ++++++++++++------- tdwii_plus_examples/cstorescp.py | 3 +- .../tests/test_basescp_unit.py | 10 +++--- .../tests/test_cechohandler.py | 3 +- .../tests/test_cechoscp_unit.py | 3 +- .../tests/test_cstorehandler.py | 15 ++++---- .../tests/test_cstorescp_integration.py | 15 ++++---- .../tests/test_cstorescp_unit.py | 5 ++- 8 files changed, 55 insertions(+), 35 deletions(-) diff --git a/tdwii_plus_examples/cstorehandler.py b/tdwii_plus_examples/cstorehandler.py index 3584d4a..a8632ba 100644 --- a/tdwii_plus_examples/cstorehandler.py +++ b/tdwii_plus_examples/cstorehandler.py @@ -20,29 +20,41 @@ "1.2.840.10008.5.1.4.1.1.128": ( "PT", "Positron Emission Tomography Image Storage"), "1.2.840.10008.5.1.4.1.1.481.1": ( - "RI", "RTIMG", "RTIMAGE", "RT Image Storage"), + "RI", "RTIMG", "RTIMAGE", + "RT Image Storage"), "1.2.840.10008.5.1.4.1.1.481.2": ( - "RD", "RTDOSE", "RT Dose Storage"), + "RD", "RTDOSE", + "RT Dose Storage"), "1.2.840.10008.5.1.4.1.1.481.3": ( - "RS", "RTSTRUCT", "RTSTRUCTURESET", "RT Structure Set Storage"), + "RS", "RTSTRUCT", "RTSTRUCTURESET", + "RT Structure Set Storage"), "1.2.840.10008.5.1.4.1.1.481.4": ( - "RR", "RTREC", "RTRECORD", "RT Beam Treatment Record Storage"), + "RR", "RTREC", "RTRECORD", + "RT Beam Treatment Record Storage"), "1.2.840.10008.5.1.4.1.1.481.5": ( - "RP", "RTPLAN", "RTPLAN", "RT Plan Storage"), + "RP", "RTPLAN", "RTPLAN", + "RT Plan Storage"), "1.2.840.10008.5.1.4.1.1.481.6": ( - "BR", "RTBYREC", "RTBRACHYRECORD", "RT Brachy Treatment Record Storage"), + "BR", "RTBYREC", "RTBRACHYRECORD", + "RT Brachy Treatment Record Storage"), "1.2.840.10008.5.1.4.1.1.481.7": ( - "SR", "SUMREC", "RTSUMRECORD", "RT Treatment Summary Record Storage"), + "SR", "SUMREC", "RTSUMRECORD", + "RT Treatment Summary Record Storage"), "1.2.840.10008.5.1.4.1.1.481.8": ( - "RN", "RTIONPLN", "RTIONPLAN", "RT Ion Plan Storage"), + "RN", "RTIONPLN", "RTIONPLAN", + "RT Ion Plan Storage"), "1.2.840.10008.5.1.4.1.1.481.9": ( - "IR", "RTIONREC", "RTIONRECORD", "RT Ion Beams Treatment Record Storage"), + "IR", "RTIONREC", "RTIONRECORD", + "RT Ion Beams Treatment Record Storage"), "1.2.840.10008.5.1.4.34.7": ( - "BDI", "RTBDI", "RTBEAMDELIVERYINSTRUCTION", "RT Beams Delivery Instruction Storage"), + "BDI", "RTBDI", "RTBEAMDELIVERYINSTRUCTION", + "RT Beams Delivery Instruction Storage"), "1.2.840.10008.5.1.4.1.1.66.1": ( - "REG", "IMREG", "IMAGEREGISTRATION", "Spatial Registration Storage"), + "REG", "IMREG", "IMAGEREGISTRATION", + "Spatial Registration Storage"), "1.2.840.10008.5.1.4.1.1.66.3": ( - "DIR", "DEFIMREG", "DEFORMABLEIMAGEREGISTRATION", "Deformable Spatial Registration Storage") + "DIR", "DEFIMREG", "DEFORMABLEIMAGEREGISTRATION", + "Deformable Spatial Registration Storage") } diff --git a/tdwii_plus_examples/cstorescp.py b/tdwii_plus_examples/cstorescp.py index 8f0fb87..3704b43 100644 --- a/tdwii_plus_examples/cstorescp.py +++ b/tdwii_plus_examples/cstorescp.py @@ -187,7 +187,8 @@ def _validate_syntaxes(self, items, uid_type): self.logger.debug(f"Valid {uid_type} : {item}") elif item in valid_syntaxes.values(): valid_items.append( - next(UID for UID, keyword in valid_syntaxes.items() if keyword == item)) + next(UID for UID, keyword in valid_syntaxes.items() + if keyword == item)) self.logger.debug(f"Valid {uid_type} : {item}") else: invalid_items.append(item) diff --git a/tdwii_plus_examples/tests/test_basescp_unit.py b/tdwii_plus_examples/tests/test_basescp_unit.py index ea3032d..c0756e7 100644 --- a/tdwii_plus_examples/tests/test_basescp_unit.py +++ b/tdwii_plus_examples/tests/test_basescp_unit.py @@ -6,7 +6,7 @@ from tdwii_plus_examples.basescp import BaseSCP from tdwii_plus_examples.basehandlers import handle_open, handle_close -from pynetdicom import AE, evt +from pynetdicom import evt class TestBaseSCP(unittest.TestCase): @@ -82,8 +82,9 @@ def test_init_params( with self.assertRaises(expected_exception) as exception_context: BaseSCP(ae_title, bind_address, port, logger) self.test_logger.info( - f"Raised expected exception: {expected_exception.__name__}:" - f" {exception_context.exception}") + "Raised expected exception: %s: %s" % ( + expected_exception.__name__, + exception_context.exception)) else: scp = BaseSCP(ae_title, bind_address, port, logger) @@ -115,7 +116,8 @@ def test_init_params( # Print the log messages # for record in self.memory_handler.buffer: - # self.test_logger.info(f"{record.levelname}: {record.getMessage()}") + # self.test_logger.info("%s: %s" % ( + # record.levelname, record.getMessage()[:77])) # Mock unit tests for the run method diff --git a/tdwii_plus_examples/tests/test_cechohandler.py b/tdwii_plus_examples/tests/test_cechohandler.py index 5bdd95e..a6b4ba4 100644 --- a/tdwii_plus_examples/tests/test_cechohandler.py +++ b/tdwii_plus_examples/tests/test_cechohandler.py @@ -24,7 +24,8 @@ def test_handle_cecho(self, MockLogger): # Check that the logger was called with the correct message mock_logger.info.assert_called_once_with( - 'Received C-ECHO request from TEST_AET@127.0.0.1:104 at 2024-12-28 11:00:00' + 'Received C-ECHO request from TEST_AET@127.0.0.1:104 at ' + '2024-12-28 11:00:00' ) diff --git a/tdwii_plus_examples/tests/test_cechoscp_unit.py b/tdwii_plus_examples/tests/test_cechoscp_unit.py index eb31379..53ac236 100644 --- a/tdwii_plus_examples/tests/test_cechoscp_unit.py +++ b/tdwii_plus_examples/tests/test_cechoscp_unit.py @@ -36,7 +36,8 @@ def test_init_params(self, ae_title, bind_address, port, logger_name): scp = CEchoSCP(ae_title=ae_title, bind_address=bind_address, port=port, logger=logger) - self.assertEqual(scp.ae_title, "ECHO_SCP" if not ae_title else ae_title) + self.assertEqual( + scp.ae_title, "ECHO_SCP" if not ae_title else ae_title) self.assertEqual(scp.bind_address, bind_address) self.assertEqual(scp.port, port) self.assertEqual( diff --git a/tdwii_plus_examples/tests/test_cstorehandler.py b/tdwii_plus_examples/tests/test_cstorehandler.py index 457e29d..516545a 100644 --- a/tdwii_plus_examples/tests/test_cstorehandler.py +++ b/tdwii_plus_examples/tests/test_cstorehandler.py @@ -11,7 +11,7 @@ def create_mock_dataset(): ds = Dataset() - ds.SOPClassUID = '1.2.840.10008.5.1.4.1.1.7' # SC Image Storage + ds.SOPClassUID = uid.SecondaryCaptureImageStorage ds.SOPInstanceUID = uid.generate_uid() ds.PatientName = 'Test^Patient' ds.PatientID = '123456' @@ -23,9 +23,9 @@ def create_mock_dataset(): def create_mock_file_meta(sop_instance_uid): file_meta = FileMetaDataset() # Secondary Capture Image Storage - file_meta.MediaStorageSOPClassUID = '1.2.840.10008.5.1.4.1.1.7' + file_meta.MediaStorageSOPClassUID = uid.SecondaryCaptureImageStorage file_meta.MediaStorageSOPInstanceUID = sop_instance_uid - file_meta.TransferSyntaxUID = '1.2.840.10008.1.2.1' # Explicit VR Little Endian + file_meta.TransferSyntaxUID = uid.ExplicitVRLittleEndian file_meta.ImplementationClassUID = uid.PYDICOM_IMPLEMENTATION_UID return file_meta @@ -55,7 +55,8 @@ def tearDownClass(cls): (False, '/invalid/path\0', 0xA700), # Status.OUT_OF_RESOURCES ]) @patch('logging.Logger') - def test_handle_cstore(self, ignore, output_directory, expected_status, MockLogger): + def test_handle_cstore(self, ignore, output_directory, expected_status, + MockLogger): # Create a mock args mock_args = MagicMock() @@ -93,7 +94,8 @@ def test_handle_cstore(self, ignore, output_directory, expected_status, MockLogg # Check that the logger was called with the correct messages if ignore: - mock_logger.info.assert_called_once_with("Ignoring C-STORE request") + mock_logger.info.assert_called_once_with( + "Ignoring C-STORE request") elif output_directory is None: mock_logger.error.assert_called_once_with( "args.output_directory attribute not present or None") @@ -106,7 +108,8 @@ def test_handle_cstore(self, ignore, output_directory, expected_status, MockLogg else: mock_logger.info.assert_any_call("Processing C-STORE request") mock_logger.info.assert_any_call( - f"Storing DICOM file: SC.{self.mock_event.dataset.SOPInstanceUID}.dcm") + "Storing DICOM file: SC.%s.dcm" + % self.mock_event.dataset.SOPInstanceUID) if __name__ == '__main__': diff --git a/tdwii_plus_examples/tests/test_cstorescp_integration.py b/tdwii_plus_examples/tests/test_cstorescp_integration.py index 8b99ac3..3bb2de4 100644 --- a/tdwii_plus_examples/tests/test_cstorescp_integration.py +++ b/tdwii_plus_examples/tests/test_cstorescp_integration.py @@ -7,12 +7,9 @@ from logging.handlers import MemoryHandler import subprocess import time -import re -from pydicom.dataset import Dataset, FileMetaDataset, FileDataset +from pydicom.dataset import FileMetaDataset, FileDataset from pydicom import uid -from pynetdicom import AE -from pynetdicom.sop_class import SecondaryCaptureImageStorage from tdwii_plus_examples.cstorescp import CStoreSCP @@ -105,9 +102,13 @@ def test_run_and_check_log(self): self.scp.run() # Send the dataset using pynetdicom's storescu.py - subprocess.check_call(['python', '-m', 'pynetdicom', 'storescu', - 'localhost', '11112', - '-aet', 'STORESCU', '-aec', 'STORE_SCP', self.dataset_file]) + subprocess.check_call( + [ + 'python', '-m', 'pynetdicom', 'storescu', + 'localhost', '11112', '-aet', 'STORESCU', + '-aec', 'STORE_SCP', self.dataset_file + ] + ) # Wait for 1 second to ensure the logs are generated time.sleep(1) diff --git a/tdwii_plus_examples/tests/test_cstorescp_unit.py b/tdwii_plus_examples/tests/test_cstorescp_unit.py index f30cb30..ff0b65c 100644 --- a/tdwii_plus_examples/tests/test_cstorescp_unit.py +++ b/tdwii_plus_examples/tests/test_cstorescp_unit.py @@ -5,7 +5,7 @@ from logging.handlers import MemoryHandler from parameterized import parameterized from pydicom import uid -from pynetdicom import DEFAULT_TRANSFER_SYNTAXES, evt +from pynetdicom import DEFAULT_TRANSFER_SYNTAXES from tdwii_plus_examples.cstorescp import CStoreSCP # Define dictionaries of valid and invalid SOP Classes and Transfer syntaxes @@ -182,5 +182,4 @@ def test_init_params(self, self.assertEqual(scp.store_directory, store_directory) # Print the log messages - for record in self.memory_handler.buffer: - self.test_logger.info(f"{record.levelname}: {record.getMessage()}") + self.test_logger.info(f"{log_output}")