def test_flattens_inner_list(self): "Assure arbitrarily nested lists are flattened" nested_list = [1, [2, [ 3, 4, [5], ], 6, 7], 8] self.assertEqual(list(_flatten(nested_list)), list(range(1, 9)))
def test_flatten_string_unchanged(self): "Assure strings are left intact" data = ['abc', ['abc', ['abc']], 'abc'] self.assertEqual(list(_flatten(data)), ['abc', 'abc', 'abc', 'abc'])
def test_flatten_generator(self): "Assure generators are flattened" gens = [1, list(range(2, 4)), (num for num in (4, list(range(5, 7))))] self.assertEqual(list(_flatten(gens)), list(range(1, 7)))
def test_flatten_nested_combinations(self): "Assure nested iterables are flattened" nested = [1, frozenset([2, 3]), (4, (5, ), 6), [7], 8] self.assertEqual(list(_flatten(nested)), list(range(1, 9)))
def test_flattens_sets(self): "Assure nested sets are flattened" nested_sets = set([1, frozenset([2, 3]), 4]) self.assertEqual(list(_flatten(nested_sets)), list(range(1, 5)))
def test_flattens_tuples(self): "Assure nested tuples are also flattened" nested_tuples = (1, (2, 3, (4, ), 5), 6) self.assertEqual(list(_flatten(nested_tuples)), list(range(1, 7)))
def test_flatten_string_unchanged(self): "Assure strings are left intact" data = ["abc", ["abc", ["abc"]], "abc"] self.assertEqual(list(_flatten(data)), ["abc", "abc", "abc", "abc"])
def test_flatten_nested_combinations(self): "Assure nested iterables are flattened" nested = [1, frozenset([2, 3]), (4, (5,), 6), [7], 8] self.assertEqual(list(_flatten(nested)), list(range(1, 9)))
def test_flattens_tuples(self): "Assure nested tuples are also flattened" nested_tuples = (1, (2, 3, (4,), 5), 6) self.assertEqual(list(_flatten(nested_tuples)), list(range(1, 7)))
def test_flattens_inner_list(self): "Assure arbitrarily nested lists are flattened" nested_list = [1, [2, [3, 4, [5]], 6, 7], 8] self.assertEqual(list(_flatten(nested_list)), list(range(1, 9)))