コード例 #1
0
def testFlattenSkipTypeOfSubclass():
    class Foo(ListWithoutIter):
        def __init__(self, *args, **kwargs):
            super(Foo, self).__init__(*args, **kwargs)

    obj = Foo()
    a = [obj, "c", "d"]
    assert Flatten(a, skip_types=[ListWithoutIter]) == [obj, "c", "d"]
コード例 #2
0
def testFlattenSkipSpecificClass():
    obj = ListWithoutIter("a", "b")
    a = [obj, "c", ["d", "e"]]
    assert Flatten(a, skip_types=[ListWithoutIter]) == [obj, "c", "d", "e"]
コード例 #3
0
def testFlattenForTuples():
    a = [(0, "a"), (1, "b"), ((2, "c"), 42)]
    assert Flatten(a) == [0, "a", 1, "b", 2, "c", 42]
コード例 #4
0
def testFlattenForUnicodeStrings():
    a = [["a", "bb"], "ccc"]
    assert Flatten(a) == ["a", "bb", "ccc"]
コード例 #5
0
def testFlattenOnClassWithoutIterForStrings():
    a = ListWithoutIter(ListWithoutIter("a", "bb"), "ccc")
    assert Flatten(a) == ["a", "bb", "ccc"]
コード例 #6
0
def testFlattenOnClassWithoutIter():
    a = ListWithoutIter(ListWithoutIter(0, 1), 2, 3)
    assert Flatten(a) == [0, 1, 2, 3]
コード例 #7
0
def testFlatten():
    a = [[[1], [2]], [3]]
    assert Flatten(a) == [1, 2, 3]

    a = [1, 2, [3, 4], (5, 6)]
    assert Flatten(a) == [1, 2, 3, 4, 5, 6]