-
-
Notifications
You must be signed in to change notification settings - Fork 53
Fixes for failing unit tests #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
smjoshiatglobus
wants to merge
31
commits into
KitwareMedical:master
from
globusmedical:fix_unit_test
Closed
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
a222d63
Merge pull request #4 from KitwareMedical/master
smjoshiatglobus 4b1ee1d
unit test fix
smjoshiatglobus 9818970
pipenv setup
smjoshiatglobus 387cfb4
exclude DA type for deletion test
smjoshiatglobus bdaad70
fixed replacement tests
smjoshiatglobus a4bbcc9
black formatting
smjoshiatglobus f02873f
black formatting
smjoshiatglobus 683c4ba
black formatting
smjoshiatglobus 02ce585
silenced sourcery warnings
smjoshiatglobus 6ea6eaa
support spellchecker
smjoshiatglobus 8d31c5c
typos and spellcheck
smjoshiatglobus 399d136
added issue number and link
smjoshiatglobus 9780514
behaviour is correct spelling
smjoshiatglobus ee535a8
Fix for #63, can't set attribute
smjoshiatglobus 3efe54f
Suppressed filename copying warning
smjoshiatglobus 843465f
Merge pull request #5 from KitwareMedical/master
smjoshiatglobus 2ec2a8d
Merge branch 'master' into fix_unit_test
smjoshiatglobus f6f8421
isinstance instead of type
smjoshiatglobus 2d53d34
Remove unused code
smjoshiatglobus f5bfe2c
black formatting
smjoshiatglobus da91c4f
silenced sourcery warnings
smjoshiatglobus 2f07e17
support spellchecker
smjoshiatglobus 893ce24
typos and spellcheck
smjoshiatglobus 9af7d7c
added issue number and link
smjoshiatglobus ad6b05a
behaviour is correct spelling
smjoshiatglobus bc08b06
Fix for #63, can't set attribute
smjoshiatglobus 0872799
Suppressed filename copying warning
smjoshiatglobus 428ccb3
ENH: Add dicom fields scrapping script
pchoisel 2aae45f
isinstance instead of type
smjoshiatglobus af2f02c
Remove unused code
smjoshiatglobus 89e302d
Merge branch 'fix_unit_test' of github.com:globusmedical/dicom-anonym…
smjoshiatglobus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| # pipenv is useful for developing local package in | ||
| # editable mode. See https://pypi.org/project/pipenv/ | ||
|
|
||
| [[source]] | ||
| url = "https://pypi.org/simple" | ||
| verify_ssl = true | ||
| name = "pypi" | ||
|
|
||
| [packages] | ||
| dicom-anonymizer = {file = ".", editable = true} | ||
|
|
||
| [dev-packages] | ||
| pytest = "*" | ||
| setuptools = "*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // cSpell Settings | ||
| { | ||
| // Version of the setting file. Always 0.2 | ||
| "version": "0.2", | ||
| // language - current active spelling language | ||
| "language": "en", | ||
| // ignorepaths - list of glob patterns for files to ignore | ||
| "ignorePaths": [ | ||
| "ext", | ||
| "*.json", | ||
| "Pipfile.lock", | ||
| "**/tests" | ||
| ], | ||
| // words - list of words to be always considered correct | ||
| "words": [ | ||
| "anonymization", | ||
| "argparse", | ||
| "bdist", | ||
| "behaviour", | ||
| "dcmread", | ||
| "DICM", | ||
| "DICOM", | ||
| "dicomanonymizer", | ||
| "dicomfields", | ||
| "Edern", | ||
| "Fiducials", | ||
| "Fontaine", | ||
| "Haumont", | ||
| "Kitware", | ||
| "Laurenn", | ||
| "multival", | ||
| "pipenv", | ||
| "Pipfile", | ||
| "pydicom", | ||
| "pytest", | ||
| "Radiopharmaceutical", | ||
| "setuptools", | ||
| "simpledicomanonymizer", | ||
| "tqdm", | ||
| "venv", | ||
| "virtualenv", | ||
| "xgggg" | ||
| ] | ||
| // flagWords - list of words to be always considered incorrect | ||
| // This is useful for offensive words and common spelling errors. | ||
| // For example "hte" should be "the" | ||
| // "flagWords": [ | ||
| // "hte" | ||
| // ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ | |
| warnings.filterwarnings("ignore") | ||
|
|
||
|
|
||
| def get_all_failed(): | ||
| def get_all_failed(): # sourcery skip: inline-immediately-returned-variable | ||
| # The following files are intended to fail dcmread | ||
| # No point including them for anonymization testing | ||
| dcmread_failed = [ | ||
|
|
@@ -27,50 +27,7 @@ def get_all_failed(): | |
| "OT-PAL-8-face.dcm", | ||
| ] | ||
|
|
||
| # TODO: Investigate why these fail replacement test of anonymization | ||
| replaced_failed = [ | ||
| "693_J2KI.dcm", | ||
| "JPEG-lossy.dcm", | ||
| "JPEG2000-embedded-sequence-delimiter.dcm", | ||
| "JPEG2000.dcm", | ||
| "JPGExtended.dcm", | ||
| "reportsi.dcm", | ||
| "reportsi_with_empty_number_tags.dcm", | ||
| "SC_rgb_gdcm_KY.dcm", | ||
| "SC_rgb_jpeg_lossy_gdcm.dcm", | ||
| "693_UNCI.dcm", | ||
| "JPEG-LL.dcm", | ||
| "JPEG2000_UNC.dcm", | ||
| "MR2_J2KI.dcm", | ||
| "MR2_J2KR.dcm", | ||
| "MR2_UNCI.dcm", | ||
| "RG1_J2KI.dcm", | ||
| "RG1_J2KR.dcm", | ||
| "RG1_UNCI.dcm", | ||
| "RG3_J2KI.dcm", | ||
| "RG3_J2KI.dcm", | ||
| "RG3_J2KR.dcm", | ||
| "RG3_UNCI.dcm", | ||
| "SC_rgb_gdcm2k_uncompressed.dcm", | ||
| "US1_J2KI.dcm", | ||
| "US1_J2KR.dcm", | ||
| "US1_UNCI.dcm", | ||
| "test-SR.dcm", | ||
| ] | ||
|
|
||
| # TODO: Investigate why these fail deletion test of anonymization | ||
| deleted_failed = [ | ||
| "color3d_jpeg_baseline.dcm", | ||
| "JPGLosslessP14SV1_1s_1f_8b.dcm", | ||
| "test-SR.dcm", | ||
| ] | ||
|
|
||
| # TODO: Investigate why these fail emptying test of anonymization | ||
| emptied_failed = [ | ||
| "JPGLosslessP14SV1_1s_1f_8b.dcm", | ||
| "test-SR.dcm", | ||
| ] | ||
| return dcmread_failed + replaced_failed + deleted_failed + emptied_failed | ||
| return dcmread_failed | ||
|
|
||
|
|
||
| @lru_cache(maxsize=None) | ||
|
|
@@ -83,6 +40,7 @@ def get_passing_files(): | |
| @pytest.fixture(scope="module", params=get_passing_files()) | ||
| def orig_anon_dataset(request): | ||
| orig_ds = dcmread(request.param) | ||
| orig_ds.filename = None # Non-None value causes warnings in copy(). Not needed for this testing | ||
| anon_ds = orig_ds.copy() | ||
| anonymize_dataset(anon_ds) | ||
| return (orig_ds, anon_ds) | ||
|
|
@@ -91,34 +49,81 @@ def orig_anon_dataset(request): | |
| def test_deleted_tags_are_removed(orig_anon_dataset): | ||
| orig_ds, anon_ds = orig_anon_dataset | ||
| deleted_tags = dicomfields.X_TAGS | ||
| for tt in deleted_tags: | ||
| if len(tt) == 2 and tt in orig_ds: | ||
| assert tt not in anon_ds | ||
|
|
||
| for tt in deleted_tags: # sourcery skip: no-loop-in-tests | ||
| if ( | ||
| len(tt) == 2 and tt in orig_ds | ||
| ): # sourcery skip: merge-nested-ifs, no-conditionals-in-tests | ||
|
Comment on lines
+54
to
+56
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This formatting feels weird, is it because of Flake8 ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment suppresses couple of errors from Sourcery plugin: https://sourcery.ai/ |
||
| # TODO: Investigate why Date type are replaced instead of deleted | ||
| # See issue https://github.com/KitwareMedical/dicom-anonymizer/issues/56 | ||
| if orig_ds[tt].VR != "DA": # sourcery skip: no-conditionals-in-tests | ||
| assert ( | ||
| tt not in anon_ds | ||
| ), f"({tt[0]:04X},{tt[1]:04x}):{orig_ds[tt].value}->{anon_ds[tt].value}" | ||
|
|
||
| def test_changed_tags_are_replaced(orig_anon_dataset): | ||
| changed_tags = ( | ||
| dicomfields.U_TAGS | ||
| + dicomfields.D_TAGS | ||
| + dicomfields.Z_D_TAGS | ||
| + dicomfields.X_D_TAGS | ||
| + dicomfields.X_Z_D_TAGS | ||
| + dicomfields.X_Z_U_STAR_TAGS | ||
| ) | ||
|
|
||
| changed_tags = ( | ||
| dicomfields.U_TAGS | ||
| + dicomfields.D_TAGS | ||
| + dicomfields.Z_D_TAGS | ||
| + dicomfields.X_D_TAGS | ||
| + dicomfields.X_Z_D_TAGS | ||
| + dicomfields.X_Z_U_STAR_TAGS | ||
| ) | ||
|
|
||
| empty_values = (0, "", "00010101", "000000.00", "ANONYMIZED") | ||
|
|
||
|
|
||
| def is_elem_replaced(orig, anon) -> bool: | ||
| if orig.VR == "SQ": | ||
| for x, y in zip(orig.value, anon.value): | ||
| for tt in changed_tags: | ||
| if tt in x and len(x[tt].value) > 0: | ||
| assert tt in y, f"({tt[0]:04X},{tt[1]:04x}):{x[tt].value}->missing!" | ||
| assert is_elem_replaced( | ||
| x[tt], y[tt] | ||
| ), f"({tt[0]:04X},{tt[1]:04x}):{x[tt].value} not replaced" | ||
| return True | ||
|
|
||
| return orig.value != anon.value if orig.value not in empty_values else True | ||
|
|
||
|
|
||
| def test_changed_tags_are_replaced(orig_anon_dataset): | ||
| orig_ds, anon_ds = orig_anon_dataset | ||
|
|
||
| for tt in changed_tags: | ||
| if tt in orig_ds: | ||
| assert anon_ds[tt] != orig_ds[tt] | ||
| for tt in changed_tags: # sourcery skip: no-loop-in-tests | ||
| if tt in orig_ds: # sourcery skip: no-conditionals-in-tests | ||
| assert ( | ||
| tt in anon_ds | ||
| ), f"({tt[0]:04X},{tt[1]:04x}):{orig_ds[tt].value}->missing!" | ||
| assert is_elem_replaced( | ||
| orig_ds[tt], anon_ds[tt] | ||
| ), f"({tt[0]:04X},{tt[1]:04x}):{orig_ds[tt].value} not replaced" | ||
|
|
||
|
|
||
| def test_empty_tags_are_emptied(orig_anon_dataset): | ||
| empty_values = (0, "", "00010101", "000000.00") | ||
| empty_tags = dicomfields.Z_TAGS + dicomfields.X_Z_TAGS | ||
| empty_tags = dicomfields.Z_TAGS + dicomfields.X_Z_TAGS | ||
|
|
||
|
|
||
| def is_elem_empty(elem) -> bool: | ||
| if elem.VR == "SQ": | ||
| for x in elem.value: | ||
| for tt in empty_tags: | ||
| if tt in x and len(x[tt].value) > 0: | ||
| assert is_elem_empty( | ||
| x[tt] | ||
| ), f"({tt[0]:04X},{tt[1]:04x}):{x[tt].value} is not empty" | ||
| return True | ||
|
|
||
| return elem.value in empty_values | ||
|
|
||
|
|
||
| def test_empty_tags_are_emptied(orig_anon_dataset): | ||
| orig_ds, anon_ds = orig_anon_dataset | ||
|
|
||
| for tt in empty_tags: | ||
| if tt in orig_ds: | ||
| assert anon_ds[tt].value in empty_values | ||
| for tt in empty_tags: # sourcery skip: no-loop-in-tests | ||
| if ( | ||
| tt in orig_ds and len(orig_ds[tt].value) > 0 | ||
| ): # sourcery skip: no-conditionals-in-tests | ||
| assert is_elem_empty( | ||
| anon_ds[tt] | ||
| ), f"({tt[0]:04X},{tt[1]:04x}):{anon_ds[tt].value} is not empty" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.