def test_invalid_result(self, trial_config): """Test that invalid objectives cannot be set""" t = Trial(**trial_config) # Make sure valid ones pass t.results = [ Trial.Result(name="asfda", type="constraint", value=None), Trial.Result(name="asfdb", type="objective", value=1e-5), ] # No results at all with pytest.raises(ValueError) as exc: t.results = [] assert "No objective found" in str(exc.value) # No objectives with pytest.raises(ValueError) as exc: t.results = [ Trial.Result(name="asfda", type="constraint", value=None) ] assert "No objective found" in str(exc.value) # Bad objective type with pytest.raises(ValueError) as exc: t.results = [ Trial.Result(name="asfda", type="constraint", value=None), Trial.Result(name="asfdb", type="objective", value=None), ] assert "Results must contain" in str(exc.value)
def test_invalid_result(self, exp_config): """Test that invalid objectives cannot be set""" t = Trial(**exp_config[1][1]) # Make sure valid ones pass t.results = [ Trial.Result(name='asfda', type='constraint', value=None), Trial.Result(name='asfdb', type='objective', value=1e-5) ] # No results at all with pytest.raises(ValueError) as exc: t.results = [] assert 'No objective found' in str(exc.value) # No objectives with pytest.raises(ValueError) as exc: t.results = [ Trial.Result(name='asfda', type='constraint', value=None) ] assert 'No objective found' in str(exc.value) # Bad objective type with pytest.raises(ValueError) as exc: t.results = [ Trial.Result(name='asfda', type='constraint', value=None), Trial.Result(name='asfdb', type='objective', value=None) ] assert 'Results must contain' in str(exc.value)
def _add_result(trial: Trial, y: float) -> Trial: trial = copy.deepcopy(trial) trial.results = [_result(y)] trial.status = "completed" return trial