Example #1
0
    def test_load_project_valid_path(self):
        project_handler = ProjectHandler()
        path = generate_sample_project().path
        project_handler.load_project(path)

        self.assertIsNotNone(project_handler.current_project)

        remove_project(path)
Example #2
0
 def test_generate_file_string_missing_template(self):
     frames: List[dict] = []
     for x in range(5):
         frames.append(frame)
     project = generate_sample_project()
     project.storyboard.frames = frames
     EasyLayout.template_path = "/not/a/valid/path"
     self.assertRaises(FileNotFoundError,
                       EasyLayout.generate_file_string(project.storyboard))
Example #3
0
    def test_create_new_project_has_current_project(self):
        project_handler = ProjectHandler()
        path = f"/tmp/test_project_{str(datetime.now().timestamp()).replace('.', '_')}"
        os.mkdir(path)
        project_handler.load_project(generate_sample_project().path)

        self.assertIsNone(project_handler.create_new_project(path))

        remove_project(project_handler.current_project.path)
        remove_project(path)
Example #4
0
    def test_save_project_current_project(self):
        project_handler = ProjectHandler()
        project = generate_sample_project()
        project_handler.current_project = project

        storyboard = Storyboard.generate_from_file(
            os.path.join(project.path, "storyboard.json"))
        self.assertEqual(project.storyboard, storyboard)

        project.storyboard.title = "Is now different"
        project_handler.save_project()

        storyboard_after = Storyboard.generate_from_file(
            os.path.join(project.path, "storyboard.json"))
        self.assertEqual(project.storyboard, storyboard_after)
        self.assertNotEqual(storyboard_after, storyboard)

        remove_project(project_handler.current_project.path)
Example #5
0
 def test_generate_file_string_full_page(self):
     frames: List[dict] = []
     for x in range(5):
         frames.append(frame)
     project = generate_sample_project()
     project.storyboard.frames = frames
     result = EasyLayout.generate_file_string(project)
     expected_result = load_easy_layout_template()
     expected_result = expected_result.replace("%*imagepath*",
                                               project.images_directory)
     expected_result = expected_result.replace("%*title*",
                                               project.storyboard.title)
     expected_result = expected_result.replace("%*author*",
                                               project.storyboard.author)
     expected_result = expected_result.replace(
         "%*frames*",
         EasyLayout._generate_frames_string(project.storyboard.frames))
     self.assertEqual(result, expected_result)
Example #6
0
 def test_run_file_already_exists(self):
     GenerateTexFileStep.get_file_name = get_tex_file_name
     job = Job(
         layout=LayoutName.EASY_LAYOUT.value, project=generate_sample_project()
     )
     for x in range(2):
         job.project.storyboard.frames.append(
             dict(image=sample_image_path, image_description="image_description")
         )
     tex_file_path = os.path.join(
         job.project.output_directory,
         get_tex_file_name(job.project.storyboard.title),
     )
     write_file(tex_file_path, "nothing special")
     GenerateTexFileStep.run(job)
     self.assertEqual(job.status, Status.GENERATE_TEX_ERROR)
     self.assertEqual(
         job.status_data["message"],
         f"Cannot save the .tex file, path {tex_file_path} already exists",
     )
     clear_output_directory(job)
Example #7
0
    def test_run_valid(self):
        GenerateTexFileStep.get_file_name = get_tex_file_name
        job = Job(
            layout=LayoutName.EASY_LAYOUT.value, project=generate_sample_project()
        )
        GenerateTexFileStep.run(job)
        expected_tex_file_path = os.path.join(
            job.project.output_directory,
            get_tex_file_name(job.project.storyboard.title),
        )

        self.assertEqual(job.status, Status.VALID)
        self.assertTrue(os.path.exists(job.tex_file_path))

        file_content = load_file_as_string(job.tex_file_path)
        self.assertEqual(job.tex_file_path, expected_tex_file_path)
        self.assertEqual(
            file_content,
            expected_file_content.replace("%*imagepath*", job.project.images_directory),
        )
        clear_output_directory(job)
Example #8
0
def generate_project():
    return generate_sample_project()
def generate_job():
    return Job(layout=LayoutName.EASY_LAYOUT.value, project=generate_sample_project())
 def test_run_with_invalid_layout(self):
     job = Job(layout="SuperHeroLayout", project=generate_sample_project())
     self.assertFalse(LayoutValidationStep.run(job))
 def test_run_with_valid_layout(self):
     job = Job(layout=LayoutName.EASY_LAYOUT.value,
               project=generate_sample_project())
     self.assertTrue(LayoutValidationStep.run(job))
Example #12
0
    def test_load_project_has_current_project(self):
        project_handler = ProjectHandler()
        project = generate_sample_project()
        project_handler.current_project = project

        self.assertIsNone(project_handler.load_project(project.path))