Пример #1
0
def test_modelpipeline_classmethod_constructor_errors(mock_future):
    # catch 404 error if model isn't found and throw ValueError
    mock_client = mock.Mock()
    response = namedtuple('Reponse', ['content', 'response', 'reason',
                                      'status_code'])(False, None, None, 404)
    mock_future.side_effect = CivisAPIError(response)
    with pytest.raises(ValueError):
        _model.ModelPipeline.from_existing(1, 1, client=mock_client)
Пример #2
0
def test_modelpipeline_init_err():
    mock_client = mock.MagicMock()
    r = Response({'content': None, 'status_code': 9999, 'reason': None})
    mock_client.templates.get_scripts.side_effect = CivisAPIError(r)
    with pytest.raises(NotImplementedError):
        _model.ModelPipeline(LogisticRegression(),
                             'test',
                             etl=LogisticRegression(),
                             client=mock_client)
    # clean up
    del _model._NEWEST_CIVISML_VERSION
Пример #3
0
 def mock_api_error(job_id, run_id):
     if counter['failures'] < num_failures:
         counter['failures'] += 1
         if failure_is_error:
             raise CivisAPIError(mock.MagicMock())
         else:
             return response.Response({'id': run_id,
                                       'container_id': job_id,
                                       'state': 'failed'})
     else:
         return response.Response({'id': run_id,
                                   'container_id': job_id,
                                   'state': 'succeeded'})
Пример #4
0
def test_train_data_exc_handling(mock_load_table, m_sleep):
    def poller(*args, **kwargs):
        return Response({'state': 'succeeded'})
    mock_client = mock.MagicMock()
    mock_client.scripts.get_containers_runs = poller
    mf = _model.ModelFuture(job_id=1, run_id=2, client=mock_client)
    mf._train_data_fname = 'placeholder.csv'

    # check we catch 404 error and raise some intelligible
    r = Response({'content': None, 'status_code': 404, 'reason': None})
    mock_load_table.side_effect = [CivisAPIError(r)]
    with pytest.raises(ValueError):
        mf.train_data
Пример #5
0
def test_get_service__not_found(mock_client, classes_mock):
    classes_mock.return_value = {}
    sc = ServiceClient(MOCK_SERVICE_ID)
    err_resp = response.Response({
        'status_code': 404,
        'error': 'not_found',
        'errorDescription': 'The requested resource could not be found.',
        'content': True})
    err_resp.json = lambda: err_resp.json_data

    mock_client.return_value.services.get.side_effect = CivisAPIError(err_resp)

    with pytest.raises(CivisAPIError) as excinfo:
        _get_service(sc)

    expected_error = ('(404) The requested resource could not be found.')
    assert str(excinfo.value) == expected_error
Пример #6
0
def test_cancel_finished_job():
    # If we try to cancel a completed job, we get a 404 error.
    # That shouldn't be sent to the user.

    # Set up a mock client which will give an exception when
    # you try to cancel any job.
    c = _setup_client_mock()
    err_resp = response.Response({
        'status_code': 404,
        'error': 'not_found',
        'errorDescription': 'The requested resource could not be found.',
        'content': True})
    err_resp.json = lambda: err_resp.json_data
    c.scripts.post_cancel.side_effect = CivisAPIError(err_resp)
    c.scripts.post_containers_runs.return_value.state = 'running'

    fut = ContainerFuture(-10, 100, polling_interval=1, client=c,
                          poll_on_creation=False)
    assert not fut.done()
    assert fut.cancel() is False
Пример #7
0
    def _make_request(self,
                      method,
                      path=None,
                      params=None,
                      data=None,
                      **kwargs):
        url = self._build_path(path)

        with requests.Session() as sess:
            auth_service_session(sess, self._client)
            with self._lock:
                response = sess.request(method,
                                        url,
                                        json=data,
                                        params=params,
                                        **kwargs)

        if not response.ok:
            raise CivisAPIError(response)

        return response
Пример #8
0
 def mock_submit(fn='', *args, **kwargs):
     if counter['n_failed'] < num_failures:
         counter['n_failed'] += 1
         raise CivisAPIError(mock.MagicMock())
     else:
         return mock.MagicMock(spec=ContainerFuture)
Пример #9
0
 def pre_2p0_template(id=None, **kwargs):
     if id > 9113:
         raise CivisAPIError(r)
     return {}