def test_presets(self): tdf = RenderingTaskDefinition() tdf.subtasks_count = 12 tdf.options = "Some option" tdf.optimize_total = True tdf.verification_options = "Option" tdf.resolution = [1111, 2222] tdf.output_format = ".exr" preset = tdf.make_preset() assert len(preset) == 6 assert preset["subtasks_count"] == 12 assert preset["options"] == "Some option" assert preset["optimize_total"] assert preset["verification_options"] == "Option" assert preset["output_format"] == ".exr" assert preset["resolution"] == [1111, 2222] tdf2 = RenderingTaskDefinition() assert tdf2.subtasks_count == 0 assert tdf2.options is None assert not tdf2.optimize_total assert tdf2.verification_options is None assert tdf2.resolution == [0, 0] assert tdf2.output_format == "" tdf2.load_preset(preset) assert tdf2.subtasks_count == 12 assert tdf2.options == "Some option" assert tdf2.optimize_total assert tdf2.verification_options == "Option" assert tdf2.resolution == [1111, 2222] assert tdf2.output_format == ".exr"
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
def get_test_lux_task(self): td = RenderingTaskDefinition() lro = LuxRenderOptions() td.options = lro dm = DirManager(self.path) lb = LuxRenderTaskBuilder("ABC", td, self.path, dm) return lb.build()
def test_build(self): definition = RenderingTaskDefinition() definition.options = BlenderRendererOptions() builder = BlenderRenderTaskBuilder(node_name="ABC", task_definition=definition, root_path=self.tempdir, dir_manager=DirManager( self.tempdir)) blender_task = builder.build() self.assertIsInstance(blender_task, BlenderRenderTask)
def test_build(self): definition = RenderingTaskDefinition() definition.subtasks_count = 1 definition.options = BlenderRendererOptions() builder = BlenderRenderTaskBuilder(owner=Node(), task_definition=definition, dir_manager=DirManager( self.tempdir)) blender_task = builder.build() self.assertIsInstance(blender_task, BlenderRenderTask)
def _create_blender_task(self, dir_manager): definition = RenderingTaskDefinition() definition.options = BlenderRendererOptions() definition.task_id = "deadbeef" definition.task_type = "Blender" task_file_name = os.path.join(self.path, 'task_file.gt') with open(task_file_name, 'wb') as task_file: task_file.write(jsonpickle.dumps(definition)) return task_file_name
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) == []
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()
def test_compositing(self): task_definition = RenderingTaskDefinition() task_definition.options = BlenderRendererOptions() task_definition.options.use_frames = True task_definition.options.frames = [7, 8, 10] task_definition.main_scene_file = self.temp_file_name("example.blend") task_definition.output_file = self.temp_file_name('output') task_definition.output_format = 'PNG' task_definition.resolution = [2, 300] task_definition.task_id = "ABC" def _get_blender_task(task_definition, total_tasks=6): return BlenderRenderTask( owner=Node(node_name="exmaple-node-name"), task_definition=task_definition, total_tasks=total_tasks, root_path=self.tempdir, ) # Compostiting set to False task_definition.options.compositing = False bt = _get_blender_task(task_definition) assert not bt.compositing # Compositing True, use frames, more subtasks than frames task_definition.options.compositing = True bt = _get_blender_task(task_definition) assert not bt.compositing # Compositing True, use frames, as many subtasks as frames bt = _get_blender_task(task_definition, 3) assert not bt.compositing # Compositing True, use frames, less subtasks than frames bt = _get_blender_task(task_definition, 1) assert not bt.compositing # Compositing True, use frames is False, as many subtask as frames task_definition.options.use_frames = False bt = _get_blender_task(task_definition, 3) assert not bt.compositing
def setUp(self): super(TestBlenderFrameTask, self).setUp() program_file = self.temp_file_name('program') task_definition = RenderingTaskDefinition() task_definition.options = BlenderRendererOptions() task_definition.options.compositing = False task_definition.options.use_frames = True task_definition.options.frames = [7, 8, 10] task_definition.main_scene_file = self.temp_file_name("example.blend") task_definition.output_file = self.temp_file_name('output') task_definition.output_format = 'PNG' task_definition.resolution = [2, 300] self.bt = BlenderRenderTask( node_name="example-node-name", task_definition=task_definition, total_tasks=6, root_path=self.tempdir, ) dm = DirManager(self.path) self.bt.initialize(dm)
def setUp(self): super(TestBlenderFrameTask, self).setUp() task_definition = RenderingTaskDefinition() task_definition.options = BlenderRendererOptions() task_definition.options.compositing = False task_definition.options.use_frames = True task_definition.options.frames = [7, 8, 10] task_definition.main_scene_file = self.temp_file_name("example.blend") task_definition.output_file = self.temp_file_name('output') task_definition.output_format = 'PNG' task_definition.resolution = [200, 300] task_definition.task_id = str(uuid.uuid4()) BlenderRenderTask.VERIFICATION_QUEUE._reset() self.bt = BlenderRenderTask( owner=Node(node_name="example-node-name"), task_definition=task_definition, total_tasks=6, root_path=self.tempdir, ) dm = DirManager(self.path) self.bt.initialize(dm)
def _get_frame_task(self, use_frames=True, num_tasks=3): files_ = self.additional_dir_content([3]) rt = RenderingTaskDefinition() rt.options = FrameRendererOptions() rt.options.use_frames = use_frames rt.options.frames = list(range(6)) rt.main_scene_file = files_[1] rt.output_format = "PNG" rt.output_file = files_[2] rt.resources = [] rt.resolution = [800, 600] rt.timeout = 3600 rt.subtask_timeout = 600 rt.estimated_memory = 1000 rt.max_price = 15 task = FrameRenderingTaskMock(files_[0], owner=Node(node_name="ABC"), task_definition=rt, total_tasks=num_tasks, root_path=self.path) dm = DirManager(self.path) task.initialize(dm) return task
def build_bt(self, res_x, res_y, total_tasks, frames=None): output_file = self.temp_file_name('output') if frames is None: use_frames = False frames = [1] else: use_frames = True task_definition = RenderingTaskDefinition() task_definition.options = BlenderRendererOptions() task_definition.options.use_frames = use_frames task_definition.options.frames = frames task_definition.output_file = output_file task_definition.output_format = "PNG" task_definition.resolution = [res_x, res_y] task_definition.main_scene_file = path.join(self.path, "example.blend") task_definition.task_id = str(uuid.uuid4()) bt = BlenderRenderTask(owner=Node(node_name="example-node-name"), task_definition=task_definition, total_tasks=total_tasks, root_path=self.tempdir) bt.initialize(DirManager(self.tempdir)) return bt
def test_calculate_total(self): definition = RenderingTaskDefinition() definition.optimize_total = True definition.subtasks_count = 12 definition.options = FrameRendererOptions() definition.options.use_frames = True definition.options.frames = list(range(1, 7)) builder = FrameRenderingTaskBuilder(Node(node_name="node"), dir_manager=DirManager(self.path), task_definition=definition) defaults = RendererDefaults() # More subtasks than frames -> use frames count assert builder._calculate_total(defaults) == 6 definition.options.use_frames = False # Optimize total to default assert builder._calculate_total(defaults) == 20 definition.optimize_total = False # Don't optimize -> use subtasks_count assert builder._calculate_total(defaults) == 12 definition.subtasks_count = None # subtasks_count unknown -> use default assert builder._calculate_total(defaults) == 20 definition.subtasks_count = 0 # subtasks_count invalid -> use default assert builder._calculate_total(defaults) == 20 definition.subtasks_count = 1 # subtasks_count min assert builder._calculate_total(defaults) == 1 definition.subtasks_count = 51 # subtasks_count over max -> use default assert builder._calculate_total(defaults) == 20 definition.subtasks_count = 50 # subtasks_count max assert builder._calculate_total(defaults) == 50 definition.options.use_frames = True definition.subtasks_count = None with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 6 definition.subtasks_count = 0 with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 6 definition.subtasks_count = 1 with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 1 definition.subtasks_count = 2 with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 2 definition.subtasks_count = 3 with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 3 definition.subtasks_count = 6 with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 6 definition.subtasks_count = 12 with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 12 definition.subtasks_count = 4 with self.assertLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 3 definition.subtasks_count = 13 with self.assertLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 12 definition.subtasks_count = 17 with self.assertLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 12 definition.subtasks_count = 18 with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 18
def test_calculate_total(self): definition = RenderingTaskDefinition() definition.optimize_total = True definition.total_subtasks = 12 definition.options = FrameRendererOptions() definition.options.use_frames = True definition.options.frames = range(1, 7) builder = FrameRenderingTaskBuilder(root_path=self.path, dir_manager=DirManager(self.path), node_name="SOME NODE NAME", task_definition=definition) class Defaults(object): def __init__(self, default_subtasks, min_subtasks, max_subtasks): self.default_subtasks = default_subtasks self.min_subtasks = min_subtasks self.max_subtasks = max_subtasks defaults = Defaults(13, 3, 33) assert builder._calculate_total(defaults) == 6 definition.options.use_frames = False assert builder._calculate_total(defaults) == 13 definition.optimize_total = False assert builder._calculate_total(defaults) == 12 definition.total_subtasks = 2 assert builder._calculate_total(defaults) == 13 definition.total_subtasks = 3 assert builder._calculate_total(defaults) == 3 definition.total_subtasks = 34 assert builder._calculate_total(defaults) == 13 definition.total_subtasks = 33 assert builder._calculate_total(defaults) == 33 definition.total_subtasks = 6 definition.options.use_frames = True with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 6 definition.total_subtasks = 3 with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 3 definition.total_subtasks = 12 with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 12 definition.total_subtasks = 4 with self.assertLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 3 definition.total_subtasks = 13 with self.assertLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 12 definition.total_subtasks = 17 with self.assertLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 12 definition.total_subtasks = 18 with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 18