Project-MONAI / Project-MONAI/MONAI
Candidate Duplicate Test Cases For Cleanup
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.7k
- Forks
- 1.6k
- Avg merge
- 5d 1h
- Merged PRs (30d)
- 20
Description
[!TIP]
For best results, initiate chat on the files or code changes.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
python3 - <<'EOF'
import ast
import os
import sys
from pathlib import Path
def find_duplicates_in_list(elements):
seen = []
dupes = []
for i, el in enumerate(elements):
key = ast.dump(el)
for j, (prev_key, prev_idx) in enumerate(seen):
if key == prev_key:
dupes.append((prev_idx, i))
break
else:
seen.append((key, i))
return dupes
results = []
for path in Path("tests").rglob("*.py"):
try:
src = path.read_text(errors="replace")
tree = ast.parse(src, filename=str(path))
except SyntaxError:
continue
for node in ast.walk(tree):
if not isinstance(node, ast.Assign):
continue
for target in node.targets:
if not isinstance(target, ast.Name):
continue
name = target.id
if "TEST" not in name.upper() and "CASES" not in name.upper() and "PARAMS" not in name.upper():
continue
val = node.value
if not isinstance(val, ast.List):
continue
elems = val.elts
if len(elems) < 2:
continue
dupes = find_duplicates_in_list(elems)
if dupes:
results.append((str(path), name, dupes))
for fpath, varname, dupes in sorted(results):
for (i, j) in dupes:
print(f"{fpath} {varname} indices {i} and {j} are identical")
if not results:
print("No duplicates found.")
EOF
Length of output: 16409
@ericspod Here's the full list of files with byte-identical duplicate entries in their test case lists:
apps/
tests/apps/deepgrow/test_deepgrow_dataset.py—TEST_CASE_4,TEST_CASE_5tests/apps/detection/utils/test_detector_utils.py—TEST_CASE_3tests/apps/pathology/transforms/post/test_generate_succinct_contour.py—TEST_CASE_1tests/apps/pathology/transforms/post/test_generate_succinct_contourd.py—TEST_CASE_1
bundle/
tests/bundle/test_bundle_ckpt_export.py—TEST_CASE_1tests/bundle/test_bundle_trt_export.py—TEST_CASE_1,TEST_CASE_2
data/
tests/data/test_arraydataset.py—TEST_CASE_1/2/3,test_labelstests/data/test_lmdbdataset.py—TEST_CASE_3tests/data/test_nrrd_reader.py—TEST_CASE_1throughTEST_CASE_8(indices 0 and 2 identical in each)tests/data/test_persistentdataset.py—TEST_CASE_4/5/6/7tests/data/test_pil_reader.py—TEST_CASE_1throughTEST_CASE_6tests/data/utils/test_decollate.py—test_case
handlers/
tests/handlers/test_handler_checkpoint_saver.py—TEST_CASE_1throughTEST_CASE_8(many cross-index duplicates — likely worth a separate look; the list entries may be intentional combinations of primitives)tests/handlers/test_handler_hausdorff_distance.py—TEST_SAMPLE_2,TEST_SAMPLE_4tests/handlers/test_handler_surface_distance.py—TEST_SAMPLE_2,TEST_SAMPLE_4
inferers/
tests/inferers/test_patch_inferer.py— 9 differentTEST_CASE_*variables (indices 0 and 3 identical in each)
metrics/
tests/metrics/test_calibration_metric.py—TEST_VALUE_1B1C
networks/
tests/networks/blocks/test_mlp.py,test_se_blocks.py,test_selfattention.py—test_casetests/networks/layers/test_savitzky_golay_filter.py—TEST_CASE_1D_REP,TEST_CASE_SINGLE_VALUE_REPtests/networks/nets/test_ahnet.py— 5 casestests/networks/nets/test_autoencoder.py—TEST_CASE_0/1/2tests/networks/nets/test_autoencoderkl.py—CASES_ATTENTIONtests/networks/nets/test_cell_sam_wrapper.py,test_fullyconnectednet.py,test_spade_autoencoderkl.py,test_varautoencoder.py,test_vnet.py,test_voxelmorph.pytests/networks/test_save_state.py—TEST_CASE_6,TEST_CASE_10
transforms/
tests/transforms/test_border_pad.py,test_border_padd.pytests/transforms/test_center_spatial_crop.pytests/transforms/test_cucim_dict_transform.py,test_cucim_transform.py(and rand variants)tests/transforms/test_fill_holes.py,test_fill_holesd.py— 8 cases eachtests/transforms/test_load_image.py— 5 casestests/transforms/test_rand_torchio.py,test_rand_torchiod.py,test_torchio.py,test_torchiod.pytests/transforms/test_savitzky_golay_smooth.py,test_savitzky_golay_smoothd.pytests/transforms/test_spatial_padd.py
The test_handler_checkpoint_saver.py cases are likely combining shared primitive values intentionally (not pure parametrize duplicates), so worth manually verifying those. The rest look like straightforward cleanup candidates similar to this PR.
Originally posted by @coderabbitai[bot] in https://github.com/Project-MONAI/MONAI/issues/8896#issuecomment-4773223542
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the listed duplicate test-case definitions under tests/, especially tests/handlers/test_handler_checkpoint_saver.py where combinations may be intentional. Compare each reported pair in its surrounding test file, then run the affected tests after removing only confirmed duplicates. Done means redundant entries are cleaned up without losing distinct coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100