コード例 #1
0
ファイル: test_gspawn.py プロジェクト: AbelMon/librarian
def test_exception_propagates():
    """ Exceptions raised by the callable are re-raised """
    fn = mock.Mock()
    fn.side_effect = RuntimeError
    try:
        mod.call(fn)
        assert False, 'Expected to raise'
    except RuntimeError:
        pass
コード例 #2
0
ファイル: test_gspawn.py プロジェクト: AbelMon/librarian
def test_with_timeout():
    """ Optional timeout paramter can be used to force a timeout """
    import time
    fn = mock.Mock()
    fn.side_effect = lambda: time.sleep(2)
    try:
        mod.call(fn, _timeout=0.1)
        assert False, 'Expected to raise'
    except mod.TimeoutError:
        pass
コード例 #3
0
ファイル: test_gspawn.py プロジェクト: AbelMon/librarian
def test_spawn_returns_callable_return_value():
    """ Return value of the callable is returned by spawn """
    fn = mock.Mock()
    ret = mod.call(fn)
    assert ret == fn.return_value
コード例 #4
0
ファイル: test_gspawn.py プロジェクト: AbelMon/librarian
def test_spawn_passes_kwargs():
    """ Keyword arguments are passed to the callable """
    fn = mock.Mock()
    mod.call(fn, foo='bar')
    fn.assert_called_once_with(foo='bar')
コード例 #5
0
ファイル: test_gspawn.py プロジェクト: AbelMon/librarian
def test_spawn_passes_arguments():
    """ Arguments are passed to the callable """
    fn = mock.Mock()
    mod.call(fn, 'foo')
    fn.assert_called_once_with('foo')
コード例 #6
0
ファイル: test_gspawn.py プロジェクト: AbelMon/librarian
def test_spawn_calls():
    """ Spawning will call the callable """
    fn = mock.Mock()
    mod.call(fn)
    assert fn.called