Exemplo n.º 1
0
def earlyorder(*goals):
    """ Reorder goals to avoid EarlyGoalErrors

    All goals are evaluated.  Those that raise EarlyGoalErrors are placed at
    the end in a lallearly

    See also:
        EarlyGoalError
    """
    groups = groupby(earlysafe, goals)
    good = groups.get(True, [])
    bad  = groups.get(False, [])

    if not good:
        raise EarlyGoalError()
    elif not bad:
        return tuple(good)
    else:
        return tuple(good) + ((lallearly,) + tuple(bad),)
Exemplo n.º 2
0
def test_groupby():
    d = groupby(lambda x: x%2, range(10))
    assert set(d.keys()) == set((0, 1))
    assert set(d[0]) == set((0, 2, 4, 6, 8))
    assert set(d[1]) == set((1, 3, 5, 7, 9))