[GitHub] [airflow] uranusjr commented on a diff in pull request #27797: Add tests to PythonOperator

2022-12-06 Thread GitBox


uranusjr commented on code in PR #27797:
URL: https://github.com/apache/airflow/pull/27797#discussion_r1040774539


##
airflow/exceptions.py:
##
@@ -368,3 +368,11 @@ class 
AirflowProviderDeprecationWarning(DeprecationWarning):
 
 deprecated_provider_since: str | None = None
 "Indicates the provider version that started raising this deprecation 
warning"
+
+
+class DeserializingResultError(AirflowException):
+""" Raised when an error is encountered while a pickling library 
deserializes a pickle file"""
+
+def __str__(self):
+return "Error deserializing result. Note that result deserialization 
\n" \
+   "is not supported across major Python versions."

Review Comment:
   ```suggestion
   return (
   "Error deserializing result. Note that result deserialization "
   "is not supported across major Python versions."
   )
   ```



##
airflow/operators/python.py:
##
@@ -372,11 +373,7 @@ def _read_result(self, path: Path):
 try:
 return self.pickling_library.loads(path.read_bytes())
 except ValueError:
-self.log.error(
-"Error deserializing result. Note that result deserialization "
-"is not supported across major Python versions."
-)
-raise
+raise DeserializingResultError

Review Comment:
   ```suggestion
   raise DeserializingResultError from None
   ```



##
airflow/exceptions.py:
##
@@ -368,3 +368,11 @@ class 
AirflowProviderDeprecationWarning(DeprecationWarning):
 
 deprecated_provider_since: str | None = None
 "Indicates the provider version that started raising this deprecation 
warning"
+
+
+class DeserializingResultError(AirflowException):

Review Comment:
   ```suggestion
   class DeserializingResultError(ValueError):
   ```



-- 
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-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [airflow] uranusjr commented on a diff in pull request #27797: Add tests to PythonOperator

2022-11-30 Thread GitBox


uranusjr commented on code in PR #27797:
URL: https://github.com/apache/airflow/pull/27797#discussion_r1036761554


##
tests/operators/test_python.py:
##
@@ -375,6 +375,20 @@ def func():
 "INFO:airflow.task.operators:Done. Returned value not shown" in 
cm.output
 ), "Log message that the option is turned off should be shown"
 
+def test_python_operator_templates_exts(self):
+def func():
+return "test_return_value"
+
+python_operator = PythonOperator(
+task_id="python_operator",
+python_callable=func,
+dag=self.dag,
+show_return_value_in_logs=False,
+templates_exts=['test_ext']
+)
+
+assert python_operator.template_ext == ['test_ext']

Review Comment:
   Oh it’s the `templates_exts` argument specific to PythonOperaotr. I wonder 
if it’s a good target for deprecation…



-- 
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-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [airflow] uranusjr commented on a diff in pull request #27797: Add tests to PythonOperator

2022-11-28 Thread GitBox


uranusjr commented on code in PR #27797:
URL: https://github.com/apache/airflow/pull/27797#discussion_r1034362366


##
tests/operators/test_python.py:
##
@@ -1155,6 +1169,21 @@ def f():
 )
 copy.deepcopy(task)
 
+def test_except_value_error(self):
+def f():
+return 1
+
+task = PythonVirtualenvOperator(
+python_callable=f,
+task_id="task",
+dag=self.dag,
+)
+
+task.log.error = unittest.mock.Mock()
+task.pickling_library.loads = 
unittest.mock.Mock(side_effect=ValueError)
+with pytest.raises(ValueError):
+task._read_result(path=unittest.mock.Mock())

Review Comment:
   Would be a good idea to use a custom exception class to ensure the exception 
is actually raised by the mocked pickling lib.



-- 
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-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [airflow] uranusjr commented on a diff in pull request #27797: Add tests to PythonOperator

2022-11-28 Thread GitBox


uranusjr commented on code in PR #27797:
URL: https://github.com/apache/airflow/pull/27797#discussion_r1034361731


##
tests/operators/test_python.py:
##
@@ -1155,6 +1169,21 @@ def f():
 )
 copy.deepcopy(task)
 
+def test_except_value_error(self):
+def f():
+return 1
+
+task = PythonVirtualenvOperator(
+python_callable=f,
+task_id="task",
+dag=self.dag,
+)
+
+task.log.error = unittest.mock.Mock()

Review Comment:
   Maybe this should use `caplog` to actually capture the logs instead of 
mocking it.



-- 
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-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [airflow] uranusjr commented on a diff in pull request #27797: Add tests to PythonOperator

2022-11-28 Thread GitBox


uranusjr commented on code in PR #27797:
URL: https://github.com/apache/airflow/pull/27797#discussion_r1034360950


##
tests/operators/test_python.py:
##
@@ -375,6 +375,20 @@ def func():
 "INFO:airflow.task.operators:Done. Returned value not shown" in 
cm.output
 ), "Log message that the option is turned off should be shown"
 
+def test_python_operator_templates_exts(self):
+def func():
+return "test_return_value"
+
+python_operator = PythonOperator(
+task_id="python_operator",
+python_callable=func,
+dag=self.dag,
+show_return_value_in_logs=False,
+templates_exts=['test_ext']
+)
+
+assert python_operator.template_ext == ['test_ext']

Review Comment:
   Why is this test relevant? `tempalte_ext` is a property on BaseOperator, is 
it not?



-- 
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-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org