MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / test_transform_api

Method test_transform_api

tests/integration/test_module_list.py:41–72  ·  view source on GitHub ↗

monai subclasses of MapTransforms must have alias names ending with 'd', 'D', 'Dict

(self)

Source from the content-addressed store, hash-verified

39 self.assertEqual(sorted(monai.__all__), sorted(mod))
40
41 def test_transform_api(self):
42 """monai subclasses of MapTransforms must have alias names ending with 'd', 'D', 'Dict'"""
43 to_exclude = {"MapTransform"} # except for these transforms
44 to_exclude_docs = {"Decollate", "Ensemble", "Invert", "SaveClassification", "RandTorchVision", "RandCrop"}
45 to_exclude_docs.update({"DeleteItems", "SelectItems", "FlattenSubKeys", "CopyItems", "ConcatItems"})
46 to_exclude_docs.update({"ToMetaTensor", "FromMetaTensor"})
47 xforms = {
48 name: obj
49 for name, obj in monai.transforms.__dict__.items()
50 if inspect.isclass(obj) and issubclass(obj, monai.transforms.MapTransform)
51 }
52 names = sorted(x for x in xforms if x not in to_exclude)
53 remained = set(names)
54 doc_file = os.path.join(pathlib.Path(__file__).parent.parent, "docs", "source", "transforms.rst")
55 contents = pathlib.Path(doc_file).read_text() if os.path.exists(doc_file) else None
56 for n in names:
57 if not n.endswith("d"):
58 continue
59 with self.subTest(n=n):
60 basename = n[:-1] # Transformd basename is Transform
61
62 # remove aliases to check, do this before the assert below so that a failed assert does skip this
63 for postfix in ("D", "d", "Dict"):
64 remained.remove(f"{basename}{postfix}")
65
66 for docname in (f"{basename}", f"{basename}d"):
67 if docname in to_exclude_docs:
68 continue
69 if (contents is not None) and f"`{docname}`" not in f"{contents}":
70 self.assertTrue(False, f"please add `{docname}` to docs/source/transforms.rst")
71
72 self.assertFalse(remained)
73
74
75if __name__ == "__main__":

Callers

nothing calls this directly

Calls 2

removeMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected