def test_get_socket_exception(self, cb, mocker): mocker.patch('socket.socket') mocker.patch('socket.getaddrinfo', side_effect=BlynkError('BE')) with pytest.raises(BlynkError) as b_err: cb._get_socket() assert 'Connection with the Blynk server failed: BE' in str( b_err.value)
def test_connect_exception(self, bl, mocker): with mocker.patch.object(bl, 'connected', return_value=False): with mocker.patch.object(bl, '_get_socket', return_value=None): with mocker.patch.object(bl, '_authenticate', side_effect=BlynkError()): with mocker.patch.object(bl, 'disconnect', return_value=None): with mocker.patch('time.sleep', return_value=None): mocker.spy(bl, 'disconnect') result = bl.connect(0.001) assert result is False assert bl.disconnect.call_count > 1