def test_custom_basecase(self): def basecase(iterable): return isinstance(iterable, tuple) self.assert_iter_equal( flattened([[(0, )], [(1, ), [], []], (2, )], basecase=basecase), [(0, ), (1, ), (2, )])
def test_nested(self): self.assert_iter_equal(flattened([0]), [0]) self.assert_iter_equal(flattened(['a']), ['a']) self.assert_iter_equal(flattened([[], [[], []]]), []) self.assert_iter_equal(flattened([[[0]], [1, [2]], [3]]), [0, 1, 2, 3]) self.assert_iter_equal(flattened([[{0}], (), [1, ([2],), []], [3]]), [0, 1, 2, 3]) self.assert_iter_equal(flattened([[{0}], (), ['b', (['a'],), []], [3]]), [0, 'b', 'a', 3]) # Python 2.7 unicode test try: unicode except NameError: pass else: self.assert_iter_equal(flattened([[unicode('a')], [unicode('b')]]), [unicode('a'), unicode('b')])
def test_nested(self): self.assert_iter_equal(flattened([0]), [0]) self.assert_iter_equal(flattened(['a']), ['a']) self.assert_iter_equal(flattened([[], [[], []]]), []) self.assert_iter_equal(flattened([[[0]], [1, [2]], [3]]), [0, 1, 2, 3]) self.assert_iter_equal(flattened([[{0}], (), [1, ([2], ), []], [3]]), [0, 1, 2, 3]) self.assert_iter_equal( flattened([[{0}], (), ['b', (['a'], ), []], [3]]), [0, 'b', 'a', 3]) # Python 2.7 unicode test try: unicode except NameError: pass else: self.assert_iter_equal(flattened([[unicode('a')], [unicode('b')]]), [unicode('a'), unicode('b')])
def test_empty(self): self.assert_iter_equal(flattened(range(0)), [])
def test_custom_basecase(self): def basecase(iterable): return isinstance(iterable, tuple) self.assert_iter_equal(flattened([[(0,)], [(1,), [], []], (2,)], basecase=basecase), [(0,), (1,), (2,)])