MCPcopy Create free account
hub / github.com/FastLED/FastLED / detect_test_file_changes

Function detect_test_file_changes

ci/meson/meson_setup_phases.py:388–505  ·  view source on GitHub ↗

Return True when discovered test files differ from the cached list.

(
    source_dir: Path, build_dir: Path, max_tests_dir_mtime: float
)

Source from the content-addressed store, hash-verified

386
387
388def detect_test_file_changes(
389 source_dir: Path, build_dir: Path, max_tests_dir_mtime: float
390) -> bool:
391 """Return True when discovered test files differ from the cached list."""
392 test_list_cache_path = build_dir / "test_list_cache.txt"
393 skip_test_discovery = False
394 if test_list_cache_path.exists():
395 try:
396 tlc_mtime = test_list_cache_path.stat().st_mtime
397 if max_tests_dir_mtime <= tlc_mtime:
398 skip_test_discovery = True
399 except OSError:
400 pass
401
402 if skip_test_discovery:
403 return False
404
405 try:
406 import importlib.util
407
408 tests_py_path = source_dir / "tests"
409
410 spec_dt = importlib.util.spec_from_file_location(
411 "discover_tests", tests_py_path / "discover_tests.py"
412 )
413 assert spec_dt is not None and spec_dt.loader is not None
414 mod_dt = importlib.util.module_from_spec(spec_dt)
415 spec_dt.loader.exec_module(mod_dt)
416 discover_test_files = mod_dt.discover_test_files
417
418 spec_tc = importlib.util.spec_from_file_location(
419 "test_config", tests_py_path / "test_config.py"
420 )
421 assert spec_tc is not None and spec_tc.loader is not None
422 mod_tc = importlib.util.module_from_spec(spec_tc)
423 spec_tc.loader.exec_module(mod_tc)
424 EXCLUDED_TEST_FILES = mod_tc.EXCLUDED_TEST_FILES
425 EXCLUDED_TEST_DIRS = mod_tc.EXCLUDED_TEST_DIRS
426
427 tests_dir = source_dir / "tests"
428 current_test_files: list[str] = sorted(
429 discover_test_files(tests_dir, EXCLUDED_TEST_FILES, EXCLUDED_TEST_DIRS)
430 )
431
432 test_list_cache = build_dir / "test_list_cache.txt"
433 cached_test_files: list[str] = []
434 try:
435 with open(test_list_cache, "r") as f:
436 cached_test_files = [
437 line.strip()
438 for line in f
439 if line.strip() and not line.startswith("#")
440 ]
441 except FileNotFoundError:
442 cached_test_files = []
443 except (IOError, OSError) as e:
444 _ts_print(f"[MESON] Warning: Could not read test cache: {e}")
445 cached_test_files = []

Callers 1

setup_meson_buildFunction · 0.90

Calls 6

print_warningFunction · 0.90
discover_test_filesFunction · 0.85
unlinkMethod · 0.80
setClass · 0.50
writeMethod · 0.45

Tested by

no test coverage detected