Exemple #1
0
def validate_outputs_config(config, raise_for_rest: bool = False) -> None:
    if not config:
        return None
    try:
        OutputsConfig.from_dict(config)
    except MarshmallowValidationError as e:
        if raise_for_rest:
            raise ValidationError(e)
        else:
            raise DjangoValidationError(e)
Exemple #2
0
    def test_set_outputs(self):
        experiment_outputs = [
            '{}'.format(self.experiment.id),
            '{}'.format(self.project_experiment.id),
            self.project_experiment.name,
            '{}.{}'.format(self.project.name, self.project_experiment.name),
            '{}/{}'.format(self.project.name, self.project_experiment.name),
            '{}.{}.{}'.format(self.user.username, self.project.name,
                              self.project_experiment.name),
            '{}/{}/{}'.format(self.user.username, self.project.name,
                              self.project_experiment.name),
        ]
        job_outputs = [
            '{}'.format(self.job.id),
            '{}'.format(self.project_job.id),
            self.project_job.name,
            '{}.{}'.format(self.project.name, self.project_job.name),
            '{}/{}'.format(self.project.name, self.project_job.name),
            '{}.{}.{}'.format(self.user.username, self.project.name,
                              self.project_job.name),
            '{}/{}/{}'.format(self.user.username, self.project.name,
                              self.project_job.name),
        ]
        outputs_config = OutputsConfig(
            jobs=job_outputs, experiments=experiment_outputs).to_dict()

        experiment = ExperimentFactory(user=self.user, project=self.project)
        assert experiment.outputs is None
        experiment.outputs = outputs_config
        assert experiment.outputs is not None
        assert len(experiment.outputs_experiments) == len(experiment_outputs)
        assert len(experiment.outputs_jobs) == len(job_outputs)
        set_outputs(instance=experiment)
        del experiment.outputs_config
        del experiment.outputs_experiments
        del experiment.outputs_jobs
        assert len(experiment.outputs_experiments) == 2
        assert len(experiment.outputs_jobs) == 2

        job = JobFactory(user=self.user, project=self.project)
        assert job.outputs is None
        job.outputs = outputs_config
        assert job.outputs is not None
        assert job.outputs is not None
        assert len(job.outputs_experiments) == len(experiment_outputs)
        assert len(job.outputs_jobs) == len(job_outputs)
        set_outputs(instance=job)
        del job.outputs_config
        del job.outputs_experiments
        del job.outputs_jobs
        assert len(job.outputs_experiments) == 2
        assert len(job.outputs_jobs) == 2
Exemple #3
0
 def outputs_config(self):
     return OutputsConfig.from_dict(self.outputs) if self.outputs else None
Exemple #4
0
 def outputs_config(self) -> Optional['OutputsConfig']:
     return OutputsConfig.from_dict(self.outputs) if self.outputs else None