|
16 | 16 | # under the License. |
17 | 17 |
|
18 | 18 | """Test pydolphinscheduler java gateway.""" |
| 19 | +import importlib |
| 20 | +import warnings |
| 21 | +from unittest.mock import PropertyMock, patch |
| 22 | + |
19 | 23 | import pytest |
20 | 24 | from py4j.java_gateway import GatewayParameters, JavaGateway, java_import |
21 | 25 |
|
| 26 | +from pydolphinscheduler import java_gateway |
22 | 27 | from tests.testing.constants import TOKEN |
23 | 28 |
|
24 | 29 | gateway_parameters = GatewayParameters(auth_token=TOKEN) |
@@ -58,3 +63,30 @@ def test_python_client_java_import_package(): |
58 | 63 | # test if jvm view have some common utils |
59 | 64 | for util in ("FileUtils", "OSUtils", "DateUtils"): |
60 | 65 | assert hasattr(gateway.jvm, util) |
| 66 | + |
| 67 | + |
| 68 | +@pytest.mark.parametrize( |
| 69 | + "version, is_warning", |
| 70 | + [ |
| 71 | + ("dev", False), |
| 72 | + ("1.0.0-dev", False), |
| 73 | + ("1.0.0", True), |
| 74 | + ], |
| 75 | +) |
| 76 | +@patch("pydolphinscheduler.__version__", new_callable=PropertyMock) |
| 77 | +def test_gateway_entry_point_version_warning( |
| 78 | + mock_version, version: str, is_warning: bool |
| 79 | +): |
| 80 | + """Test whether gateway entry point will raise version warning or not.""" |
| 81 | + mock_version.return_value = version |
| 82 | + mock_version.endswith.return_value = version.endswith("dev") |
| 83 | + |
| 84 | + importlib.reload(java_gateway) |
| 85 | + with warnings.catch_warnings(record=True) as w: |
| 86 | + _ = java_gateway.GatewayEntryPoint() |
| 87 | + if is_warning: |
| 88 | + assert len(w) == 1 |
| 89 | + assert issubclass(w[-1].category, UserWarning) |
| 90 | + assert "Using unmatched version of pydolphinscheduler" in str(w[-1].message) |
| 91 | + else: |
| 92 | + assert len(w) == 0 |
0 commit comments