示例#1
0
    def load_from_path(path: str):
        if not os.path.exists(path):
            raise FileNotFoundError

        storyboard: Storyboard

        if os.path.isdir(path):
            tmp_storyboard_path = os.path.join(path, "storyboard.json")
            if not os.path.exists(tmp_storyboard_path):
                raise StoryboardFileNotFound(
                    f"No storyboard file found in {tmp_storyboard_path}."
                    f"Please create a new project or try another path.")
            storyboard_path = tmp_storyboard_path
        else:
            storyboard_path = path
            path = get_directory_of_file(path)

        file_type = os.path.splitext(storyboard_path)[1]
        if file_type == ".json":
            file_string = load_file_as_string(storyboard_path)
            file_json = json.loads(file_string)
            if not Storyboard.is_valid_storyboard_dict(file_json):
                raise InvalidStoryboard(
                    f"The chosen storyboard is not valid, please check, that all required attributes are set!"
                )
        else:
            raise StoryboardFileNotFound(
                f"Storyboard file if from type {file_type}, "
                f"instead of .json. Please check that the file has the ending .json and is a valid storyboard file!"
            )

        storyboard: Storyboard = Storyboard.generate_from_file(storyboard_path)
        return Project(path=path, storyboard=storyboard)
示例#2
0
 def test_save_project(self):
     generate_temporary_project_folder()
     expected_storyboard = Storyboard(title="test storyboard",
                                      author="Bernhard Brueckenpfeiler",
                                      frames=[])
     project = Project.load_from_path(project_folder_path)
     project.storyboard = expected_storyboard
     project.save_project()
     storyboard = Storyboard.generate_from_file(
         os.path.join(project_folder_path, "storyboard.json"))
     self.assertEquals(storyboard, expected_storyboard)
     remove_temporary_project_folder()
示例#3
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)
def generate_storyboard():
    frame = dict(
        image=os.path.join(sample_data_path, "sample_image.jpg"),
        image_description="image description",
    )
    return Storyboard(
        title="test storyboard",
        author="Bernhard Brueckpfeiler",
        frames=[frame, frame, frame],
    )
示例#5
0
 def test_is_valid_storyboard_dict_invalid(self):
     storyboard_dict = dict(
         title="test storyboard",
         missing_author="Bernhard Brueckenpfeiler",
         frames=[
             dict(
                 image=os.path.join(sample_data_path, "sample_image.jpg"),
                 image_description="image_description",
             )
         ],
     )
     is_valid = Storyboard.is_valid_storyboard_dict(storyboard_dict)
     self.assertFalse(is_valid)
示例#6
0
 def test_generate_from_string_invalid(self):
     json_string = json.dumps(
         dict(
             title="test storyboard",
             missing_author="Bernhard Brueckenpfeiler",
             frames=[
                 dict(
                     image=os.path.join(sample_data_path,
                                        "sample_image.jpg"),
                     image_description="image_description",
                 )
             ],
         ))
     storyboard = Storyboard.generate_from_string(json_string)
     self.assertIsNone(storyboard)
示例#7
0
 def test_init(self):
     storyboard = Storyboard(title="test storyboard",
                             author="Bernhard Brueckenpfeiler",
                             frames=[])
     generate_temporary_project_folder(False, False)
     project = Project(path=project_folder_path, storyboard=storyboard)
     self.assertIsNotNone(project)
     self.assertEqual(project.path, project_folder_path)
     self.assertEqual(project.storyboard, storyboard)
     self.assertEqual(project.image_hashes, [])
     self.assertEqual(project.images_directory,
                      os.path.join(project_folder_path, "images"))
     self.assertEqual(project.output_directory,
                      os.path.join(project_folder_path, "output"))
     remove_temporary_project_folder()
示例#8
0
 def test_generate_image_hashes(self):
     generate_temporary_project_folder()
     storyboard = Storyboard(title="test storyboard",
                             author="Bernhard Brueckenpfeiler",
                             frames=[])
     project = Project(path=project_folder_path, storyboard=storyboard)
     expected_image_hashes = [
         dict(file_type=".png",
              hash="00087e7ffffe2c00",
              file_name="sample_image_2"),
         dict(file_type=".jpg",
              hash="7f3f1e0c003e381f",
              file_name="sample_image_1"),
     ]
     self.assertEquals(project.image_hashes, expected_image_hashes)
     remove_temporary_project_folder()
示例#9
0
    def generate_new_project(path: str):
        if not os.path.exists(path) or len(os.listdir(path)) is not 0:
            raise DirectoryIsNotEmpty(
                f"The directory {path} is not empty or does not exists! "
                f"Please create an empty directory for the project.")

        storyboard_path = os.path.join(path, "storyboard.json")
        if not os.path.exists(storyboard_path):
            copyfile(
                os.path.join(sample_data_path, "sample_storyboard.json"),
                storyboard_path,
            )
        os.mkdir(os.path.join(path, "output"))
        os.mkdir(os.path.join(path, "images"))
        storyboard: Storyboard = Storyboard.generate_from_file(storyboard_path)
        return Project(path=path, storyboard=storyboard)
示例#10
0
    def test_generate_from_file_valid(self):
        json_string = json.dumps(
            dict(
                title="test storyboard",
                author="Bernhard Brueckenpfeiler",
                frames=[
                    dict(
                        image=os.path.join(sample_data_path,
                                           "sample_image.jpg"),
                        image_description="image_description",
                    )
                ],
            ))
        storyboard_file_path = os.path.join(
            "/tmp/", f"temporary_test_file_{str(hash('test_directory'))}.json")
        write_file(storyboard_file_path, json_string)

        storyboard = Storyboard.generate_from_file(storyboard_file_path)
        self.assertEqual(storyboard, generate_storyboard())
示例#11
0
def generate_storyboard():
    return Storyboard(title="test title",
                      author="Bernhard Brueckenpfeiler",
                      frames=[])
示例#12
0
import unittest

from backend.classes.render_job import Job
from backend.classes.steps.generate_tex_file_step import GenerateTexFileStep
from backend.classes.storyboard import Storyboard
from backend.config import output_path, sample_data_path
from backend.sample_data.sample_generator import (
    generate_sample_project,
    remove_project,
)
from backend.utils.enums import LayoutName, Status
from backend.utils.utils import write_file, load_file_as_string

sample_image_path = os.path.join(sample_data_path, "sample_image.jpg")
storyboard = Storyboard(
    title="test title", author="Bernhard Brueckenpfeiler", frames=[]
)
expected_file_content = """\\documentclass[10pt]{scrreprt}
\\usepackage[
	a4paper,
	margin=2cm
]{geometry}
\\usepackage{graphicx}
\\usepackage[german]{babel}
\\usepackage[utf8]{inputenc}
\\usepackage{fancyhdr}
\\usepackage{csquotes}
%\\usepackage{fontspec}

\\graphicspath{%*imagepath*}