You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@airflow.apache.org by GitBox <gi...@apache.org> on 2018/08/03 13:28:46 UTC

[GitHub] Fokko closed pull request #3686: [AIRFLOW-2796] Expand code coverage for utils/helpers.py

Fokko closed pull request #3686: [AIRFLOW-2796] Expand code coverage for utils/helpers.py
URL: https://github.com/apache/incubator-airflow/pull/3686
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py
index 1005671e9e..b2e79560f4 100644
--- a/tests/utils/test_helpers.py
+++ b/tests/utils/test_helpers.py
@@ -117,5 +117,62 @@ def test_reduce_in_chunks(self):
                          14)
 
 
+class HelpersTest(unittest.TestCase):
+    def test_as_tuple_iter(self):
+        test_list = ['test_str']
+        as_tup = helpers.as_tuple(test_list)
+        self.assertTupleEqual(tuple(test_list), as_tup)
+
+    def test_as_tuple_no_iter(self):
+        test_str = 'test_str'
+        as_tup = helpers.as_tuple(test_str)
+        self.assertTupleEqual((test_str,), as_tup)
+
+    def test_is_in(self):
+        from airflow.utils import helpers
+        # `is_in` expects an object, and a list as input
+
+        test_dict = {'test': 1}
+        test_list = ['test', 1, dict()]
+        small_i = 3
+        big_i = 2 ** 31
+        test_str = 'test_str'
+        test_tup = ('test', 'tuple')
+
+        test_container = [test_dict, test_list, small_i, big_i, test_str, test_tup]
+
+        # Test that integers are referenced as the same object
+        self.assertTrue(helpers.is_in(small_i, test_container))
+        self.assertTrue(helpers.is_in(3, test_container))
+
+        # python caches small integers, so i is 3 will be True,
+        # but `big_i is 2 ** 31` is False.
+        self.assertTrue(helpers.is_in(big_i, test_container))
+        self.assertFalse(helpers.is_in(2 ** 31, test_container))
+
+        self.assertTrue(helpers.is_in(test_dict, test_container))
+        self.assertFalse(helpers.is_in({'test': 1}, test_container))
+
+        self.assertTrue(helpers.is_in(test_list, test_container))
+        self.assertFalse(helpers.is_in(['test', 1, dict()], test_container))
+
+        self.assertTrue(helpers.is_in(test_str, test_container))
+        self.assertTrue(helpers.is_in('test_str', test_container))
+        bad_str = 'test_'
+        bad_str += 'str'
+        self.assertFalse(helpers.is_in(bad_str, test_container))
+
+        self.assertTrue(helpers.is_in(test_tup, test_container))
+        self.assertFalse(helpers.is_in(('test', 'tuple'), test_container))
+        bad_tup = ('test', 'tuple', 'hello')
+        self.assertFalse(helpers.is_in(bad_tup[:2], test_container))
+
+    def test_is_container(self):
+        self.assertTrue(helpers.is_container(['test_list']))
+        self.assertFalse(helpers.is_container('test_str_not_iterable'))
+        # Pass an object that is not iter nor a string.
+        self.assertFalse(helpers.is_container(10))
+
+
 if __name__ == '__main__':
     unittest.main()


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services