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 20:57:55 UTC

[GitHub] [airflow] coopergillan opened a new pull request #7315: [AIRFLOW-6699] Parameterize weekday_sensor tests

coopergillan opened a new pull request #7315: [AIRFLOW-6699] Parameterize weekday_sensor tests
URL: https://github.com/apache/airflow/pull/7315
 
 
   Using `pytest`, consolidate the "True" or "happy path" tests into one parameterized test that uses a new TRUE_TESTS_CONFIG to drive test names and the `week_day` parameter.
   
   Update all tests to use `pytest`, including regex matching on the failing tests as needed.
   
   ---
   Issue link: WILL BE INSERTED BY [boring-cyborg](https://github.com/kaxil/boring-cyborg)
   
   Make sure to mark the boxes below before creating PR: [x]
   
   - [x] Description above provides context of the change
   - [x] Commit message/PR title starts with `[AIRFLOW-NNNN]`. AIRFLOW-NNNN = JIRA ID<sup>*</sup>
   - [x] Unit tests coverage for changes (not needed for documentation changes)
   - [x] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
   - [x] Relevant documentation is updated including usage instructions.
   - [x] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
   
   <sup>*</sup> For document-only changes commit message can start with `[AIRFLOW-XXXX]`.
   
   ---
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
   

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

[GitHub] [airflow] coopergillan closed pull request #7315: [AIRFLOW-6699] Parameterize weekday_sensor tests

Posted by GitBox <gi...@apache.org>.
coopergillan closed pull request #7315: [AIRFLOW-6699] Parameterize weekday_sensor tests
URL: https://github.com/apache/airflow/pull/7315
 
 
   

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

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

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #7315: [AIRFLOW-6699] Parameterize weekday_sensor tests
URL: https://github.com/apache/airflow/pull/7315#discussion_r373683785
 
 

 ##########
 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:
   It is necessary to use classes in tests. More information: https://lists.apache.org/thread.html/1e4df7d4b0cd9b2d2bb76a3336471aa85e852545dd41ada6d4e461b8%40%3Cdev.airflow.apache.org%3E

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

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

Posted by GitBox <gi...@apache.org>.
coopergillan commented on a change in pull request #7315: [AIRFLOW-6699] Parameterize weekday_sensor tests
URL: https://github.com/apache/airflow/pull/7315#discussion_r373692143
 
 

 ##########
 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:
   This helped me learn about how tests **are** parameterized here in `airflow`. Went with a different approach over in #7316.

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

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

Posted by GitBox <gi...@apache.org>.
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

[GitHub] [airflow] coopergillan commented on issue #7315: [AIRFLOW-6699] Parameterize weekday_sensor tests

Posted by GitBox <gi...@apache.org>.
coopergillan commented on issue #7315: [AIRFLOW-6699] Parameterize weekday_sensor tests
URL: https://github.com/apache/airflow/pull/7315#issuecomment-580917441
 
 
   Closed in favor of https://github.com/apache/airflow/pull/7316.

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

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

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #7315: [AIRFLOW-6699] Parameterize weekday_sensor tests
URL: https://github.com/apache/airflow/pull/7315#discussion_r373683785
 
 

 ##########
 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:
   It is necessary to use classes in tests. More information: https://lists.apache.org/thread.html/1e4df7d4b0cd9b2d2bb76a3336471aa85e852545dd41ada6d4e461b8%40%3Cdev.airflow.apache.org%3E (question 5)

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