Ejemplo n.º 1
0
    def test_get_task_num_from_pixels(self):
        offsets = generate_expected_offsets(30, 1920, 1080)
        frame_offsets = generate_expected_offsets(15, 1920, 1080)
        task_definition = RenderingTaskDefinition()
        task_definition.options = BlenderRendererOptions()
        task_definition.resolution = [1920, 1080]

        for k in range(1, 31):
            task_definition.options.use_frames = False
            num = BlenderTaskTypeInfo.get_task_num_from_pixels(
                6, offsets[k] + 1, task_definition, 30)
            assert num == k

            task_definition.options.use_frames = True
            task_definition.options.frames = range(30)
            num = BlenderTaskTypeInfo.get_task_num_from_pixels(
                1, 0, task_definition, 30, k)
            assert num == k

            i = (k - 1) % 15 + 1
            task_definition.options.frames = range(2)
            num = BlenderTaskTypeInfo.get_task_num_from_pixels(
                1, frame_offsets[i] + 3, task_definition, 30, (k - 1) / 15 + 1)
            assert num == k

        task_definition.options.use_frames = False
        assert BlenderTaskTypeInfo.get_task_num_from_pixels(
            5, 1200, task_definition, 30) == 30
Ejemplo n.º 2
0
    def _get_task_border(as_path=False):
        offsets = generate_expected_offsets(30, 800, 600)
        subtask = SubtaskState()

        definition = RenderingTaskDefinition()
        definition.options = BlenderRendererOptions()
        definition.options.use_frames = False
        definition.resolution = [800, 600]

        for k in range(1, 31):
            subtask.extra_data = {'start_task': k, 'end_task': k}
            border = BlenderTaskTypeInfo.get_task_border(subtask,
                                                         definition,
                                                         30,
                                                         as_path=as_path)
            assert min(border) == (0, offsets[k])
            assert max(border) == (797, offsets[k + 1] - 1)

        definition.options.use_frames = True
        definition.options.frames = list(range(2))
        offsets = generate_expected_offsets(15, 800, 600)

        for k in range(1, 31):
            subtask.extra_data = {'start_task': k, 'end_task': k}
            border = BlenderTaskTypeInfo.get_task_border(subtask,
                                                         definition,
                                                         30,
                                                         as_path=as_path)
            i = (k - 1) % 15 + 1
            assert min(border) == (0, offsets[i])
            assert max(border) == (798, offsets[i + 1] - 1)

        subtask.extra_data = {'start_task': 2, 'end_task': 2}
        definition.options.use_frames = True
        definition.options.frames = list(range(30))
        if as_path:
            assert BlenderTaskTypeInfo.get_task_border(
                subtask, definition, 30, as_path=as_path) == \
                [(0, 600), (800, 600), (800, 0), (0, 0)]
        else:
            assert BlenderTaskTypeInfo.get_task_border(subtask,
                                                       definition,
                                                       30,
                                                       as_path=as_path) == []

        definition.options.use_frames = False
        definition.resolution = (0, 0)
        assert BlenderTaskTypeInfo.get_task_border(subtask,
                                                   definition,
                                                   30,
                                                   as_path=as_path) == []
