derrickaw commented on code in PR #40916:
URL: https://github.com/apache/beam/pull/40916#discussion_r4469571910


##########
sdks/python/apache_beam/yaml/yaml_enrichment_test.py:
##########
@@ -47,30 +56,108 @@ def test_enrichment_with_bigquery(self):
         Row(label="item1", rank=0),
         Row(label="item2", rank=1),
     ]
-
-    handler = 'BigQuery'
     config = {
         "project": "apache-beam-testing",
         "table_name": "project.database.table",
         "row_restriction_template": "label='item1' or label='item2'",
-        "fields": ["label"]
+        "fields": ["label"],
     }
 
-    with beam.Pipeline() as p:
-      with mock.patch('apache_beam.yaml.yaml_enrichment.enrichment_transform',
-                      FakeEnrichmentTransform(enrichment_handler=handler,
-                                              handler_config=config)):
-        # Force a reload to respect our mock.
-        yaml_provider.standard_providers.cache_clear()
-        input_pcoll = p | 'CreateInput' >> beam.Create(input_data)
-        result = input_pcoll | YamlTransform(
-            f'''
-                    type: Enrichment
-                    config:
-                        enrichment_handler: {handler}
-                        handler_config: {config}
-                    ''')
-        assert_that(result, equal_to(input_data))
+    captured = {}
+
+    def make_handler(**kwargs):
+      captured['kwargs'] = kwargs
+      return _FakeHandler(**kwargs)
+
+    with (mock.patch.object(yaml_enrichment, 'Enrichment', _FakeEnrichment),
+          mock.patch.object(yaml_enrichment,
+                            'BigQueryEnrichmentHandler',
+                            side_effect=make_handler)):
+      with beam.Pipeline(options=_enrichment_options()) as p:
+        result = (
+            p
+            | 'CreateInput' >> beam.Create(input_data)
+            | YamlTransform(
+                f'''
+                type: Enrichment
+                config:
+                  enrichment_handler: BigQuery
+                  handler_config: {config}
+                '''))
+        assert_that(
+            result,
+            equal_to([
+                Row(label="item1", rank=0, enriched_timeout=30),
+                Row(label="item2", rank=1, enriched_timeout=30),
+            ]))
+    self.assertEqual(captured['kwargs'], config)
+
+  def test_enrichment_other_handlers_and_timeout(self):
+    for handler_name, attr_name in [
+        ('BigTable', 'BigTableEnrichmentHandler'),
+        ('VertexAIFeatureStore', 'VertexAIFeatureStoreEnrichmentHandler'),
+        ('FeastFeatureStore', 'FeastFeatureStoreEnrichmentHandler'),
+    ]:
+      with self.subTest(handler=handler_name):
+        with (mock.patch.object(yaml_enrichment, 'Enrichment', 
_FakeEnrichment),
+              mock.patch.object(yaml_enrichment, attr_name, _FakeHandler) as

Review Comment:
   done



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to