-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathsea_connector_test.py
More file actions
122 lines (93 loc) · 3.45 KB
/
sea_connector_test.py
File metadata and controls
122 lines (93 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""
Main script to run all SEA connector tests.
This script runs all the individual test modules and displays
a summary of test results with visual indicators.
"""
import os
import sys
import logging
import subprocess
from typing import List, Tuple
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
TEST_MODULES = [
"test_sea_session",
"test_sea_sync_query",
"test_sea_async_query",
"test_sea_metadata",
"test_sea_multi_chunk",
]
def run_test_module(module_name: str) -> bool:
"""Run a test module and return success status."""
module_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "tests", f"{module_name}.py"
)
# Handle the multi-chunk test which is in the main directory
if module_name == "test_sea_multi_chunk":
module_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), f"{module_name}.py"
)
# Simply run the module as a script - each module handles its own test execution
result = subprocess.run(
[sys.executable, module_path], capture_output=True, text=True
)
# Log the output from the test module
if result.stdout:
for line in result.stdout.strip().split("\n"):
logger.info(line)
if result.stderr:
for line in result.stderr.strip().split("\n"):
logger.error(line)
return result.returncode == 0
def run_tests() -> List[Tuple[str, bool]]:
"""Run all tests and return results."""
results = []
for module_name in TEST_MODULES:
try:
logger.info(f"\n{'=' * 50}")
logger.info(f"Running test: {module_name}")
logger.info(f"{'-' * 50}")
success = run_test_module(module_name)
results.append((module_name, success))
status = "✅ PASSED" if success else "❌ FAILED"
logger.info(f"Test {module_name}: {status}")
except Exception as e:
logger.error(f"Error loading or running test {module_name}: {str(e)}")
import traceback
logger.error(traceback.format_exc())
results.append((module_name, False))
return results
def print_summary(results: List[Tuple[str, bool]]) -> None:
"""Print a summary of test results."""
logger.info(f"\n{'=' * 50}")
logger.info("TEST SUMMARY")
logger.info(f"{'-' * 50}")
passed = sum(1 for _, success in results if success)
total = len(results)
for module_name, success in results:
status = "✅ PASSED" if success else "❌ FAILED"
logger.info(f"{status} - {module_name}")
logger.info(f"{'-' * 50}")
logger.info(f"Total: {total} | Passed: {passed} | Failed: {total - passed}")
logger.info(f"{'=' * 50}")
if __name__ == "__main__":
# Check if required environment variables are set
required_vars = [
"DATABRICKS_SERVER_HOSTNAME",
"DATABRICKS_HTTP_PATH",
"DATABRICKS_TOKEN",
]
missing_vars = [var for var in required_vars if not os.environ.get(var)]
if missing_vars:
logger.error(
f"Missing required environment variables: {', '.join(missing_vars)}"
)
logger.error("Please set these variables before running the tests.")
sys.exit(1)
# Run all tests
results = run_tests()
# Print summary
print_summary(results)
# Exit with appropriate status code
all_passed = all(success for _, success in results)
sys.exit(0 if all_passed else 1)