Skip to content

Commit

Permalink
[AIRFLOW-5276] remove unused is_in helper function (#5878)
Browse files Browse the repository at this point in the history
(cherry picked from commit cd4ab7b)
  • Loading branch information
Qingping Hou authored and ashb committed Aug 22, 2019
1 parent df4fe07 commit 2148a16
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 73 deletions.
12 changes: 0 additions & 12 deletions airflow/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,6 @@ def ask_yesno(question):
print("Please respond by yes or no.")


def is_in(obj, l):
"""
Checks whether an object is one of the item in the list.
This is different from ``in`` because ``in`` uses __cmp__ when
present. Here we change based on the object itself
"""
for item in l:
if item is obj:
return True
return False


def is_container(obj):
"""
Test if an object is a container (iterable) but not a string
Expand Down
61 changes: 0 additions & 61 deletions tests/utils/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,6 @@ def test_reduce_in_chunks(self):
2),
14)

def test_is_in(self):
obj = ["list", "object"]
# Check for existence of a list object within a list
self.assertTrue(
helpers.is_in(obj, [obj])
)

# Check that an empty list returns false
self.assertFalse(
helpers.is_in(obj, [])
)

# Check to ensure it handles None types
self.assertFalse(
helpers.is_in(None, [obj])
)

# Check to ensure true will be returned of multiple objects exist
self.assertTrue(
helpers.is_in(obj, [obj, obj])
)

def test_is_container(self):
self.assertFalse(helpers.is_container("a string is not a container"))
self.assertTrue(helpers.is_container(["a", "list", "is", "a", "container"]))
Expand Down Expand Up @@ -194,45 +172,6 @@ def test_as_tuple_no_iter(self):
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'))
Expand Down

0 comments on commit 2148a16

Please sign in to comment.