Beispiel #1
0
 def test_run_valid_frame_data(self):
     project = generate_project()
     job = Job(layout=LayoutName.EASY_LAYOUT.value, project=project)
     for x in range(2):
         job.project.storyboard.frames.append(
             dict(image=sample_image_path,
                  image_description="image_description"))
     FrameDataValidationStep.run(job)
     self.assertEqual(job.status, Status.VALID)
Beispiel #2
0
 def test_run_data_is_missing(self):
     error_layout = "Frame_{}: {} is missing"
     project = generate_project()
     job = Job(layout=LayoutName.EASY_LAYOUT.value, project=project)
     job.project.storyboard.frames.append(dict(image="path_to_file"))
     job.project.storyboard.frames.append(
         dict(image_description="image_description"))
     FrameDataValidationStep.run(job)
     self.assertEqual(job.status, Status.INVALID_DATA)
     self.assertEqual(
         job.status_data["missing_data"]["0"],
         error_layout.format(0, "image_description"),
     )
     self.assertEqual(job.status_data["missing_data"]["1"],
                      error_layout.format(1, "image"))
 def test_job_worker_run_with_error(self):
     job = generate_job()
     job.project.storyboard.frames[0] = dict(image=12,)
     JobWorker.run_job(
         job,
         [
             LayoutValidationStep(),
             FrameDataValidationStep(),
             GenerateTexFileStep(),
             CompileTexStep(),
         ],
     )
     self.assertEqual(job.status, Status.INVALID_DATA)
     self.assertEqual(
         job.status_data,
         dict(
             missing_data={
                 # the structure with a number as string in the dict is dirty
                 # todo Change number as string inside the dict!
                 "0": "Frame_0: image_description is missing"
             },
             wrong_data_type={
                 # the structure with a number as string in the dict is dirty
                 # todo Change number as string inside the dict!
                 "0": "Frame_0: image is from type int instead of str"
             },
         ),
     )
     self.assertEqual(job.step, StepType.VALIDATE_DATA)
Beispiel #4
0
 def test_run_data_mixed_errors(self):
     wrong_type_error = "Frame_{}: {} is from type {} instead of {}"
     missing_data_error = "Frame_{}: {} is missing"
     project = generate_project()
     job = Job(layout=LayoutName.EASY_LAYOUT.value, project=project)
     job.project.storyboard.frames.append(dict(image=120))
     job.project.storyboard.frames.append(
         dict(image="path_to_file", image_description=120))
     FrameDataValidationStep.run(job)
     self.assertEqual(job.status, Status.INVALID_DATA)
     self.assertEqual(
         job.status_data["missing_data"]["0"],
         missing_data_error.format(0, "image_description"),
     )
     self.assertEqual(
         job.status_data["wrong_data_type"]["1"],
         wrong_type_error.format(1, "image_description", int.__name__,
                                 str.__name__),
     )
 def test_job_worker_without_errors(self):
     job = generate_job()
     JobWorker.run_job(
         job,
         [
             LayoutValidationStep(),
             FrameDataValidationStep(),
             GenerateTexFileStep(),
             CompileTexStep(),
         ],
     )
     self.assertEqual(job.status, Status.VALID)
     self.assertEqual(job.status_data, dict())
     self.assertEqual(job.step, StepType.FINISHED)
     remove_files(job.tex_file_path.replace(".tex", ""))
Beispiel #6
0
class JobWorker:
    # List of steps
    steps: List[Step] = [
        LayoutValidationStep(),
        FrameDataValidationStep(),
        GenerateTexFileStep(),
        CompileTexStep(),
    ]

    @staticmethod
    def run_job(job: Job, steps: List[Step] = None):
        if not steps:
            job.status_data[
                "job_worker_error"] = "The specified list of steps, is empty or None. The default list will used instead!"
            steps = JobWorker.steps
        for step in steps:
            if job.status is Status.VALID:
                step.run(job)

        if job.status is Status.VALID:
            job.step = StepType.FINISHED