Example #1
0
def test_basic():
    my_callable1 = Mock()
    my_callable2 = Mock()
    bag = Bag(*args, **kwargs)

    assert not my_callable1.called
    result1 = bag.apply(my_callable1)
    assert my_callable1.called and result1 is my_callable1.return_value

    assert not my_callable2.called
    result2 = bag.apply(my_callable2)
    assert my_callable2.called and result2 is my_callable2.return_value

    assert result1 is not result2

    my_callable1.assert_called_once_with(*args, **kwargs)
    my_callable2.assert_called_once_with(*args, **kwargs)
Example #2
0
def test_iterator():
    bag = Bag()
    assert list(bag.apply([1, 2, 3])) == [1, 2, 3]
    assert list(bag.apply((1, 2, 3))) == [1, 2, 3]
    assert list(bag.apply(range(5))) == [0, 1, 2, 3, 4]
    assert list(bag.apply('azerty')) == ['a', 'z', 'e', 'r', 't', 'y']