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 2022/12/12 11:28:48 UTC

[GitHub] [airflow] Taragolis commented on a diff in pull request #28301: [WIP] Migrate Google Cloud hooks test to `pytest`

Taragolis commented on code in PR #28301:
URL: https://github.com/apache/airflow/pull/28301#discussion_r1045708637


##########
tests/providers/google/cloud/hooks/test_gcs.py:
##########
@@ -776,24 +788,13 @@ def test_list_by_timespans(self, mock_service):
         assert len(response) == 2 and all("in-interval" in b for b in response)
 
 
-class TestGCSHookUpload(unittest.TestCase):
-    def setUp(self):
+class TestGCSHookUpload:
+    def setup_method(self):
         with mock.patch(BASE_STRING.format("GoogleBaseHook.__init__")):
             self.gcs_hook = gcs.GCSHook(gcp_conn_id="test")
 
-        # generate a 384KiB test file (larger than the minimum 256KiB multipart chunk size)
-
-        self.testfile = tempfile.NamedTemporaryFile(delete=False)
-        self.testfile.write(b"x" * 393216)
-        self.testfile.flush()
-        self.testdata_bytes = b"x" * 393216
-        self.testdata_str = "x" * 393216
-
-    def tearDown(self):
-        os.unlink(self.testfile.name)
-

Review Comment:
   Replace this one by fixtures.



##########
tests/providers/google/cloud/hooks/test_dataflow.py:
##########
@@ -1437,30 +1427,61 @@ def test_check_dataflow_job_state_without_job_type(self, job_state, wait_until_f
         result = dataflow_job._check_dataflow_job_state(job)
         assert result == expected_result
 
-    # fmt: off
-    @parameterized.expand([
-        (DataflowJobType.JOB_TYPE_BATCH, DataflowJobStatus.JOB_STATE_FAILED,
-            "Google Cloud Dataflow job name-2 has failed\\."),
-        (DataflowJobType.JOB_TYPE_STREAMING, DataflowJobStatus.JOB_STATE_FAILED,
-         "Google Cloud Dataflow job name-2 has failed\\."),
-        (DataflowJobType.JOB_TYPE_STREAMING, DataflowJobStatus.JOB_STATE_UNKNOWN,
-         "Google Cloud Dataflow job name-2 was unknown state: JOB_STATE_UNKNOWN"),
-        (DataflowJobType.JOB_TYPE_BATCH, DataflowJobStatus.JOB_STATE_UNKNOWN,
-         "Google Cloud Dataflow job name-2 was unknown state: JOB_STATE_UNKNOWN"),
-        (DataflowJobType.JOB_TYPE_BATCH, DataflowJobStatus.JOB_STATE_CANCELLED,
-            "Google Cloud Dataflow job name-2 was cancelled\\."),
-        (DataflowJobType.JOB_TYPE_STREAMING, DataflowJobStatus.JOB_STATE_CANCELLED,
-         "Google Cloud Dataflow job name-2 was cancelled\\."),
-        (DataflowJobType.JOB_TYPE_BATCH, DataflowJobStatus.JOB_STATE_DRAINED,
-            "Google Cloud Dataflow job name-2 was drained\\."),
-        (DataflowJobType.JOB_TYPE_STREAMING, DataflowJobStatus.JOB_STATE_DRAINED,
-         "Google Cloud Dataflow job name-2 was drained\\."),
-        (DataflowJobType.JOB_TYPE_BATCH, DataflowJobStatus.JOB_STATE_UPDATED,
-            "Google Cloud Dataflow job name-2 was updated\\."),
-        (DataflowJobType.JOB_TYPE_STREAMING, DataflowJobStatus.JOB_STATE_UPDATED,
-         "Google Cloud Dataflow job name-2 was updated\\."),
-    ])
-    # fmt: on

Review Comment:
   Actually there is quite a few instructions for disable `black`. 
   I've just change only related to migration.
   
   But still exists in some modules, we could get rid of them later:
   
   ```console
   ❯ grep -rl '# fmt: off' ./tests/providers | sort | uniq
   ./tests/providers/google/cloud/hooks/test_dataflow.py
   ./tests/providers/google/cloud/hooks/test_functions.py
   ./tests/providers/google/cloud/hooks/test_gcs.py
   ./tests/providers/google/cloud/hooks/test_life_sciences.py
   ./tests/providers/google/cloud/hooks/test_mlengine.py
   ./tests/providers/google/cloud/operators/test_functions.py
   ./tests/providers/google/cloud/transfers/test_bigquery_to_mssql.py
   ./tests/providers/google/cloud/transfers/test_bigquery_to_mysql.py
   ./tests/providers/google/marketing_platform/hooks/test_analytics.py
   ./tests/providers/google/marketing_platform/hooks/test_campaign_manager.py
   ./tests/providers/google/marketing_platform/hooks/test_display_video.py
   ./tests/providers/microsoft/azure/hooks/test_azure_cosmos.py
   ```
   



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