def test_flatten_many_nested(self): self.assertEquals(transformations.flatten([[[[[1]]]]]), [1]) self.assertEquals(transformations.flatten([[[['a']]]]), ['a']) self.assertEquals(transformations.flatten([[['abc']]]), ['abc']) self.assertEquals(transformations.flatten([[['abc'], 'def']]), ['abc', 'def']) self.assertEquals(transformations.flatten([[[['abc']]], [['def']]]), ['abc', 'def']) self.assertEquals(transformations.flatten([[[[['abc']]]], 'def']), ['abc', 'def']) self.assertEquals(transformations.flatten([[[[{'a': 1}, {'a': 2}]]]]), [{'a': 1}, {'a': 2}]) self.assertEquals(transformations.flatten((set([('abc',)]), ([('def',)],))), ['abc', 'def']) self.assertEquals(transformations.flatten([[[i]]] for i in xrange(5)), [0, 1, 2, 3, 4]) self.assertEquals(transformations.flatten([[[[[1]]]], [FakeIterable([2])]]), [1, 2])
def test_flatten_basics(self): self.assertEquals(transformations.flatten(1), [1]) self.assertEquals(transformations.flatten('a'), ['a']) self.assertEquals(transformations.flatten('abc'), ['abc']) self.assertEquals(transformations.flatten(['abc', 'def']), ['abc', 'def']) self.assertEquals(transformations.flatten(('abc', 'def')), ['abc', 'def']) self.assertEquals(transformations.flatten({'a': 1}), [{'a': 1}]) self.assertEquals(transformations.flatten((e for e in [1,2])), [1, 2]) self.assertEquals(transformations.flatten(set(['abc', 'def'])), ['abc', 'def']) self.assertEquals(transformations.flatten(xrange(5)), [0, 1, 2, 3, 4]) self.assertEquals(transformations.flatten(FakeIterable([1, 2])), [1, 2])