mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Add new munge_lists function + unit test
This commit is contained in:
@@ -1882,3 +1882,14 @@ def enum_values(enum_class):
|
||||
Values are in member definition order.
|
||||
"""
|
||||
return [value.value for value in enum_class.__members__.values()]
|
||||
|
||||
|
||||
def munge_lists(listA: Any, listB: Any) -> List:
|
||||
"""
|
||||
Combine two lists into a single list.
|
||||
|
||||
Arguments can be None, non-lists, or lists. If an argument is None, it will
|
||||
not be included in the returned list. If both arguments are None, an empty
|
||||
list will be returned.
|
||||
"""
|
||||
return listify(listA) + listify(listB)
|
||||
|
||||
@@ -149,3 +149,20 @@ def test_enum_values():
|
||||
B = "b"
|
||||
|
||||
assert util.enum_values(Stuff) == ["a", "c", "b"]
|
||||
|
||||
|
||||
class NotFalsy:
|
||||
"""Class requires explicit check for None"""
|
||||
|
||||
def __bool__(self):
|
||||
raise Exception("not implemented")
|
||||
|
||||
|
||||
def test_munge_lists():
|
||||
foo, bar = NotFalsy(), NotFalsy()
|
||||
assert util.munge_lists(foo, None) == [foo]
|
||||
assert util.munge_lists(None, foo) == [foo]
|
||||
assert util.munge_lists(foo, bar) == [foo, bar]
|
||||
assert util.munge_lists([foo, bar], None) == [foo, bar]
|
||||
assert util.munge_lists(None, [foo, bar]) == [foo, bar]
|
||||
assert util.munge_lists(None, None) == []
|
||||
|
||||
Reference in New Issue
Block a user