Lee-W commented on code in PR #34592:
URL: https://github.com/apache/airflow/pull/34592#discussion_r1335740572
##########
tests/providers/amazon/aws/sensors/test_batch.py:
##########
@@ -106,6 +106,33 @@ def
test_execute_failure_in_deferrable_mode_with_soft_fail(self, deferrable_batc
with pytest.raises(AirflowSkipException):
deferrable_batch_sensor.execute_complete(context={},
event={"status": "failure"})
+ @pytest.mark.parametrize(
+ "soft_fail, expected_exception", ((False, AirflowException), (True,
AirflowSkipException))
+ )
+ @mock.patch.object(BatchClientHook, "get_job_description")
+ def test_fail_poke_failed_state(
+ self, mock_get_job_description, batch_sensor: BatchSensor, soft_fail,
expected_exception
+ ):
+ mock_get_job_description.return_value = {"status":
BatchClientHook.FAILURE_STATE}
+ message = f"Batch sensor failed. AWS Batch job status:
{BatchClientHook.FAILURE_STATE}"
+ batch_sensor.soft_fail = soft_fail
+ with pytest.raises(expected_exception, match=message):
+ batch_sensor.poke({})
+
+ @pytest.mark.parametrize(
+ "soft_fail, expected_exception", ((False, AirflowException), (True,
AirflowSkipException))
+ )
+ @mock.patch.object(BatchClientHook, "get_job_description")
+ def test_fail_poke_unknown_state(
+ self, mock_get_job_description, batch_sensor: BatchSensor, soft_fail,
expected_exception
+ ):
+ state = "unknown_state"
+ mock_get_job_description.return_value = {"status": state}
+ message = f"Batch sensor failed. Unknown AWS Batch job status: {state}"
+ batch_sensor.soft_fail = soft_fail
+ with pytest.raises(expected_exception, match=message):
+ batch_sensor.poke({})
Review Comment:
```suggestion
@pytest.mark.parametrize(
"soft_fail, expected_exception", ((False, AirflowException), (True,
AirflowSkipException))
)
@pytest.mark.parametrize(
"state, error_message",
(
(BatchClientHook.FAILURE_STATE, f"Batch sensor failed. AWS Batch
job status: {BatchClientHook.FAILURE_STATE}"),
("unknown_state", "Batch sensor failed. Unknown AWS Batch job
status: unknown_state")
)
)
@mock.patch.object(BatchClientHook, "get_job_description")
def test_fail_poke(
self, mock_get_job_description, batch_sensor: BatchSensor, status,
error_message, soft_fail, expected_exception
):
mock_get_job_description.return_value = {"status": state}
batch_sensor.soft_fail = soft_fail
with pytest.raises(expected_exception, match=error_message):
batch_sensor.poke({})
```
Forgot this one
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]