Пример #1
0
def test_unwrap_functions():
    a = lambda x: False
    b = lambda x: False
    c = lambda x: False
    d = lambda x: False
    e = lambda x: False

    lst = [a, Collection(b, Collection(c, d)), e]
    assert unwrap_functions(lst) == [a, b, c, d, e]
Пример #2
0
def test_collection_applied_in_order(fake_report):
    collection = Collection(
        "foo",
        lambda x: x + [1],
        lambda x: x + [2]
    )
    report, data = system_model([], collection)
    assert data == [1,2]
Пример #3
0
def test_collection_contains():
    collection = Collection(1, 2)
    assert 1 in collection
    assert 3 not in collection
Пример #4
0
def test_collection_len():
    collection = Collection(1, 2)
    assert len(collection) == 2
Пример #5
0
def test_empty_collection_is_falsey():
    """Passing a bare empty collection will trigger the default configuration"""
    assert not bool(Collection())
Пример #6
0
def test_can_nest_collections(fake_report):
    empty_collection = Collection()
    report, data = system_model([1, 2, 3, 4], Collection(empty_collection))
    assert data == [1, 2, 3, 4]
Пример #7
0
def test_can_pass_collection_directly(fake_report):
    """i.e. not in a list"""
    collection = Collection(lambda x: x)
    report, data = system_model([1, 2, 3, 4], collection)
    assert data == [1, 2, 3, 4]
Пример #8
0
def test_empty_collection(fake_report):
    empty_collection = Collection()
    report, data = system_model([1, 2, 3, 4], [empty_collection])
    assert data == [1, 2, 3, 4]
Пример #9
0
def test_collection_getitem():
    collection = Collection("foo", 1, 2, 3)
    assert collection[1] == 2
Пример #10
0
def test_collection_unwrapped():
    collection = Collection("foo", 1, 2, Collection("bar", 3, 4))
    assert collection.functions == [1,2,3,4]
Пример #11
0
def test_collection_str():
    collection = Collection("foo", 1, 2, 3)
    assert str(collection) == 'Collection foo with 3 functions'
    assert repr(collection) == 'Collection foo with 3 functions'
Пример #12
0
def test_collection_reversed():
    collection = Collection("foo", 1, 2, 3)
    assert list(reversed(collection)) == [3, 2, 1]
Пример #13
0
def test_collection_insert():
    collection = Collection("foo", 1, 2, 3)
    collection.insert(0, 'foo')
    assert collection.functions == ['foo', 1, 2, 3]
Пример #14
0
def test_collection_deltiem():
    collection = Collection("foo", 1, 2, 3)
    del collection[1]
    assert collection.functions == [1, 3]
Пример #15
0
def test_collection_setitem():
    collection = Collection("foo", 1, 2, 3)
    collection[2] = 'bar'
    assert collection.functions == [1, 2, 'bar']