ashb commented on a change in pull request #3115: [AIRFLOW-2193] Add ROperator 
for using R
URL: https://github.com/apache/airflow/pull/3115#discussion_r256340112
 
 

 ##########
 File path: tests/contrib/operators/test_r_operator.py
 ##########
 @@ -0,0 +1,171 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from __future__ import print_function, unicode_literals
+
+import os
+import unittest
+
+from airflow import configuration, DAG
+from airflow.contrib.operators.r_operator import ROperator
+from airflow.models import TaskInstance
+from airflow.utils import timezone
+
+
+DEFAULT_DATE = timezone.datetime(2016, 1, 1)
+
+
+class ROperatorTest(unittest.TestCase):
+    """Test the ROperator"""
+
+    def setUp(self):
+        super(ROperatorTest, self).setUp()
+        configuration.load_test_config()
+        self.dag = DAG(
+            'test_roperator_dag',
+            default_args={
+                'owner': 'airflow',
+                'start_date': DEFAULT_DATE
+            },
+            schedule_interval='@once'
+        )
+
+        self.xcom_test_str = 'Hello Airflow'
+        self.task_xcom = ROperator(
+            task_id='test_r_xcom',
+            r_command='cat("Ignored Line\n{}")'.format(self.xcom_test_str),
+            xcom_push=True,
+            dag=self.dag
+        )
+
+    def test_invalid_rscript_bin(self):
+        """Fail if invalid rscript_bin supplied"""
+
+        try:
+            expected_error = FileNotFoundError
+        except NameError:
+            # py2
+            expected_error = OSError
+
+        task = ROperator(
+            task_id='test_r_bad_rscript',
+            r_command='print(Sys.Date())',
+            rscript_bin='somebadrscript',
+            dag=self.dag
+        )
+
+        self.assertIsNotNone(task)
+
+        ti = TaskInstance(task=task, execution_date=timezone.utcnow())
+
+        with self.assertRaises(expected_error):
+            ti.run()
+
+    def test_xcom_output(self):
+        """Test whether Xcom output is produced using last line"""
+
+        self.task_xcom.xcom_push = True
 
 Review comment:
   ```suggestion
           self.task_xcom.do_xcom_push = True
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to