예제 #1
0
 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)))
예제 #2
0
 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'])
예제 #3
0
 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)))
예제 #4
0
 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)))
예제 #5
0
 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)))
예제 #6
0
 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)))
예제 #7
0
 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"])
예제 #8
0
 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)))
예제 #9
0
 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)))
예제 #10
0
 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)))
예제 #11
0
 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)))
예제 #12
0
 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)))