Skip to content

Commit 533a06f

Browse files
authored
[impv] Do not warnings in dev version (#33)
1 parent baf6402 commit 533a06f

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

src/pydolphinscheduler/java_gateway.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"""Module java gateway, contain gateway behavior."""
1919

2020
import contextlib
21+
import warnings
2122
from logging import getLogger
2223
from typing import Any, Optional
2324

@@ -70,12 +71,14 @@ def __init__(
7071
# 1. Java gateway version is too old: doesn't have method 'getGatewayVersion()'
7172
# 2. Error connecting to Java gateway
7273
gateway_version = self.get_gateway_version()
73-
if gateway_version != __version__:
74-
logger.warning(
74+
if not __version__.endswith("dev") and gateway_version != __version__:
75+
warnings.warn(
7576
f"Using unmatched version of pydolphinscheduler (version {__version__}) "
7677
f"and Java gateway (version {gateway_version}) may cause errors. "
7778
"We strongly recommend you to find the matched version "
78-
"(check: https://pypi.org/project/apache-dolphinscheduler)"
79+
"(check: https://pypi.org/project/apache-dolphinscheduler)",
80+
UserWarning,
81+
stacklevel=2,
7982
)
8083

8184
@property

tests/integration/test_java_gateway.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@
1616
# under the License.
1717

1818
"""Test pydolphinscheduler java gateway."""
19+
import importlib
20+
import warnings
21+
from unittest.mock import PropertyMock, patch
22+
1923
import pytest
2024
from py4j.java_gateway import GatewayParameters, JavaGateway, java_import
2125

26+
from pydolphinscheduler import java_gateway
2227
from tests.testing.constants import TOKEN
2328

2429
gateway_parameters = GatewayParameters(auth_token=TOKEN)
@@ -58,3 +63,30 @@ def test_python_client_java_import_package():
5863
# test if jvm view have some common utils
5964
for util in ("FileUtils", "OSUtils", "DateUtils"):
6065
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

Comments
 (0)