def test_equal(): dicom1 = DicomBase.from_dict({ 'Manufacturer': 'PyMedPhys', 'PatientName': 'Python^Monte' }) dicom2 = DicomBase.from_dict({ 'Manufacturer': 'PyMedPhys', 'PatientName': 'Python^Monte' }) assert dicom1 == dicom2 # Equality from dict try: fp1 = DicomBytesIO() dicom1.to_file(fp1) fp2 = DicomBytesIO() dicom2.to_file(fp2) dicom1_from_file = DicomBase.from_file(fp1) dicom2_from_file = DicomBase.from_file(fp2) # Equality from file (implicitly also from dataset) assert dicom1_from_file == dicom2_from_file dicom1_from_file.dataset.PatientName = 'test^PatientName change' assert dicom1_from_file != dicom2_from_file # Negative case dicom1_from_file.dataset.PatientName = 'Python^Monte' assert dicom1_from_file == dicom2_from_file # Equality post re-assignment dicom1_from_file_copied = deepcopy(dicom1_from_file) assert dicom1_from_file == dicom1_from_file_copied # Equality from deepcopy finally: fp1.close() fp2.close()
def test_surface_entry_with_fallback(): should_fail_with_unsupported_gantry = DicomBase.from_dict( {'BeamSequence': [{ 'ControlPointSequence': [{ 'GantryAngle': "5.0" }] }]}) with pytest.raises(ValueError): get_surface_entry_point_with_fallback( should_fail_with_unsupported_gantry.dataset) plan_dataset = pydicom.read_file(str(DICOM_PLAN_FILEPATH), force=True) for beam in plan_dataset.BeamSequence: for control_point in beam.ControlPointSequence: try: del control_point.SurfaceEntryPoint except AttributeError: pass with pytest.raises(DICOMEntryMissing): get_surface_entry_point(plan_dataset) assert get_surface_entry_point_with_fallback(plan_dataset) == (0.0, -300.0, 0.0)
def test_surface_entry(): plan = pydicom.read_file(str(DICOM_PLAN_FILEPATH), force=True) assert get_surface_entry_point(plan) == (0.0, -300.0, 0.0) should_pass = DicomBase.from_dict({ 'BeamSequence': [{ 'ControlPointSequence': [{ 'SurfaceEntryPoint': ["10.0", "20.0", "30.0"] }] }] }) assert get_surface_entry_point(should_pass.dataset) == (10.0, 20.0, 30.0) should_fail_with_no_points = DicomBase.from_dict( {'BeamSequence': [{ 'ControlPointSequence': [] }]}) with pytest.raises(DICOMEntryMissing): get_surface_entry_point(should_fail_with_no_points.dataset) should_fail_with_differing_points = DicomBase.from_dict({ 'BeamSequence': [ { 'ControlPointSequence': [{ 'SurfaceEntryPoint': ["10.0", "20.0", "30.0"] }] }, { 'ControlPointSequence': [{ 'SurfaceEntryPoint': ["20.0", "20.0", "30.0"] }] }, ] }) with pytest.raises(ValueError): get_surface_entry_point(should_fail_with_differing_points.dataset)
def test_anonymise(): expected_dataset = dicom_dataset_from_dict({ 'Manufacturer': 'PyMedPhys', 'PatientName': 'Anonymous' }) dicom = DicomBase.from_dict({ 'Manufacturer': 'PyMedPhys', 'PatientName': 'Python^Monte' }) dicom.anonymise(inplace=True) assert dicom.dataset == expected_dataset
def test_anonymise(): expected_dataset = dicom_dataset_from_dict({ "Manufacturer": "PyMedPhys", "PatientName": "Anonymous" }) dicom = DicomBase.from_dict({ "Manufacturer": "PyMedPhys", "PatientName": "Python^Monte" }) dicom.anonymise(inplace=True) assert dicom.dataset == expected_dataset
def test_to_and_from_file(): temp_file = io.BytesIO() dicom = DicomBase.from_dict({ 'Manufacturer': 'PyMedPhys', 'PatientName': 'Python^Monte' }) dicom.to_file(temp_file) new_dicom = DicomBase.from_file(temp_file) # TODO: Without the str this was passing locally but not on CI. Further # investigation needed. assert new_dicom == dicom