|
35 | 35 | # Test Directories - all relative to project root dir |
36 | 36 | CODE_DIR = "libensemble" |
37 | 37 | LIBE_SRC_DIR = CODE_DIR |
38 | | -TESTING_DIR = os.path.join(CODE_DIR, "tests") |
| 38 | +TESTING_DIR = Path(CODE_DIR) / "tests" |
39 | 39 | UNIT_TEST_SUBDIRS = [ |
40 | 40 | "unit_tests", |
41 | 41 | "unit_tests_mpi_import", |
42 | 42 | "unit_tests_nompi", |
43 | 43 | "unit_tests_logger", |
44 | 44 | ] |
45 | | -UNIT_TEST_DIRS = [os.path.join(TESTING_DIR, subdir) for subdir in UNIT_TEST_SUBDIRS] |
46 | | -REG_TEST_SUBDIR = os.path.join(TESTING_DIR, "regression_tests") |
47 | | -FUNC_TEST_SUBDIR = os.path.join(TESTING_DIR, "functionality_tests") |
| 45 | +UNIT_TEST_DIRS = [TESTING_DIR / subdir for subdir in UNIT_TEST_SUBDIRS] |
| 46 | +REG_TEST_SUBDIR = TESTING_DIR / "regression_tests" |
| 47 | +FUNC_TEST_SUBDIR = TESTING_DIR / "functionality_tests" |
48 | 48 |
|
49 | 49 | # Coverage merge and report dir |
50 | 50 | COV_MERGE_DIR = TESTING_DIR |
@@ -132,12 +132,13 @@ def cleanup(root_dir): |
132 | 132 | ] |
133 | 133 | dirs_to_clean = UNIT_TEST_DIRS + [REG_TEST_SUBDIR, FUNC_TEST_SUBDIR] |
134 | 134 | for dir_path in dirs_to_clean: |
135 | | - full_path = os.path.join(root_dir, dir_path) |
136 | | - if "libensemble/tests/" not in full_path.replace("\\", "/"): |
137 | | - cprint(f"Safety check failed for {full_path}. Check directory", style="red") |
| 135 | + full_path = Path(root_dir) / dir_path |
| 136 | + full_path_str = str(full_path) |
| 137 | + if "libensemble/tests/" not in full_path_str.replace("\\", "/"): |
| 138 | + cprint(f"Safety check failed for {full_path_str}. Check directory", style="red") |
138 | 139 | sys.exit(2) |
139 | 140 | for pattern in patterns: |
140 | | - for file_path in glob.glob(os.path.join(full_path, pattern)): |
| 141 | + for file_path in glob.glob(str(full_path / pattern)): |
141 | 142 | try: |
142 | 143 | if os.path.isfile(file_path) or os.path.islink(file_path): |
143 | 144 | os.remove(file_path) |
@@ -199,8 +200,8 @@ def print_test_failed(test_num, test_script_name, comm, nprocs, duration): |
199 | 200 | def merge_coverage_reports(root_dir): |
200 | 201 | """Merge coverage data from multiple tests and generate a report.""" |
201 | 202 | print_heading("Generating coverage reports") |
202 | | - tests_dir = os.path.join(root_dir, "libensemble", "tests") |
203 | | - cov_files = glob.glob(os.path.join(tests_dir, "**", ".cov_*"), recursive=True) |
| 203 | + tests_dir = Path(root_dir) / "libensemble" / "tests" |
| 204 | + cov_files = glob.glob(str(tests_dir / "**" / ".cov_*"), recursive=True) |
204 | 205 |
|
205 | 206 | if cov_files: |
206 | 207 | try: |
@@ -262,11 +263,11 @@ def is_open_mpi(): |
262 | 263 | def build_forces(root_dir): |
263 | 264 | """Build forces.x using mpicc.""" |
264 | 265 | cprint("Building forces.x before running regression tests...", style="yellow", newline=True) |
265 | | - forces_app_dir = os.path.join(root_dir, "libensemble/tests/scaling_tests/forces/forces_app") |
| 266 | + forces_app_dir = Path(root_dir) / "libensemble/tests/scaling_tests/forces/forces_app" |
266 | 267 | subprocess.run(["mpicc", "-O3", "-o", "forces.x", "forces.c", "-lm"], cwd=forces_app_dir, check=True) |
267 | | - destination_dir = os.path.join(root_dir, "libensemble/tests/forces_app") |
| 268 | + destination_dir = Path(root_dir) / "libensemble/tests/forces_app" |
268 | 269 | os.makedirs(destination_dir, exist_ok=True) |
269 | | - shutil.copy(os.path.join(forces_app_dir, "forces.x"), destination_dir) |
| 270 | + shutil.copy(forces_app_dir / "forces.x", destination_dir) |
270 | 271 |
|
271 | 272 |
|
272 | 273 | def skip_test(directives, args, current_os): |
@@ -335,7 +336,7 @@ def run_unit_tests(root_dir, python_exec, args): |
335 | 336 | print_heading(f"Running unit tests (with pytest)") |
336 | 337 | for dir_path in UNIT_TEST_DIRS: |
337 | 338 | cprint(f"Entering unit test dir: {dir_path}", style="yellow", newline=True) |
338 | | - full_path = os.path.join(root_dir, dir_path) |
| 339 | + full_path = Path(root_dir) / dir_path |
339 | 340 | cov_rep = cov_report_type + ":cov_unit" |
340 | 341 | cmd = python_exec + ["-m", "pytest", "--color=yes", "--timeout=120", "--cov", "--cov-report", cov_rep] |
341 | 342 | if args.e: |
@@ -366,8 +367,8 @@ def run_regression_tests(root_dir, python_exec, args, current_os): |
366 | 367 | reg_test_list = REG_TEST_LIST |
367 | 368 | reg_test_files = [] |
368 | 369 | for dir_path in test_dirs: |
369 | | - full_path = os.path.join(root_dir, dir_path) |
370 | | - reg_test_files.extend(glob.glob(os.path.join(full_path, reg_test_list))) |
| 370 | + full_path = Path(root_dir) / dir_path |
| 371 | + reg_test_files.extend(glob.glob(str(full_path / reg_test_list))) |
371 | 372 |
|
372 | 373 | reg_test_files = sorted(reg_test_files) |
373 | 374 | reg_pass = 0 |
|
0 commit comments