Ejemplo n.º 3
0
    def test_blender_customizer(self, mock_messagebox):
        self.logic.customizer = MainWindowCustomizer(self.gui.main_window,
                                                     self.logic)
        self.logic.register_new_task_type(
            BlenderTaskTypeInfo(TaskWidget(Ui_BlenderWidget),
                                BlenderRenderDialogCustomizer))
        self.logic.client = Mock()
        self.logic.client.config_desc = ClientConfigDescriptor()
        self.logic.client.config_desc.use_ipv6 = False
        self.logic.client.config_desc.max_price = 0
        self.logic.client.get_config.return_value = self.logic.client.config_desc
        self.logic.client.get_res_dirs.return_value = {'computing': self.path, 'received': self.path}
        self.logic.customizer.init_config()
        customizer = self.logic.customizer.new_task_dialog_customizer.task_customizer

        assert isinstance(customizer, FrameRendererCustomizer)
        assert not customizer.gui.ui.framesCheckBox.isChecked()
        customizer._change_options()
        assert customizer.options.frames == range(1, 11)
        customizer.gui.ui.framesCheckBox.setChecked(True)
        customizer.gui.ui.framesLineEdit.setText(u"{}".format("1;3;5-12"))
        customizer._change_options()
        assert customizer.options.frames == [1, 3] + range(5, 13)
        customizer.gui.ui.framesLineEdit.setText(u"{}".format("Not proper frames"))
        customizer._change_options()
        assert customizer.options.frames == [1, 3] + range(5, 13)
        mock_messagebox.assert_called_with(mock_messagebox.Critical, "Error",
                                           u"Wrong frame format. Frame list expected, e.g. 1;3;5-12.",
                                           ANY, ANY)
Ejemplo n.º 4
0
 def test_build_correct_format(self):
     task_type = BlenderTaskTypeInfo()
     task_dict = self._task_dictionary
     output_format = task_dict.get('options').get('format')
     definition = BlenderRenderTaskBuilder.build_full_definition(
         task_type, task_dict)
     self.assertEqual(definition.output_format, output_format)
Ejemplo n.º 5
0
 def test_build_unsupported_format(self):
     task_type = BlenderTaskTypeInfo()
     task_dict = self._task_dictionary
     output_format = 'JPG'
     task_dict['options']['format'] = output_format
     definition = BlenderRenderTaskBuilder.build_full_definition(
         task_type, task_dict)
     self.assertEqual(definition.output_format, 'PNG')
Ejemplo n.º 6
0
    def test_update_preview(self):
        bt = self.build_bt(300, 200, 10)
        dm = DirManager(self.tempdir)
        bt.initialize(dm)
        files = self.additional_dir_content([1])
        preview = files[0]
        img = Image.new("RGBA", (20, 200))
        img.save(preview, "PNG")
        bt._update_preview(preview, 3)

        preview = BlenderTaskTypeInfo.get_preview(bt, single=False)
        assert isinstance(preview, list)
        assert len(preview) == 1
        assert all(os.path.exists(p) for p in preview)

        preview = BlenderTaskTypeInfo.get_preview(bt, single=True)
        assert os.path.exists(preview)

        preview = BlenderTaskTypeInfo.get_preview(None, single=True)
        assert preview is None
Ejemplo n.º 7
0
    def test_customizer(self, file_dialog_mock):
        self.logic.client = Mock()
        self.logic.client.config_desc = Mock()
        self.logic.client.config_desc.max_price = 0
        self.logic.client.get_config.return_value = self.logic.client.config_desc
        self.logic.dir_manager = Mock()
        self.logic.dir_manager.root_path = self.path
        self.logic.customizer = Mock()

        register_task_types(self.logic)
        customizer = NewTaskDialogCustomizer(self.gui.main_window, self.logic)
        self.assertIsInstance(customizer, NewTaskDialogCustomizer)

        definition = RenderingTaskDefinition()
        renderer = BlenderTaskTypeInfo(Mock(), Mock())
        assert renderer.name == "Blender"
        assert renderer.options is not None
        definition.task_type = renderer.name
        definition.options = Mock()
        definition.options.use_frames = False
        definition.options.compositing = False
        resources = self.additional_dir_content([3])
        definition.resources = set(resources)
        self.logic.customizer = Mock()
        self.logic.task_types[renderer.name] = renderer
        customizer.load_task_definition(definition)
        with self.assertRaises(TypeError):
            customizer.load_task_definition(None)
        self.assertEqual(len(definition.resources), 3)
        customizer.gui.ui.taskNameLineEdit.setText("NEW NAME")
        definition2 = customizer._query_task_definition()
        self.assertEqual(definition2.task_name, "NEW NAME")
        file_dialog_mock.getOpenFileName.return_value = "/abc/def/ghi"

        definition.task_type = "UNKNOWN"
        with self.assertLogs(logger, level="ERROR"):
            customizer._load_task_type(definition)

        options = Options()
        customizer.set_options(options)
        assert customizer.logic.options == options

        customizer._NewTaskDialogCustomizer__test_task_button_clicked()
        customizer.test_task_computation_finished(True, 103139)
        self.assertEqual(customizer.task_state.definition.estimated_memory, 103139)
        self.assertTrue(customizer.gui.ui.finishButton.isEnabled())
        customizer._show_add_resource_dialog()
        self.assertFalse(customizer.gui.ui.finishButton.isEnabled())

        customizer._open_options()
