diff --git a/wlauto/tests/test_utils.py b/wlauto/tests/test_utils.py index 74e159d8..3043eb8d 100644 --- a/wlauto/tests/test_utils.py +++ b/wlauto/tests/test_utils.py @@ -20,7 +20,7 @@ from unittest import TestCase from nose.tools import raises, assert_equal, assert_not_equal # pylint: disable=E0611 from wlauto.utils.android import check_output -from wlauto.utils.misc import merge_dicts, TimeoutError +from wlauto.utils.misc import merge_dicts, merge_lists, TimeoutError from wlauto.utils.types import list_or_integer, list_or_bool, caseless_string, arguments @@ -56,6 +56,12 @@ class TestMerge(TestCase): result = merge_dicts(base, other, list_duplicates='last') assert_equal(result['a'], [1, 2, 3, 4, 5]) + def test_merge_lists(self): + result = merge_lists([1, 2, 3], 7) + assert_equal(result, [1, 2, 3, 7]) + result = merge_lists([1, 2, 3], 1, duplicates='last') + assert_equal(result, [2, 3, 1]) + @raises(ValueError) def test_type_mismatch(self): base = {'a': [1, 2, 3]} diff --git a/wlauto/utils/misc.py b/wlauto/utils/misc.py index ac770d59..6b02992a 100644 --- a/wlauto/utils/misc.py +++ b/wlauto/utils/misc.py @@ -330,6 +330,10 @@ def _merge_two_lists(base, other, duplicates='all', dict_type=dict): # pylint: will never be removed. """ + if not isiterable(base): + base = [base] + if not isiterable(other): + other = [other] if duplicates == 'all': merged_list = [] for v in normalize(base, dict_type) + normalize(other, dict_type):