Skip to content

Commit bf82225

Browse files
committed
Start fixing path issues after moving files
1 parent dda65c4 commit bf82225

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

tests/bundle/test_bundle_workflow.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,20 @@
3030
from monai.transforms import Compose, LoadImage, LoadImaged, SaveImaged
3131
from tests.nonconfig_workflow import NonConfigWorkflow, PythonicWorkflowImpl
3232

33-
TEST_CASE_1 = [os.path.join(os.path.dirname(__file__), "testing_data", "inference.json")]
33+
MODULE_PATH = os.path.dirname(os.path.abspath(__file__).parents[2])
3434

35-
TEST_CASE_2 = [os.path.join(os.path.dirname(__file__), "testing_data", "inference.yaml")]
35+
TEST_CASE_1 = [os.path.join(MODULE_PATH, "tests", "testing_data", "inference.json")]
3636

37-
TEST_CASE_3 = [os.path.join(os.path.dirname(__file__), "testing_data", "config_fl_train.json")]
37+
TEST_CASE_2 = [os.path.join(MODULE_PATH, "tests", "testing_data", "inference.yaml")]
3838

39-
TEST_CASE_4 = [os.path.join(os.path.dirname(__file__), "testing_data", "responsive_inference.json")]
39+
TEST_CASE_3 = [os.path.join(MODULE_PATH, "tests", "testing_data", "config_fl_train.json")]
40+
41+
TEST_CASE_4 = [os.path.join(MODULE_PATH, "tests", "testing_data", "responsive_inference.json")]
4042

4143
TEST_CASE_NON_CONFIG_WRONG_LOG = [None, "logging.conf", "Cannot find the logging config file: logging.conf."]
4244

4345

4446
class TestBundleWorkflow(unittest.TestCase):
45-
4647
def setUp(self):
4748
self.data_dir = tempfile.mkdtemp()
4849
self.expected_shape = (128, 128, 128)

tests/fl/client/monai_algo/test_fl_monai_algo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import unittest
1818
from copy import deepcopy
1919
from os.path import join as pathjoin
20+
from pathlib import Path
2021

2122
from parameterized import parameterized
2223

@@ -28,7 +29,7 @@
2829
from monai.utils import path_to_uri
2930
from tests.utils import SkipIfNoModule
3031

31-
_root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__)))
32+
_root_dir = Path(__file__).resolve().parents[3]
3233
_data_dir = os.path.join(_root_dir, "testing_data")
3334
_logging_file = pathjoin(_data_dir, "logging.conf")
3435

@@ -181,7 +182,6 @@
181182
@SkipIfNoModule("ignite")
182183
@SkipIfNoModule("mlflow")
183184
class TestFLMonaiAlgo(unittest.TestCase):
184-
185185
@parameterized.expand([TEST_TRAIN_1, TEST_TRAIN_2, TEST_TRAIN_3, TEST_TRAIN_4])
186186
def test_train(self, input_params):
187187
# initialize algo

tests/fl/test_fl_monai_algo_stats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import os
1515
import unittest
16+
from pathlib import Path
1617

1718
from parameterized import parameterized
1819

@@ -22,7 +23,7 @@
2223
from monai.fl.utils.exchange_object import ExchangeObject
2324
from tests.utils import SkipIfNoModule
2425

25-
_root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__)))
26+
_root_dir = Path(__file__).resolve().parents[1]
2627
_data_dir = os.path.join(_root_dir, "testing_data")
2728
_logging_file = os.path.join(_data_dir, "logging.conf")
2829

@@ -64,7 +65,6 @@
6465

6566
@SkipIfNoModule("ignite")
6667
class TestFLMonaiAlgo(unittest.TestCase):
67-
6868
@parameterized.expand([TEST_GET_DATA_STATS_1, TEST_GET_DATA_STATS_2, TEST_GET_DATA_STATS_3])
6969
def test_get_data_stats(self, input_params):
7070
# initialize algo

tests/min_tests.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
from __future__ import annotations
1313

14-
import glob
1514
import os
1615
import sys
1716
import unittest
17+
from pathlib import Path
1818

1919

2020
def run_testsuit():
@@ -216,17 +216,20 @@ def run_testsuit():
216216
]
217217
assert sorted(exclude_cases) == sorted(set(exclude_cases)), f"Duplicated items in {exclude_cases}"
218218

219-
files = glob.glob(os.path.join(os.path.dirname(__file__), "test_*.py"))
219+
files = [f.relative_to(Path(__file__).parent.parent) for f in Path(__file__).parent.rglob("test_*.py")]
220+
files = [str(f).replace(os.sep, ".").replace(".py", "") for f in files]
220221

221222
cases = []
222-
for case in files:
223-
test_module = os.path.basename(case)[:-3]
224-
if test_module in exclude_cases:
225-
exclude_cases.remove(test_module)
226-
print(f"skipping tests.{test_module}.")
223+
for test_module in files:
224+
test_case = test_module.split(".")[-1]
225+
if test_case in exclude_cases:
226+
exclude_cases.remove(test_case)
227+
print(f"skipping {test_module}")
227228
else:
228-
cases.append(f"tests.{test_module}")
229-
assert not exclude_cases, f"items in exclude_cases not used: {exclude_cases}."
229+
print(f"adding {test_module}")
230+
cases.append(test_module)
231+
exclude_cases = [str(list(Path(__file__).parent.rglob(f"*{et}*"))[0]) for et in exclude_cases]
232+
assert not exclude_cases, f"items in exclude_cases not used:\n\t{'\n\t'.join(exclude_cases)}"
230233
test_suite = unittest.TestLoader().loadTestsFromNames(cases)
231234
return test_suite
232235

0 commit comments

Comments
 (0)