turbaszek commented on a change in pull request #10587:
URL: https://github.com/apache/airflow/pull/10587#discussion_r506657305



##########
File path: tests/models/test_dag.py
##########
@@ -1754,3 +1757,98 @@ def test_count_number_queries(self, tasks_count):
                 state=State.RUNNING,
                 execution_date=TEST_DATE,
             )
+
+
+class TestDagDecorator:
+    DEFAULT_ARGS = {
+        "owner": "test",
+        "depends_on_past": True,
+        "start_date": timezone.utcnow(),
+        "retries": 1,
+        "retry_delay": timedelta(minutes=1),
+    }
+    DEFAULT_DATE = timezone.datetime(2016, 1, 1)
+    VALUE = 42
+
+    def setUp(self):
+        super().setUp()
+        self.operator = None
+
+    def tearDown(self):
+        super().tearDown()
+        clear_db_runs()
+
+    def test_set_dag_id(self):
+        @dag_decorator('test', default_args=self.DEFAULT_ARGS)
+        def noop_pipeline():
+            @task
+            def return_num(num):
+                return num
+
+            return_num(4)
+
+        assert noop_pipeline().dag_id, 'test'
+
+    def test_arg_not_set_fail(self):
+        @dag_decorator(default_args=self.DEFAULT_ARGS)
+        def noop_pipeline(value):
+            @task
+            def return_num(num):
+                return num
+
+            return_num(value)
+        with pytest.raises(TypeError):
+            noop_pipeline()
+
+    def test_dag_id_function_name(self):
+        @dag_decorator(default_args=self.DEFAULT_ARGS)
+        def noop_pipeline():
+            @task
+            def return_num(num):
+                return num
+
+            return_num(4)
+
+        assert noop_pipeline().dag_id, 'noop_pipeline'
+
+    def test_xcom_pass_to_op(self):
+        @dag_decorator(default_args=self.DEFAULT_ARGS)
+        def xcom_pass_to_op(value=self.VALUE):
+            @task
+            def return_num(num):
+                return num
+
+            xcom_arg = return_num(value)
+            self.operator = xcom_arg.operator
+
+        dag = xcom_pass_to_op()
+
+        dr = dag.create_dagrun(
+            run_id=DagRunType.MANUAL.value,
+            start_date=timezone.utcnow(),
+            execution_date=self.DEFAULT_DATE,
+            state=State.RUNNING
+        )
+
+        self.operator.run(start_date=self.DEFAULT_DATE, 
end_date=self.DEFAULT_DATE)
+        ti = dr.get_task_instances()[0]
+        assert ti.xcom_pull() == self.VALUE
+
+    @conf_vars({("core", "executor"): "DebugExecutor"})
+    def test_xcom_pass_to_op(self):
+        @dag_decorator(default_args=self.DEFAULT_ARGS)
+        def pipeline(some_param, other_param=self.VALUE):
+            @task
+            def some_task(param):
+                return param
+
+            @task
+            def another_task(param):
+                return param
+
+            some_task(some_param)
+            another_task(other_param)
+
+        d = pipeline(self.VALUE)
+
+        d.run()

Review comment:
       Should we add sanity test for `@dag` function with both `@task` 
decorated operator and a DummyOperator?




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


Reply via email to