コード例 #1
0
def test_coalesce_calls():
    first = MagicMock()
    second = MagicMock()
    last = MagicMock()
    first.return_value = None
    second.return_value = 'MOCK'

    coalesce = callback_utils.coalesce([first, second, last])
    value = coalesce('VALUE')

    assert first.called
    assert value is 'MOCK'
    assert not last.called
コード例 #2
0
    class Mapper(object):
        coalesce = callback_utils.coalesce([_return_none] * 10, else_='ELSE')

        def call(self, x):
            return self.coalesce(x)
コード例 #3
0
def test_coalesce_10():
    coalesce = callback_utils.coalesce([_return_none] * 10, else_='ELSE')
    assert coalesce(None) is 'ELSE'
コード例 #4
0
def test_coalesce_else():
    coalesce = callback_utils.coalesce([], else_='ELSE')
    assert coalesce(None) is 'ELSE'
コード例 #5
0
def test_coalesce_0():
    coalesce = callback_utils.coalesce([])
    assert coalesce(None) is None
コード例 #6
0
def test_coalesce_1():
    coalesce = callback_utils.coalesce([_return_arg])
    assert coalesce('RETURN') == 'RETURN'
コード例 #7
0
def test_coalesce_2():
    coalesce = callback_utils.coalesce([
        _return_none, _return_none
    ], else_='ELSE')
    assert coalesce(None) == 'ELSE'