You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/01/31 21:03:18 UTC

[GitHub] [airflow] coopergillan commented on a change in pull request #7315: [AIRFLOW-6699] Parameterize weekday_sensor tests

coopergillan commented on a change in pull request #7315: [AIRFLOW-6699] Parameterize weekday_sensor tests
URL: https://github.com/apache/airflow/pull/7315#discussion_r373684134
 
 

 ##########
 File path: tests/sensors/test_weekday_sensor.py
 ##########
 @@ -33,130 +33,91 @@
 WEEKEND_DATE = datetime(2018, 12, 22)
 TEST_DAG_ID = 'weekday_sensor_dag'
 DEV_NULL = '/dev/null'
-
-
-class TestDayOfWeekSensor(unittest.TestCase):
-
-    def setUp(self):
-        self.dagbag = DagBag(
-            dag_folder=DEV_NULL,
-            include_examples=True
-        )
-        self.args = {
-            'owner': 'airflow',
-            'start_date': DEFAULT_DATE
-        }
-        dag = DAG(TEST_DAG_ID, default_args=self.args)
-        self.dag = dag
-
-    def tearDown(self):
-        session = Session()
-        session.query(models.TaskInstance).filter_by(
-            dag_id=TEST_DAG_ID).delete()
-        session.query(TaskFail).filter_by(
-            dag_id=TEST_DAG_ID).delete()
-        session.commit()
-        session.close()
-
-    def test_weekday_sensor_true(self):
-        op = DayOfWeekSensor(
-            task_id='weekday_sensor_check_true',
-            week_day='Thursday',
-            use_task_execution_day=True,
-            dag=self.dag)
+TRUE_TESTS_CONFIG = {
+    "string": "Thursday",
+    "enum": WeekDay.THURSDAY,
+    "enum-set": {WeekDay.THURSDAY},
+    "enum-set-2-items": {WeekDay.THURSDAY, WeekDay.FRIDAY},
+    "string-set": {'Thursday'},
+    "string-set-2-items": {'Thursday', 'Friday'},
+}
+
+
+@pytest.fixture
+def dag():
+    args = {"owner": "airflow", "start_date": DEFAULT_DATE}
+    return DAG(TEST_DAG_ID, default_args=args)
+
+
+@pytest.fixture
+def tear_down():
+    yield
+
+    session = Session()
+    session.query(models.TaskInstance).filter_by(
+        dag_id=TEST_DAG_ID).delete()
+    session.query(TaskFail).filter_by(
+        dag_id=TEST_DAG_ID).delete()
+    session.commit()
+    session.close()
+
+
+@pytest.mark.parametrize("weekday", TRUE_TESTS_CONFIG.values(), ids=list(TRUE_TESTS_CONFIG.keys()))
+def test_weekday_sensor_true(dag, weekday, tear_down):
+    op = DayOfWeekSensor(
+        task_id="weekday_sensor_check_true",
 
 Review comment:
   Ah, that makes sense. Thank you for the heads up 👍

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services