dianfu commented on a change in pull request #8439: [FLINK-12485][python] Add 
completeness test for Table and TableEnviro…
URL: https://github.com/apache/flink/pull/8439#discussion_r284065527
 
 

 ##########
 File path: flink-python/pyflink/testing/test_case_utils.py
 ##########
 @@ -90,3 +92,82 @@ def setUp(self):
         super(PyFlinkBatchTableTestCase, self).setUp()
         self.t_config = 
TableConfig.Builder().as_batch_execution().set_parallelism(4).build()
         self.t_env = TableEnvironment.get_table_environment(self.t_config)
+
+
+class PythonAPICompletenessTestCase(unittest.TestCase):
+    """
+    Base class for python api completeness tests, i.e.,
+    python api should be aligned with the Java API as much as possible.
+    """
+
+    @classmethod
+    def get_python_class_methods(cls, python_class):
+        return {cls.snake_to_camel(cls.java_method_name(method_name))
+                for method_name in dir(python_class) if not 
method_name.startswith('_')}
+
+    @staticmethod
+    def snake_to_camel(method_name):
+        output = ''.join(x.capitalize() or '_' for x in method_name.split('_'))
+        return output[0].lower() + output[1:]
+
+    @staticmethod
+    def get_java_class_method(java_class):
+        gateway = get_gateway()
+        s = set()
+        method_arr = gateway.jvm.Class.forName(java_class).getDeclaredMethods()
+        for i in range(0, len(method_arr)):
+            s.add(method_arr[i].getName())
+        return s
+
+    @classmethod
+    def check_methods(cls):
+        java_methods = 
PythonAPICompletenessTestCase.get_java_class_method(cls.java_class())
+        python_methods = cls.get_python_class_methods(cls.python_class())
+        missing_methods = java_methods - python_methods - cls.exclude_methods()
+        if len(missing_methods) > 0:
+            print(missing_methods)
+            print('The Exception should be raised after FLINK-12407 is 
merged.')
+            # raise Exception('Methods: %s in Java class %s have not been 
added in Python class %s.'
+            #                % (missing_methods, java_class, python_class))
 
 Review comment:
   cls.java_class(), cls.python_class()

----------------------------------------------------------------
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