|
1 | | -""" |
2 | | -Main script to run all SEA connector tests. |
3 | | -
|
4 | | -This script runs all the individual test modules and displays |
5 | | -a summary of test results with visual indicators. |
6 | | -""" |
7 | 1 | import os |
8 | 2 | import sys |
9 | 3 | import logging |
10 | | -import subprocess |
11 | | -from typing import List, Tuple |
| 4 | +from databricks.sql.client import Connection |
12 | 5 |
|
13 | 6 | logging.basicConfig(level=logging.DEBUG) |
14 | 7 | logger = logging.getLogger(__name__) |
15 | 8 |
|
16 | | -TEST_MODULES = [ |
17 | | - "test_sea_session", |
18 | | - "test_sea_sync_query", |
19 | | - "test_sea_async_query", |
20 | | - "test_sea_metadata", |
21 | | -] |
22 | | - |
23 | | - |
24 | | -def run_test_module(module_name: str) -> bool: |
25 | | - """Run a test module and return success status.""" |
26 | | - module_path = os.path.join( |
27 | | - os.path.dirname(os.path.abspath(__file__)), "tests", f"{module_name}.py" |
28 | | - ) |
29 | | - |
30 | | - # Simply run the module as a script - each module handles its own test execution |
31 | | - result = subprocess.run( |
32 | | - [sys.executable, module_path], capture_output=True, text=True |
33 | | - ) |
34 | | - |
35 | | - # Log the output from the test module |
36 | | - if result.stdout: |
37 | | - for line in result.stdout.strip().split("\n"): |
38 | | - logger.info(line) |
39 | | - |
40 | | - if result.stderr: |
41 | | - for line in result.stderr.strip().split("\n"): |
42 | | - logger.error(line) |
43 | | - |
44 | | - return result.returncode == 0 |
45 | | - |
46 | | - |
47 | | -def run_tests() -> List[Tuple[str, bool]]: |
48 | | - """Run all tests and return results.""" |
49 | | - results = [] |
50 | | - |
51 | | - for module_name in TEST_MODULES: |
52 | | - try: |
53 | | - logger.info(f"\n{'=' * 50}") |
54 | | - logger.info(f"Running test: {module_name}") |
55 | | - logger.info(f"{'-' * 50}") |
56 | | - |
57 | | - success = run_test_module(module_name) |
58 | | - results.append((module_name, success)) |
59 | | - |
60 | | - status = "✅ PASSED" if success else "❌ FAILED" |
61 | | - logger.info(f"Test {module_name}: {status}") |
62 | | - |
63 | | - except Exception as e: |
64 | | - logger.error(f"Error loading or running test {module_name}: {str(e)}") |
65 | | - import traceback |
66 | | - |
67 | | - logger.error(traceback.format_exc()) |
68 | | - results.append((module_name, False)) |
69 | | - |
70 | | - return results |
71 | | - |
72 | | - |
73 | | -def print_summary(results: List[Tuple[str, bool]]) -> None: |
74 | | - """Print a summary of test results.""" |
75 | | - logger.info(f"\n{'=' * 50}") |
76 | | - logger.info("TEST SUMMARY") |
77 | | - logger.info(f"{'-' * 50}") |
78 | | - |
79 | | - passed = sum(1 for _, success in results if success) |
80 | | - total = len(results) |
81 | | - |
82 | | - for module_name, success in results: |
83 | | - status = "✅ PASSED" if success else "❌ FAILED" |
84 | | - logger.info(f"{status} - {module_name}") |
85 | | - |
86 | | - logger.info(f"{'-' * 50}") |
87 | | - logger.info(f"Total: {total} | Passed: {passed} | Failed: {total - passed}") |
88 | | - logger.info(f"{'=' * 50}") |
| 9 | +def test_sea_session(): |
| 10 | + """ |
| 11 | + Test opening and closing a SEA session using the connector. |
| 12 | + |
| 13 | + This function connects to a Databricks SQL endpoint using the SEA backend, |
| 14 | + opens a session, and then closes it. |
| 15 | + |
| 16 | + Required environment variables: |
| 17 | + - DATABRICKS_SERVER_HOSTNAME: Databricks server hostname |
| 18 | + - DATABRICKS_HTTP_PATH: HTTP path for the SQL endpoint |
| 19 | + - DATABRICKS_TOKEN: Personal access token for authentication |
| 20 | + """ |
89 | 21 |
|
90 | 22 | server_hostname = os.environ.get("DATABRICKS_SERVER_HOSTNAME") |
91 | 23 | http_path = os.environ.get("DATABRICKS_HTTP_PATH") |
|
0 commit comments