Exemple #1
0
def list_with_lookups():

    ilist = IndexedList(range(95, 100))

    ilist.create_lookup(name="basic")
    ilist.create_lookup(ilist.item > 97, name="filtered")

    return ilist
def gte_indexed_integers():
    """ IndexedList of integers with a gte filter """

    values = itertools.cycle(range(1, 8))
    data = [next(values) for _ in range(0, 20)]

    ilist = IndexedList(data)
    ilist.create_lookup(ilist.item >= 5)

    return ilist
def partially_indexed_integers():
    """ IndexedList of integers with only certain values indexed """

    values = itertools.cycle(range(1, 8))
    data = [next(values) for _ in range(0, 20)]

    ilist = IndexedList(data)
    ilist.create_lookup(ilist.item.in_(4, 5, 6))

    return ilist
def function_indexed_integers():
    """ IndexedList of integers with a function-based index """

    values = itertools.cycle(range(1, 8))
    data = [next(values) for _ in range(0, 20)]

    ilist = IndexedList(data)
    ilist.create_lookup(double(ilist.item))
    ilist.create_lookup(triple(triple(ilist.item)))

    return ilist
def indexed_dicts():
    """ IndexedList of dicts indexed by 'a' """

    a_values = itertools.cycle([1, 2, 3])
    b_values = itertools.cycle([3, 4, 5, 6])

    data = [{"a": next(a_values), "b": next(b_values)} for _ in range(0, 10)]

    del a_values
    del b_values

    ilist = IndexedList(data)
    ilist.create_lookup(ilist.item["a"])

    return ilist
Exemple #6
0
def test_create_lookup_before_data():
    """ Test creating a lookup before putting any data in the indexed list """

    indexed_list = IndexedList()
    indexed_list.create_lookup(name="sample")

    indexed_list.extend(range(1, 5))

    expected = [
        (1, [0]),
        (2, [1]),
        (3, [2]),
        (4, [3])
    ]

    found = [
        (key, sorted(value))
        for key, value
        in indexed_list.lookups["sample"].mapping.items()
    ]

    assert expected == found, "Data in mapping is not as expected"