Esempio n. 1
0
def test_lazy_which():
    m = mock.Mock(return_value=[mock.Mock()])
    lw = LazyWhich(m)
    assert m.call_count == 0

    lw.search('a')
    assert m.call_count == 1

    lw.search('b')
    assert m.call_count == 1
Esempio n. 2
0
def test_lazy_which_attribute():
    p = mock.Mock()
    m = mock.Mock(return_value=[p])
    lw = LazyWhich(m)
    assert lw.search('a') == p.search.return_value

    assert lw.search('b') == p.search.return_value
    assert p.search.has_calls([
        mock.call.search('a'),
        mock.call.search('b'),
    ])
Esempio n. 3
0
def test_lazy_which_evaluate():
    m = mock.Mock(return_value=[mock.Mock()])
    lw = LazyWhich(m)

    @lw.update
    def action():
        pass

    lw.search('a')
    action()

    lw.search('a')
    assert m.call_count == 2, '%s != %s' % (m.call_count, 2)