deid.tests package

Submodules

deid.tests.Xtest_dicom_header module

class deid.tests.Xtest_dicom_header.TestDicomHeader(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_get_fields()[source]
test_get_identifiers()[source]
test_replace_identifiers()[source]
deid.tests.Xtest_dicom_header.get_dicom(dataset, return_dir=False)[source]

helper function to load a dicom

deid.tests.common module

deid.tests.common.create_recipe(actions, fields=None, values=None)[source]

Helper method to create a recipe file

deid.tests.common.get_dicom(dataset)[source]

helper function to load a dicom

deid.tests.common.get_file(dataset)[source]

get a dicom file

deid.tests.common.get_same_file(dataset)[source]

get a consistent dicom file

deid.tests.test_clean module

class deid.tests.test_clean.TestClean(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_pixel_cleaner_keepcoordinates()[source]

Test the pixel cleaner to ensure that a keepcoordinates retains appropriate pixels.

test_pixel_cleaner_keepcoordinates_from()[source]

Test the pixel cleaner to ensure that multiple keep coordinates retrieved from a dicom field are appropriately retained.

test_pixel_cleaner_keepcoordinates_noaction()[source]

Test the pixel cleaner to ensure that a keepcoordinates with no removecoordinates has no impact on the pixels.

test_pixel_cleaner_remove_all()[source]

Test the pixel cleaner to ensure it appropriately clears all pixels.

test_pixel_cleaner_remove_coordinates()[source]

Test the pixel cleaner to ensure it appropriately clears specified pixels.

test_pixel_cleaner_remove_coordinates_dicom_file()[source]

Test the pixel cleaner to ensure it appropriately clears specified pixels.

test_pixel_cleaner_remove_multiple()[source]

Test the pixel cleaner to ensure that multiple remove coordinates in the same filter remove the appropriate pixels.

test_pixel_cleaner_remove_multiple_filters()[source]

Test the pixel cleaner to ensure that multiple remove coordinates in different filters remove the appropriate pixels.

deid.tests.test_clean_pixel_dimensions module

class deid.tests.test_clean_pixel_dimensions.TestCleanPizelDimensions(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_2d_Greyscale_image()[source]

Test the pixel cleaner to ensure pixels are appropriately deidentified on “2D” images - Greyscale images. Pixel data will have the shape (X, Y)

test_2d_Greyscale_image_all()[source]

Test the pixel cleaner to ensure pixels are appropriately deidentified - all keyword - on “2D” images - Greyscale images. Pixel data will have the shape (X, Y)

test_3d_Greyscale_cine_clip()[source]

Test the pixel cleaner to ensure pixels are appropriately deidentified on “3D” images - greyscale cine clips. Pixel data will have the shape (frames, X, Y)

test_3d_Greyscale_cine_clip_all()[source]

Test the pixel cleaner to ensure pixels are appropriately deidentified - all keyword - on “3D” images - greyscale cine clips. Pixel data will have the shape (frames, X, Y)

test_3d_RGB_image()[source]

Test the pixel cleaner to ensure pixels are appropriately deidentified on “3D” images - RGB images. Pixel data will have the shape (X, Y, channel)

test_3d_RGB_image_all()[source]

Test the pixel cleaner to ensure pixels are appropriately deidentified - all keyword - on “3D” images - RGB images. Pixel data will have the shape (X, Y, channel)

test_4d_RGB_cine_clip()[source]

Test the pixel cleaner to ensure pixels are appropriately deidentified on “4D” images - RGB cine clips. Pixel data will have the shape (frames, X, Y, channel)

test_4d_RGB_cine_clip_all()[source]

Test the pixel cleaner to ensure pixels are appropriately deidentified - all keyword - on “4D” images - RGB cine clips. Pixel data will have the shape (frames, X, Y, channel)

deid.tests.test_clean_pixel_dimensions.get_file(dataset, image, tempdir=None)[source]

Helper to get a dicom file

deid.tests.test_config module

class deid.tests.test_config.TestConfig(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_find_deid()[source]
test_load_deid()[source]
test_standards()[source]

deid.tests.test_data module

class deid.tests.test_data.TestUtils(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_get_dataset()[source]

test_get_dataset will make sure we can load provided datasets

deid.tests.test_deid_recipe module

class deid.tests.test_deid_recipe.TestDeidRecipe(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_get_functions()[source]
test_load_recipe()[source]

deid.tests.test_dicom_fields module

class deid.tests.test_dicom_fields.TestDicomFields(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_field_expansion()[source]

deid.tests.test_dicom_funcs module

class deid.tests.test_dicom_funcs.TestDicomFuncs(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_basic_uuid()[source]

%header REPLACE ReferringPhysicianName deid_func:basic_uuid

test_dicom_jitter()[source]

RECIPE RULE REPLACE AcquisitionDate deid_func:jitter days=1

test_dicom_uuid()[source]

%header REPLACE ReferringPhysicianName deid_func:suffix_uuid org=myorg

test_pydicom_uuid()[source]

%header REPLACE ReferringPhysicianName deid_func:pydicom_uuid

test_suffix_uuid()[source]

%header REPLACE ReferringPhysicianName deid_func:suffix_uuid

test_user_provided_func()[source]

%header REMOVE ALL func:myfunction

deid.tests.test_dicom_groups module

class deid.tests.test_dicom_groups.TestDicomGroups(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_extract_groups()[source]

deid.tests.test_dicom_tags module

class deid.tests.test_dicom_tags.TestDicomTags(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_get_tag()[source]

deid.tests.test_dicom_utils module

class deid.tests.test_dicom_utils.TestDicomUtils(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_get_files()[source]
test_get_files_as_list()[source]
test_jitter_timestamp()[source]

deid.tests.test_file_meta module

class deid.tests.test_file_meta.TestDicom(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_replace_filemeta()[source]

RECIPE RULE REPLACE MediaStorageSOPInstanceUID 1.2.3.4.5.4.3.2.1

test_replace_protected_field()[source]

RECIPE RULE REPLACE TransferSyntaxUID 1.2.3.4.5.4.3.2.1

deid.tests.test_filter_detect module

class deid.tests.test_filter_detect.TestFilterDetect(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_filter_multiple_first_filter_match()[source]

Test the DicomCleaner.detect to ensure multiple detected filters are appropriately detected.

test_filter_multiple_rule_innerop_false()[source]

Test the DicomCleaner.detect to ensure multiple rules within a filter evaluated to false detects appropriately.

test_filter_multiple_second_filter_match()[source]

Test the DicomCleaner.detect to ensure multiple detected filters are appropriately detected.

test_filter_multiple_two_filter_match()[source]

Test the DicomCleaner.detect to ensure multiple detected filters are appropriately detected.

test_filter_multiple_zero_filter_match()[source]

Test the DicomCleaner.detect to ensure multiple detected filters are appropriately not detected when they shouldn’t match.

test_filter_multple_rule_innerop_true()[source]

Test the DicomCleaner.detect to ensure multiple rules within a filter evaluated to true detects appropriately.

test_filter_single_rule_false()[source]

Test the DicomCleaner.detect to ensure a single rule evaluated to false detects appropriately.

test_filter_single_rule_innerop_false()[source]

Test the DicomCleaner.detect to ensure a single rule with an inner operator evaluated to false detects appropriately.

test_filter_single_rule_innerop_true()[source]

Test the DicomCleaner.detect to ensure a single rule with an inner operator evaluated to true detects appropriately.

test_filter_single_rule_true()[source]

Test the DicomCleaner.detect to ensure a single rule evaluated to true detects appropriately.

deid.tests.test_replace_identifiers module

class deid.tests.test_replace_identifiers.TestDicom(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_add_private_constant()[source]

RECIPE RULE ADD 11112221 SIMPSON

test_add_private_constant_save_true()[source]

RECIPE RULE ADD 11112221 SIMPSON

test_add_public_constant()[source]

RECIPE RULE ADD PatientIdentityRemoved YES

test_add_tag_variable()[source]

RECIPE RULE ADD 11112221 var:myVar ADD PatientIdentityRemoved var:myVar

test_add_tag_variable_save_true()[source]

RECIPE RULE ADD 11112221 var:myVar ADD PatientIdentityRemoved var:myVar

test_addremove_compounding()[source]

Testing add/remove compounding: Checks to ensure that multiple rules applied to the same field result in both rules being applied. While in practice this may be somewhat of a nonsensical use case when large recipes exist multiple rules may inadvertently be defined. In prior versions of pydicom/deid rules were additive and recipes are built in that manner. This test ensures consistency with prior versions.

%header ADD PatientIdentityRemoved YES REMOVE PatientIdentityRemoved

test_blank_field_keep_field_compounding_should_keep()[source]

%header ADD PatientIdentityRemoved Yes BLANK StudyDate KEEP StudyDate

test_expander_except()[source]

RECIPE RULE REMOVE except:Manufacturer

test_expanders()[source]

RECIPE RULES REMOVE contains:Collimation REMOVE endswith:Diameter REMOVE startswith:Exposure

test_fieldset_remove()[source]

RECIPE %fields field_set1 FIELD Manufacturer FIELD contains:Time %header REMOVE fields:field_set1

test_fieldset_remove_private()[source]

%fields field_set2_private FIELD 00090010 FIELD PatientID %header REMOVE fields:field_set2_private

test_jitter_blank_date()[source]

Testing to ensure jittering a date field which contains a blank value does not cause an unhandled exception

%header JITTER ContentDate 1

test_jitter_compounding()[source]

Testing jitter compounding: Checks to ensure that multiple jitter rules applied to the same field result in both rules being applied. While in practice this may be somewhat of a nonsensical use case when large recipes exist multiple rules may inadvertently be defined. In prior versions of pydicom/deid rules were additive and recipes are built in that manner. This test ensures consistency with prior versions.

%header JITTER StudyDate 1 JITTER StudyDate 2

test_jitter_date()[source]

RECIPE RULE JITTER StudyDate 1

test_jitter_private_tag()[source]

Testing to private tags can be jittered

%header JITTER 00291019 1

test_jitter_replace_compounding()[source]

RECIPE RULE JITTER AcquisitionDate 1 REPLACE AcquisitionDate 20210330

test_jitter_timestamp()[source]

RECIPE RULE JITTER AcquisitionDateTime 1

test_jitter_values()[source]

Testing to ensure fields (including non-DA/DT VR fields) identified by a values list are appropriately jittered

%values value_set1 FIELD StudyDate %header JITTER values:value_set1 1

test_nested_replace()[source]

Fields are read into a dictionary lookup that should index back to the correct data element. We add this test to ensure this is happening, meaning that a replace action to a particular contains: string changes both top level and nested fields.

%header

REPLACE contains:StudyInstanceUID var:new_val

test_remove()[source]

RECIPE RULE REMOVE InstitutionName REMOVE 00190010

test_remove_all_add_field_compounding_should_add()[source]

%header REMOVE ALL ADD PatientIdentityRemoved Yes ADD StudyDate 19700101

test_remove_all_blank_field_compounding_should_remove()[source]

%header REMOVE ALL ADD PatientIdentityRemoved Yes BLANK StudyDate

test_remove_all_func()[source]

%header REMOVE ALL func:contains_hibbard

test_remove_all_jitter_one_should_jitter()[source]

%header REMOVE ALL JITTER StudyDate 1 ADD PatientIdentityRemoved Yes

test_remove_all_keep_field_compounding_should_keep()[source]

%header REMOVE ALL KEEP StudyDate ADD PatientIdentityRemoved Yes

test_remove_all_keep_one_jitter_it_should_keep()[source]

%header REMOVE ALL KEEP StudyDate JITTER StudyDate 1 ADD PatientIdentityRemoved Yes

test_remove_all_keep_one_replace_it_should_keep()[source]

%header REMOVE ALL KEEP StudyDate REPLACE StudyDate 19700101 ADD PatientIdentityRemoved Yes

test_remove_all_replace_one_should_replace()[source]

%header REMOVE ALL REPLACE StudyDate 19700101 ADD PatientIdentityRemoved Yes

test_remove_except_field_keep_other_field_compounding_should_keep()[source]

%header REMOVE ALL ADD PatientIdentityRemoved Yes

test_remove_except_is_acting_as_substring()[source]

%header REMOVE except:Manufacturer

test_remove_field_jitter_it_should_jitter()[source]

%header REMOVE StudyDate JITTER StudyDate 1 ADD PatientIdentityRemoved Yes

test_remove_field_keep_same_field_compounding_should_keep()[source]

%header REMOVE StudyDate KEEP StudyDate ADD PatientIdentityRemoved Yes

test_remove_field_replace_it_should_replace()[source]

%header REMOVE StudyDate REPLACE StudyDate 19700101 ADD PatientIdentityRemoved Yes

test_remove_keep_add_field_compounding_should_add()[source]

%header REMOVE ALL KEEP StudyDate ADD StudyDate 19700101 ADD PatientIdentityRemoved Yes

test_removeadd_compounding()[source]

Testing remove/add compounding: Checks to ensure that multiple rules applied to the same field result in both rules being applied. While in practice this may be somewhat of a nonsensical use case when large recipes exist multiple rules may inadvertently be defined. In prior versions of pydicom/deid rules were additive and recipes are built in that manner. This test ensures consistency with prior versions.

%header REMOVE StudyDate ADD StudyDate 20200805

test_replace_with_constant()[source]

RECIPE RULE REPLACE AccessionNumber 987654321 REPLACE 00190010 NEWVALUE!

test_strip_sequences()[source]

Testing strip sequences: Checks to ensure that the strip_sequences removes all tags of type sequence. Since sequence removal relies on dicom.iterall(), nested sequences previously caused exceptions to be thrown when child (or duplicate) sequences existed within the header.

%header ADD PatientIdentityRemoved YES

test_tag_expanders_midtag()[source]

REMOVE contains:8103 Should remove: (0008, 103e) Series Description

test_tag_expanders_tagelement()[source]

%header REMOVE contains:0010

test_tag_expanders_taggroup()[source]

%header REMOVE contains:0009

test_valueset_empty_remove()[source]

Testing to ensure correct actions are taken when a defined valueset contains no data (the field identified has an empty value). Since the ConversionType flag contains “No Value”, in the test below, value_set1 will be empty and as a result this combination of rules should have no impact on the header. The input header should be identical to the output header.

%values value_set1 FIELD ConversionType %header REMOVE values:value_set1

test_valueset_private()[source]

%values value_set2_private FIELD 00311020 SPLIT 00090010 by=” “;minlength=4 %header REMOVE values:value_set2_private

test_valueset_remove()[source]

%values value_set1 FIELD contains:Manufacturer SPLIT contains:Physician by=”^”;minlength=3 %header REMOVE values:value_set1

test_valueset_remove_one_empty()[source]

Testing to ensure correct actions are taken when a defined valueset contains a field that has an empty value. Since the ConversionType flag contains “No Value”, in the test below, value_set1 will only have the value from Manufacturer and should only identify the fields which contain “SIEMENS”.

%values value_set1 FIELD ConversionType FIELD Manufacturer %header REMOVE values:value_set1

deid.tests.test_utils module

class deid.tests.test_utils.TestUtils(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_get_installdir()[source]

get install directory should return the base of where singularity is installed

test_get_temporary_name()[source]

test_get_temporary_name will test the generation of a temporary file name.

test_recursive_find()[source]

test_recursive_find should detect 7 dicoms

test_write_read_files()[source]

test_write_read_files will test the functions write_file and read_file

deid.tests.test_utils_files module

class deid.tests.test_utils_files.TestDicom(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_get_files()[source]
test_get_files_as_list()[source]

Module contents