You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/09/18 00:36:47 UTC

[GitHub] [beam] ihji commented on a change in pull request #15484: [BEAM-12769] Python support for directly using Java transforms using constructor and builder methods

ihji commented on a change in pull request #15484:
URL: https://github.com/apache/beam/pull/15484#discussion_r711410111



##########
File path: sdks/python/apache_beam/transforms/external_test.py
##########
@@ -406,6 +410,88 @@ class DataclassTransform(beam.ExternalTransform):
     return get_payload(DataclassTransform(**values))
 
 
+class JavaClassLookupPayloadBuilderTest(unittest.TestCase):

Review comment:
       Do we also need a test for setting `with_constructor_method` twice? or setting `with_constructor_method` after `with_constructor`?

##########
File path: sdks/python/apache_beam/transforms/external_test.py
##########
@@ -406,6 +410,88 @@ class DataclassTransform(beam.ExternalTransform):
     return get_payload(DataclassTransform(**values))
 
 
+class JavaClassLookupPayloadBuilderTest(unittest.TestCase):
+  def _verify_row(self, schema, row_payload, expected_values):
+    row = RowCoder(schema).decode(row_payload)
+
+    for attr_name, expected_value in expected_values.items():
+      self.assertTrue(hasattr(row, attr_name))
+      value = getattr(row, attr_name)
+      self.assertEqual(expected_value, value)
+
+  def test_build_payload_with_constructor(self):
+    payload_builder = JavaClassLookupPayloadBuilder('dummy_class_name')
+
+    payload_builder.with_constructor('abc', 123, str_field='def', int_field=456)
+    payload_bytes = payload_builder.payload()
+    payload_from_bytes = proto_utils.parse_Bytes(
+        payload_bytes, JavaClassLookupPayload)
+    self.assertTrue(isinstance(payload_from_bytes, JavaClassLookupPayload))

Review comment:
       Also check `constructor_method` field is empty?




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

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org