From d48ea0a167c4428c37fc2939779f11d03fef9863 Mon Sep 17 00:00:00 2001 From: "Agastiya S. Mohammad" <39547572+egibbm@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:32:16 +0700 Subject: [PATCH] Fix QuboleHook unable to add list to tags (#9347) --- airflow/providers/qubole/hooks/qubole.py | 2 +- tests/providers/qubole/hooks/test_qubole.py | 40 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/providers/qubole/hooks/test_qubole.py diff --git a/airflow/providers/qubole/hooks/qubole.py b/airflow/providers/qubole/hooks/qubole.py index cdd5cac67a8fa..508ead3f9d5c0 100644 --- a/airflow/providers/qubole/hooks/qubole.py +++ b/airflow/providers/qubole/hooks/qubole.py @@ -254,4 +254,4 @@ def _add_tags(tags, value): if isinstance(value, str): tags.add(value) elif isinstance(value, (list, tuple)): - tags.extend(value) + tags.update(value) diff --git a/tests/providers/qubole/hooks/test_qubole.py b/tests/providers/qubole/hooks/test_qubole.py new file mode 100644 index 0000000000000..a3718010b58d5 --- /dev/null +++ b/tests/providers/qubole/hooks/test_qubole.py @@ -0,0 +1,40 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# +import unittest + +from airflow.providers.qubole.hooks.qubole import QuboleHook + +add_tags = QuboleHook._add_tags + + +class TestQuboleHook(unittest.TestCase): + def test_add_string_to_tags(self): + tags = {'dag_id', 'task_id'} + add_tags(tags, 'string') + self.assertEqual({'dag_id', 'task_id', 'string'}, tags) + + def test_add_list_to_tags(self): + tags = {'dag_id', 'task_id'} + add_tags(tags, ['value1', 'value2']) + self.assertEqual({'dag_id', 'task_id', 'value1', 'value2'}, tags) + + def test_add_tuple_to_tags(self): + tags = {'dag_id', 'task_id'} + add_tags(tags, ('value1', 'value2')) + self.assertEqual({'dag_id', 'task_id', 'value1', 'value2'}, tags)