def test_table_None(mock_res, mock_lt): mock_lt.side_effect = FileNotFoundError() c = setup_client_mock(3, 7) mf = _model.ModelFuture(3, 7, client=c) assert mf.table is None mock_lt.assert_called_once_with(3, 7, 'predictions.csv', index_col=0, client=c)
def file_id_from_run_output(name, job_id, run_id, regex=False, client=None): """Find the file ID of a File run output with the name "name" The run output is required to have type "File". If using an approximate match and multiple names match the provided string, return only the first file ID. Parameters ---------- name : str The "name" field of the run output you wish to retrieve job_id : int run_id : int regex : bool, optional If False (the default), require an exact string match between ``name`` and the name of the run output. If True, search for a name which matches the regular expression ``name`` and retrieve the first found. client : :class:`civis.APIClient`, optional If not provided, an :class:`civis.APIClient` object will be created from the :envvar:`CIVIS_API_KEY`. Returns ------- file_id : int The ID of a Civis File with name matching ``name`` Raises ------ IOError If the provided job ID and run ID combination can't be found FileNotFoundError If the run exists, but ``name`` isn't in its run outputs See Also -------- APIClient.scripts.list_containers.runs_outputs """ client = APIClient() if client is None else client # Retrieve run outputs try: outputs = client.scripts.list_containers_runs_outputs(job_id, run_id) except CivisAPIError as err: if err.status_code == 404: six.raise_from( IOError('Could not find job/run ID {}/{}'.format( job_id, run_id)), err) else: raise # Find file in the run outputs. if not regex: # Require an exact match on the "name" string. obj = find_one(outputs, name=name, object_type='File') else: # Search for a filename which contains the "name" string obj_matches = [ o for o in outputs if re.search(name, o.name) and o.object_type == 'File' ] if len(obj_matches) > 1: log.warning('Found %s matches to "%s". Returning the first.', len(obj_matches), name) obj = None if not obj_matches else obj_matches[0] if obj is None: prefix = "A file containing the pattern" if regex else "File" raise FileNotFoundError('{} "{}" is not an output of job/run ID ' '{}/{}.'.format(prefix, name, job_id, run_id)) return obj['object_id']
def test_set_model_exception_validation_metadata(): trn = {'run': {'status': 'succeeded'}} val = {'run': {'status': 'exception', 'stack_trace': 'this is a trace'}} exc = FileNotFoundError('Hahaha, zero mocks here!') _test_set_model_exc(trn, val, exc)
def test_set_model_exception_training_metadata(): trn = {'run': {'status': 'exception', 'stack_trace': 'this is a trace'}} val = None exc = FileNotFoundError('Look, no mocks!') _test_set_model_exc(trn, val, exc)