Skip to content

Commit

Permalink
[DLMED] fix windows test
Browse files Browse the repository at this point in the history
Signed-off-by: Nic Ma <[email protected]>
  • Loading branch information
Nic-Ma committed Dec 21, 2021
1 parent 1a9bb2d commit b925f27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
19 changes: 9 additions & 10 deletions monai/apps/mmars/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,17 @@ def __init__(self, pkgs: Sequence[str], modules: Sequence[str]):
def _create_classes_table(self):
class_table = {}
for pkg in self.pkgs:
package = __import__(pkg)
package = importlib.import_module(pkg)

for _, modname, _ in pkgutil.walk_packages(path=package.__path__, prefix=package.__name__ + "."):
if modname.startswith(pkg):
if any(name in modname for name in self.modules):
try:
module = importlib.import_module(modname)
for name, obj in inspect.getmembers(module):
if inspect.isclass(obj) and obj.__module__ == modname:
class_table[name] = modname
except ModuleNotFoundError:
pass
if any(name in modname for name in self.modules):
try:
module = importlib.import_module(modname)
for name, obj in inspect.getmembers(module):
if inspect.isclass(obj) and obj.__module__ == modname:
class_table[name] = modname
except ModuleNotFoundError:
pass
return class_table

def get_module_name(self, class_name):
Expand Down
15 changes: 3 additions & 12 deletions tests/test_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from monai.apps import ConfigParser
from monai.transforms import LoadImaged
from tests.utils import skip_if_windows

TEST_CASE_1 = [
dict(pkgs=["monai"], modules=["transforms"]),
Expand Down Expand Up @@ -44,26 +43,18 @@


class TestConfigParser(unittest.TestCase):
@parameterized.expand([TEST_CASE_1, TEST_CASE_2, TEST_CASE_3])
@parameterized.expand([TEST_CASE_1, TEST_CASE_2, TEST_CASE_3, TEST_CASE_4])
def test_type(self, input_param, test_input, output_type):
configer = ConfigParser(**input_param)
result = configer.build_component(test_input)
if result is not None:
self.assertTrue(isinstance(result, output_type))
self.assertEqual(result.keys[0], "image")
if isinstance(result, LoadImaged):
self.assertEqual(result.keys[0], "image")
else:
# test `disabled` works fine
self.assertEqual(result, output_type)


@skip_if_windows
class TestConfigParserExternal(unittest.TestCase):
@parameterized.expand([TEST_CASE_4])
def test_type(self, input_param, test_input, output_type):
configer = ConfigParser(**input_param)
result = configer.build_component(test_input)
self.assertTrue(isinstance(result, output_type))


if __name__ == "__main__":
unittest.main()

0 comments on commit b925f27

Please sign in to comment.