You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by zh...@apache.org on 2022/12/02 02:11:26 UTC

[dolphinscheduler-sdk-python] branch main updated: [impv] Do not warnings in dev version (#33)

This is an automated email from the ASF dual-hosted git repository.

zhongjiajie pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler-sdk-python.git


The following commit(s) were added to refs/heads/main by this push:
     new 533a06f  [impv] Do not warnings in dev version (#33)
533a06f is described below

commit 533a06f519cdfc0eb1cf9766186ad4dd21b0744c
Author: Jay Chung <zh...@gmail.com>
AuthorDate: Fri Dec 2 10:11:21 2022 +0800

    [impv] Do not warnings in dev version (#33)
---
 src/pydolphinscheduler/java_gateway.py |  9 ++++++---
 tests/integration/test_java_gateway.py | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/src/pydolphinscheduler/java_gateway.py b/src/pydolphinscheduler/java_gateway.py
index b96ce9c..9ec039a 100644
--- a/src/pydolphinscheduler/java_gateway.py
+++ b/src/pydolphinscheduler/java_gateway.py
@@ -18,6 +18,7 @@
 """Module java gateway, contain gateway behavior."""
 
 import contextlib
+import warnings
 from logging import getLogger
 from typing import Any, Optional
 
@@ -70,12 +71,14 @@ class GatewayEntryPoint:
             # 1. Java gateway version is too old: doesn't have method 'getGatewayVersion()'
             # 2. Error connecting to Java gateway
             gateway_version = self.get_gateway_version()
-        if gateway_version != __version__:
-            logger.warning(
+        if not __version__.endswith("dev") and gateway_version != __version__:
+            warnings.warn(
                 f"Using unmatched version of pydolphinscheduler (version {__version__}) "
                 f"and Java gateway (version {gateway_version}) may cause errors. "
                 "We strongly recommend you to find the matched version "
-                "(check: https://pypi.org/project/apache-dolphinscheduler)"
+                "(check: https://pypi.org/project/apache-dolphinscheduler)",
+                UserWarning,
+                stacklevel=2,
             )
 
     @property
diff --git a/tests/integration/test_java_gateway.py b/tests/integration/test_java_gateway.py
index bc16e50..4545546 100644
--- a/tests/integration/test_java_gateway.py
+++ b/tests/integration/test_java_gateway.py
@@ -16,9 +16,14 @@
 # under the License.
 
 """Test pydolphinscheduler java gateway."""
+import importlib
+import warnings
+from unittest.mock import PropertyMock, patch
+
 import pytest
 from py4j.java_gateway import GatewayParameters, JavaGateway, java_import
 
+from pydolphinscheduler import java_gateway
 from tests.testing.constants import TOKEN
 
 gateway_parameters = GatewayParameters(auth_token=TOKEN)
@@ -58,3 +63,30 @@ def test_python_client_java_import_package():
     # test if jvm view have some common utils
     for util in ("FileUtils", "OSUtils", "DateUtils"):
         assert hasattr(gateway.jvm, util)
+
+
+@pytest.mark.parametrize(
+    "version, is_warning",
+    [
+        ("dev", False),
+        ("1.0.0-dev", False),
+        ("1.0.0", True),
+    ],
+)
+@patch("pydolphinscheduler.__version__", new_callable=PropertyMock)
+def test_gateway_entry_point_version_warning(
+    mock_version, version: str, is_warning: bool
+):
+    """Test whether gateway entry point will raise version warning or not."""
+    mock_version.return_value = version
+    mock_version.endswith.return_value = version.endswith("dev")
+
+    importlib.reload(java_gateway)
+    with warnings.catch_warnings(record=True) as w:
+        _ = java_gateway.GatewayEntryPoint()
+        if is_warning:
+            assert len(w) == 1
+            assert issubclass(w[-1].category, UserWarning)
+            assert "Using unmatched version of pydolphinscheduler" in str(w[-1].message)
+        else:
+            assert len(w) == 0