def test_create_kernel_raises_err_with_abnormal_status(mocker): mock_req_obj = mock.Mock() mock_req_obj.send.return_value = mock.MagicMock(status=400) mocker.patch('ai.backend.client.kernel.Request', return_value=mock_req_obj) with pytest.raises(BackendAPIError): Kernel.get_or_create('python')
def test_create_kernel_url(mocker): mock_req_obj = mock.Mock() mock_req_obj.send.return_value = mocker.MagicMock(status=201, json=mock.MagicMock()) mock_req = mocker.patch('ai.backend.client.kernel.Request', return_value=mock_req_obj) Kernel.get_or_create('python') mock_req.assert_called_once_with('POST', '/kernel/create', mocker.ANY) mock_req_obj.send.assert_called_once_with() mock_req_obj.send.return_value.json.assert_called_once_with()
def test_create_kernel_return_id_only(mocker): mock_json_func = lambda: {'kernelId': 'mock_kernel_id'} mock_req_obj = mock.Mock() mock_req_obj.send.return_value = mock.MagicMock(status=201, json=mock_json_func) mocker.patch('ai.backend.client.kernel.Request', return_value=mock_req_obj) k = Kernel.get_or_create('python') assert k.kernel_id == mock_json_func()['kernelId']
def run_create_kernel(_idx): begin = time.monotonic() try: k = Kernel.get_or_create('python3') ret = k.kernel_id except: log.exception('run_create_kernel') ret = None finally: end = time.monotonic() t = end - begin return t, ret
def test_kernel_lifecycles(defconfig): kernel = Kernel.get_or_create('python:latest') kernel_id = kernel.kernel_id info = kernel.get_info() assert info['lang'] == 'python:latest' assert info['numQueriesExecuted'] == 1 info = kernel.get_info() assert info['numQueriesExecuted'] == 2 kernel.destroy() # kernel destruction is no longer synchronous! time.sleep(2.0) with pytest.raises(BackendAPIError) as e: info = Kernel(kernel_id).get_info() assert e.value.args[0] == 404
def py3_kernel(): kernel = Kernel.get_or_create('python:latest') yield kernel kernel.destroy()
def test_deprecated_api(): with pytest.raises(AssertionError): Kernel.get_or_create('python')