Пример #1
0
    def test_find_by_trial_and_step(session: Session) -> None:

        trial = TestTrialIntermediateValueModel._create_model(session)
        trial_intermediate_value = TrialIntermediateValueModel.find_by_trial_and_step(
            trial, 0, session)
        assert trial_intermediate_value is not None
        assert 10 == trial_intermediate_value.intermediate_value
        assert TrialIntermediateValueModel.find_by_trial_and_step(
            trial, 1, session) is None
Пример #2
0
    def test_cascade_delete_on_trial(session: Session) -> None:

        trial = TestTrialIntermediateValueModel._create_model(session)
        trial.intermediate_values.append(
            TrialIntermediateValueModel(trial_id=1, step=1, intermediate_value=20)
        )
        session.commit()

        assert 2 == len(TrialIntermediateValueModel.where_trial_id(trial.trial_id, session))

        session.delete(trial)
        session.commit()

        assert 0 == len(TrialIntermediateValueModel.where_trial_id(trial.trial_id, session))
Пример #3
0
    def test_where_trial_id(session: Session) -> None:

        trial = TestTrialIntermediateValueModel._create_model(session)
        trial_intermediate_values = TrialIntermediateValueModel.where_trial_id(
            trial.trial_id, session)
        assert 1 == len(trial_intermediate_values)
        assert 0 == trial_intermediate_values[0].step
        assert 10 == trial_intermediate_values[0].intermediate_value
Пример #4
0
    def _create_model(session: Session) -> TrialModel:

        direction = StudyDirectionModel(direction=StudyDirection.MINIMIZE, objective=0)
        study = StudyModel(study_id=1, study_name="test-study", directions=[direction])
        trial = TrialModel(trial_id=1, study_id=study.study_id, state=TrialState.COMPLETE)
        session.add(study)
        session.add(trial)
        session.add(
            TrialIntermediateValueModel(trial_id=trial.trial_id, step=0, intermediate_value=10)
        )
        session.commit()
        return trial