Skip to content

Commit

Permalink
Correct lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dwikler committed Dec 31, 2024
1 parent 6ab9f2c commit 6d179bd
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 35 deletions.
36 changes: 24 additions & 12 deletions tdwii_plus_examples/cstorehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}


Expand Down
3 changes: 2 additions & 1 deletion tdwii_plus_examples/cstorescp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions tdwii_plus_examples/tests/test_basescp_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion tdwii_plus_examples/tests/test_cechohandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]:104 at 2024-12-28 11:00:00'
'Received C-ECHO request from [email protected]:104 at '
'2024-12-28 11:00:00'
)


Expand Down
3 changes: 2 additions & 1 deletion tdwii_plus_examples/tests/test_cechoscp_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 9 additions & 6 deletions tdwii_plus_examples/tests/test_cstorehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand All @@ -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__':
Expand Down
15 changes: 8 additions & 7 deletions tdwii_plus_examples/tests/test_cstorescp_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions tdwii_plus_examples/tests/test_cstorescp_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")

0 comments on commit 6d179bd

Please sign in to comment.