You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "dstandish (via GitHub)" <gi...@apache.org> on 2023/02/28 01:16:17 UTC

[GitHub] [airflow] dstandish commented on a diff in pull request #29793: Support setup and teardown taskflow taskgroups

dstandish commented on code in PR #29793:
URL: https://github.com/apache/airflow/pull/29793#discussion_r1119477350


##########
tests/serialization/test_dag_serialization.py:
##########
@@ -1366,6 +1366,88 @@ def _check_taskgroup_children(
             ["group1.group2.teardown2"],
         )
 
+    def test_task_group_setup_teardown_taskgroups(self):
+        """
+        Test TaskGroup setup and teardown taskgroup serialization/deserialization.
+        """
+        from airflow.decorators import setup, task_group, teardown
+        from airflow.operators.empty import EmptyOperator
+
+        execution_date = datetime(2020, 1, 1)
+        with DAG("test_task_group_setup_teardown_task_groups", start_date=execution_date) as dag:
+
+            @setup
+            @task_group
+            def setup():
+                @task_group
+                def sub_setup():
+                    EmptyOperator(task_id="setup2")
+
+                EmptyOperator(task_id="setup1")
+                sub_setup()
+
+            @teardown
+            @task_group
+            def teardown():
+                EmptyOperator(task_id="teardown1")
+
+            setup()
+            EmptyOperator(task_id="sometask")
+            teardown()
+
+        dag_dict = SerializedDAG.to_dict(dag)
+        SerializedDAG.validate_schema(dag_dict)
+        json_dag = SerializedDAG.from_json(SerializedDAG.to_json(dag))
+        self.validate_deserialized_dag(json_dag, dag)
+
+        serialized_dag = SerializedDAG.deserialize_dag(SerializedDAG.serialize_dag(dag))
+
+        def _check_taskgroup_children(
+            se_task_group, dag_task_group, expected_setup, expected_children, expected_teardown
+        ):
+            assert list(se_task_group.children.keys()) == expected_children
+            assert list(dag_task_group.children.keys()) == expected_children
+
+            assert list(se_task_group.setup_children.keys()) == expected_setup
+            assert list(dag_task_group.setup_children.keys()) == expected_setup
+
+            assert list(se_task_group.teardown_children.keys()) == expected_teardown
+            assert list(dag_task_group.teardown_children.keys()) == expected_teardown

Review Comment:
   ```suggestion
               for group in (se_task_group, dag_task_group):
                   assert list(group.children.keys()) == expected_children
                   assert list(group.setup_children.keys()) == expected_setup
                   assert list(group.teardown_children.keys()) == expected_teardown
   ```



-- 
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: commits-unsubscribe@airflow.apache.org

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