Пример #1
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, )])
Пример #2
0
    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')])
Пример #3
0
    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')])
Пример #4
0
 def test_empty(self):
     self.assert_iter_equal(flattened(range(0)), [])
Пример #5
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,)])
Пример #6
0
 def test_empty(self):
     self.assert_iter_equal(flattened(range(0)), [])