|
9 | 9 | to the kernel statement: the kernel/SEA transport controls chunk size; |
10 | 10 | - ``row_limit`` is threaded to the kernel statement's ``set_row_limit``. |
11 | 11 |
|
12 | | -No network and no Rust extension dependency: a fake kernel module is |
13 | | -installed before import (same approach as ``test_kernel_client.py``) and |
14 | | -the result-set tests drive ``KernelResultSet`` with a fake handle. |
| 12 | +No network and no Rust extension dependency: ``test_kernel_client.py``'s |
| 13 | +fake kernel module is installed before import, and the result-set tests |
| 14 | +drive ``KernelResultSet`` with a fake handle. |
15 | 15 | """ |
16 | 16 |
|
17 | 17 | from __future__ import annotations |
18 | 18 |
|
19 | | -import sys |
20 | | -import types |
21 | | -from typing import Optional |
22 | 19 | from unittest.mock import MagicMock |
23 | 20 |
|
24 | 21 | import pytest |
|
28 | 25 | pa = pytest.importorskip("pyarrow") |
29 | 26 |
|
30 | 27 |
|
31 | | -# Install the same session-global fake ``databricks_sql_kernel`` stub |
32 | | -# used by test_kernel_client.py (client.py imports the extension at |
33 | | -# module import time). ``setdefault`` keeps it idempotent when both |
34 | | -# files run in one pytest session. |
35 | | -_fake_kernel_module = types.ModuleType("databricks_sql_kernel") |
36 | | - |
37 | | - |
38 | | -class _FakeKernelError(Exception): |
39 | | - def __init__(self, code: str = "Unknown", message: str = "boom") -> None: |
40 | | - super().__init__(message) |
41 | | - self.code = code |
42 | | - self.message = message |
43 | | - self.sql_state = None |
44 | | - self.error_code = None |
45 | | - self.vendor_code = None |
46 | | - self.http_status = None |
47 | | - self.retryable = False |
48 | | - self.query_id = None |
49 | | - self.diagnostic_info: Optional[str] = None |
50 | | - self.display_message: Optional[str] = None |
51 | | - self.error_details_json: Optional[str] = None |
52 | | - |
53 | | - |
54 | | -_fake_kernel_module.KernelError = _FakeKernelError # type: ignore[attr-defined] |
55 | | -_fake_kernel_module.Session = MagicMock() # type: ignore[attr-defined] |
56 | | -sys.modules.setdefault("databricks_sql_kernel", _fake_kernel_module) |
| 28 | +# Reuse test_kernel_client.py's session-global fake |
| 29 | +# ``databricks_sql_kernel`` stub (client.py imports the extension at |
| 30 | +# module import time). Importing that module installs its stub, so both |
| 31 | +# files share one ``KernelError`` class in any collection order. |
| 32 | +import tests.unit.test_kernel_client as _shared_kernel_stub # noqa: E402 |
57 | 33 |
|
58 | 34 | from databricks.sql.auth.authenticators import AccessTokenAuthProvider |
59 | 35 | from databricks.sql.backend.kernel import client as kernel_client |
60 | 36 | from databricks.sql.backend.kernel.result_set import KernelResultSet |
61 | 37 | from databricks.sql.backend.types import CommandId |
62 | 38 |
|
| 39 | + |
| 40 | +def test_shares_kernel_stub_with_client_tests(): |
| 41 | + """client.py must bind the same fake ``KernelError`` that |
| 42 | + test_kernel_client.py raises, whichever file pytest imports first.""" |
| 43 | + assert kernel_client._kernel.KernelError is _shared_kernel_stub._FakeKernelError |
| 44 | + |
| 45 | + |
63 | 46 | # --------------------------------------------------------------------------- |
64 | 47 | # Helpers |
65 | 48 | # --------------------------------------------------------------------------- |
|
0 commit comments