Ejemplo n.º 8
0
 def output_extension(self):
     return BlenderTaskTypeInfo().output_formats[0]
Ejemplo n.º 9
0
    def test_update_frame_preview(self):
        file1 = self.temp_file_name('preview1.exr')
        file2 = self.temp_file_name('preview2.exr')
        file3 = self.temp_file_name('preview3.bmp')
        file4 = self.temp_file_name('preview4.bmp')

        bt = self.build_bt(300, 200, 2, frames=[1, 2, 3, 4])
        bt.preview_updaters = [
            PreviewUpdater(f, bt.res_x, bt.res_y, {
                1: 0,
                2: 99
            }) for f in [file1, file2, file3, file4]
        ]

        img1 = OpenEXR.OutputFile(file1, OpenEXR.Header(bt.res_x, 99))
        data = array.array('f', [1.0] * (bt.res_x * 99)).tostring()
        img1.writePixels({
            'R': data,
            'G': data,
            'B': data,
            'F': data,
            'A': data
        })
        img1.close()

        img2 = OpenEXR.OutputFile(file2, OpenEXR.Header(bt.res_x, 101))
        data = array.array('f', [1.0] * (bt.res_x * 101)).tostring()
        img2.writePixels({
            'R': data,
            'G': data,
            'B': data,
            'F': data,
            'A': data
        })
        img2.close()

        bt._update_frame_preview(file1, 1, part=1)
        assert bt.preview_updaters[0].perfect_match_area_y == 99
        self.assertTrue(bt.preview_updaters[0].perfectly_placed_subtasks == 1)

        bt._update_frame_preview(file2, 1, part=2)
        self.assertTrue(bt.preview_updaters[0].perfect_match_area_y == 200)
        self.assertTrue(bt.preview_updaters[0].perfectly_placed_subtasks == 2)

        bt.preview_file_path = []
        bt.preview_file_path.append(file3)
        bt.preview_task_file_path = []
        bt.preview_task_file_path.append(file4)

        img1 = OpenEXR.OutputFile(file1, OpenEXR.Header(bt.res_x, 99))
        data = array.array('f', [1.0] * (bt.res_x * 99)).tostring()
        img1.writePixels({
            'R': data,
            'G': data,
            'B': data,
            'F': data,
            'A': data
        })
        img1.close()

        bt._update_frame_preview(file1, 1, part=1, final=True)
        img = Image.open(file3)
        self.assertTrue(img.size == (300, 200))
        img = Image.open(file4)
        self.assertTrue(img.size == (300, 200))

        preview = BlenderTaskTypeInfo.get_preview(bt, single=False)
        assert isinstance(preview, list)
        assert len(preview) == 4
        assert all(os.path.exists(p) for p in preview)

        preview = BlenderTaskTypeInfo.get_preview(bt, single=True)
        assert isinstance(preview, basestring)
        assert os.path.exists(preview)

        preview = BlenderTaskTypeInfo.get_preview(None, single=True)
        assert preview is None

        bt.restart()
        for preview in bt.preview_updaters:
            assert preview.chunks == {}
            assert preview.perfect_match_area_y == 0
            assert preview.perfectly_placed_subtasks == 0