|
22 | 22 | "test_sea_metadata",
|
23 | 23 | ]
|
24 | 24 |
|
| 25 | + |
25 | 26 | def load_test_function(module_name: str) -> Callable:
|
26 | 27 | """Load a test function from a module."""
|
27 | 28 | module_path = os.path.join(
|
28 |
| - os.path.dirname(os.path.abspath(__file__)), |
29 |
| - "tests", |
30 |
| - f"{module_name}.py" |
| 29 | + os.path.dirname(os.path.abspath(__file__)), "tests", f"{module_name}.py" |
31 | 30 | )
|
32 |
| - |
| 31 | + |
33 | 32 | spec = importlib.util.spec_from_file_location(module_name, module_path)
|
34 | 33 | module = importlib.util.module_from_spec(spec)
|
35 | 34 | spec.loader.exec_module(module)
|
36 |
| - |
| 35 | + |
37 | 36 | # Get the main test function (assuming it starts with "test_")
|
38 | 37 | for name in dir(module):
|
39 | 38 | if name.startswith("test_") and callable(getattr(module, name)):
|
40 | 39 | # For sync and async query modules, we want the main function that runs both tests
|
41 | 40 | if name == f"test_sea_{module_name.replace('test_sea_', '')}_exec":
|
42 | 41 | return getattr(module, name)
|
43 |
| - |
| 42 | + |
44 | 43 | # Fallback to the first test function found
|
45 | 44 | for name in dir(module):
|
46 | 45 | if name.startswith("test_") and callable(getattr(module, name)):
|
47 | 46 | return getattr(module, name)
|
48 |
| - |
| 47 | + |
49 | 48 | raise ValueError(f"No test function found in module {module_name}")
|
50 | 49 |
|
| 50 | + |
51 | 51 | def run_tests() -> List[Tuple[str, bool]]:
|
52 | 52 | """Run all tests and return results."""
|
53 | 53 | results = []
|
54 |
| - |
| 54 | + |
55 | 55 | for module_name in TEST_MODULES:
|
56 | 56 | try:
|
57 | 57 | test_func = load_test_function(module_name)
|
58 | 58 | logger.info(f"\n{'=' * 50}")
|
59 | 59 | logger.info(f"Running test: {module_name}")
|
60 | 60 | logger.info(f"{'-' * 50}")
|
61 |
| - |
| 61 | + |
62 | 62 | success = test_func()
|
63 | 63 | results.append((module_name, success))
|
64 |
| - |
| 64 | + |
65 | 65 | status = "✅ PASSED" if success else "❌ FAILED"
|
66 | 66 | logger.info(f"Test {module_name}: {status}")
|
67 |
| - |
| 67 | + |
68 | 68 | except Exception as e:
|
69 | 69 | logger.error(f"Error loading or running test {module_name}: {str(e)}")
|
70 | 70 | import traceback
|
| 71 | + |
71 | 72 | logger.error(traceback.format_exc())
|
72 | 73 | results.append((module_name, False))
|
73 |
| - |
| 74 | + |
74 | 75 | return results
|
75 | 76 |
|
| 77 | + |
76 | 78 | def print_summary(results: List[Tuple[str, bool]]) -> None:
|
77 | 79 | """Print a summary of test results."""
|
78 | 80 | logger.info(f"\n{'=' * 50}")
|
79 | 81 | logger.info("TEST SUMMARY")
|
80 | 82 | logger.info(f"{'-' * 50}")
|
81 |
| - |
| 83 | + |
82 | 84 | passed = sum(1 for _, success in results if success)
|
83 | 85 | total = len(results)
|
84 |
| - |
| 86 | + |
85 | 87 | for module_name, success in results:
|
86 | 88 | status = "✅ PASSED" if success else "❌ FAILED"
|
87 | 89 | logger.info(f"{status} - {module_name}")
|
88 |
| - |
| 90 | + |
89 | 91 | logger.info(f"{'-' * 50}")
|
90 | 92 | logger.info(f"Total: {total} | Passed: {passed} | Failed: {total - passed}")
|
91 | 93 | logger.info(f"{'=' * 50}")
|
92 | 94 |
|
| 95 | + |
93 | 96 | if __name__ == "__main__":
|
94 | 97 | # Check if required environment variables are set
|
95 |
| - required_vars = ["DATABRICKS_SERVER_HOSTNAME", "DATABRICKS_HTTP_PATH", "DATABRICKS_TOKEN"] |
| 98 | + required_vars = [ |
| 99 | + "DATABRICKS_SERVER_HOSTNAME", |
| 100 | + "DATABRICKS_HTTP_PATH", |
| 101 | + "DATABRICKS_TOKEN", |
| 102 | + ] |
96 | 103 | missing_vars = [var for var in required_vars if not os.environ.get(var)]
|
97 |
| - |
| 104 | + |
98 | 105 | if missing_vars:
|
99 |
| - logger.error(f"Missing required environment variables: {', '.join(missing_vars)}") |
| 106 | + logger.error( |
| 107 | + f"Missing required environment variables: {', '.join(missing_vars)}" |
| 108 | + ) |
100 | 109 | logger.error("Please set these variables before running the tests.")
|
101 | 110 | sys.exit(1)
|
102 |
| - |
| 111 | + |
103 | 112 | # Run all tests
|
104 | 113 | results = run_tests()
|
105 |
| - |
| 114 | + |
106 | 115 | # Print summary
|
107 | 116 | print_summary(results)
|
108 |
| - |
| 117 | + |
109 | 118 | # Exit with appropriate status code
|
110 | 119 | all_passed = all(success for _, success in results)
|
111 | 120 | sys.exit(0 if all_passed else 1)
|
0 commit comments