dianfu commented on a change in pull request #10430: [FLINK-14019][python][cli] 
Add command-line options for managing Python UDF environment and dependencies.
URL: https://github.com/apache/flink/pull/10430#discussion_r354685811
 
 

 ##########
 File path: flink-python/pyflink/common/tests/test_python_option.py
 ##########
 @@ -0,0 +1,130 @@
+################################################################################
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+# limitations under the License.
+################################################################################
+import json
+import os
+import tempfile
+
+from py4j.protocol import Py4JError
+from pyflink.util.utils import to_jarray
+
+from pyflink.common import Configuration
+from pyflink.java_gateway import launch_gateway
+
+from pyflink.common.dependency_manager import DependencyManager
+
+from pyflink.testing.test_case_utils import (PyFlinkTestCase, replace_uuid,
+                                             TestEnv, encode_to_base64,
+                                             create_empty_file)
+
+
+class PythonOptionTests(PyFlinkTestCase):
+
+    def setUp(self):
+        self.j_env = TestEnv()
+        self.config = Configuration()
+        self.dependency_manager = DependencyManager(self.config, self.j_env)
+
+    def test_python_options(self):
+        dm = DependencyManager
+
+        system_env = dict()
+        system_env[dm.PYFLINK_PY_FILES] = 
"/file1.py\nhdfs://file2.zip\nfile3.egg"
+        system_env[dm.PYFLINK_PY_REQUIREMENTS] = "a.txt\nb_dir"
+        system_env[dm.PYFLINK_PY_EXECUTABLE] = "/usr/local/bin/python"
+        system_env[dm.PYFLINK_PY_ARCHIVES] = 
"/py3.zip\nvenv\n/py3.zip\n\ndata.zip\ndata"
+
+        self.dependency_manager.load_from_env(system_env)
+
+        configs = self.config.to_dict()
+        python_files = replace_uuid(json.loads(configs[dm.PYTHON_FILES]))
+        python_requirements_file = 
replace_uuid(configs[dm.PYTHON_REQUIREMENTS_FILE])
+        python_requirements_cache = 
replace_uuid(configs[dm.PYTHON_REQUIREMENTS_CACHE])
+        python_archives = replace_uuid(json.loads(configs[dm.PYTHON_ARCHIVES]))
+        python_exec = configs[dm.PYTHON_EXEC]
+        registered_files = replace_uuid(self.j_env.to_dict())
+
+        self.assertEqual(
+            {"python_file_0_{uuid}": "file1.py",
+             "python_file_1_{uuid}": "file2.zip",
+             "python_file_2_{uuid}": "file3.egg"}, python_files)
+        self.assertEqual(
+            {"python_archive_3_{uuid}": "venv",
+             "python_archive_4_{uuid}": "py3.zip",
+             "python_archive_5_{uuid}": "data"}, python_archives)
+        self.assertEqual("python_requirements_file_6_{uuid}", 
python_requirements_file)
+        self.assertEqual("python_requirements_cache_7_{uuid}", 
python_requirements_cache)
+        self.assertEqual("/usr/local/bin/python", python_exec)
+        self.assertEqual(
+            {"python_file_0_{uuid}": "/file1.py",
+             "python_file_1_{uuid}": "hdfs://file2.zip",
+             "python_file_2_{uuid}": "file3.egg",
+             "python_archive_3_{uuid}": "/py3.zip",
+             "python_archive_4_{uuid}": "/py3.zip",
+             "python_archive_5_{uuid}": "data.zip",
+             "python_requirements_file_6_{uuid}": "a.txt",
+             "python_requirements_cache_7_{uuid}": "b_dir"}, registered_files)
+
+    def test_python_options_integrated(self):
+        tmp_dir = tempfile.mkdtemp(dir=self.tempdir)
 
 Review comment:
   tempdir could be used directly, there is no need to create it again, what do 
you think?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to