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.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 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 _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_load_task_definition(self): gui = self.gui.get_main_window() gui.ui = Mock() controller = TestRendererCustomizer.TestRC(gui, self.logic) assert isinstance(controller, RendererCustomizer) task_def = RenderingTaskDefinition() files = self.additional_dir_content([1, [2]]) task_def.resources = files task_def.main_scene_file = files[2] self.logic.dir_manager.root_path = self.path controller.load_task_definition(task_def) assert task_def.resources == files[:2]
def test_init(self): with self.assertLogs(logger, level="WARNING"): rt = RenderingTaskMock(main_program_file="notexisting", task_definition=RenderingTaskDefinition(), node_name="Some name", total_tasks=10, root_path=self.path) assert isinstance(rt, RenderingTask) assert rt.src_code == ""
def test_task_border_path(self): typeinfo = LuxRenderTaskTypeInfo(None, None) definition = RenderingTaskDefinition() definition.resolution = (300, 200) border = typeinfo.get_task_border("subtask1", definition, 10, as_path=True) assert len(border) == 4 assert (0, 0) in border assert (0, 199) in border assert (299, 199) in border assert (299, 0) in border definition.resolution = (0, 0) assert typeinfo.get_task_border("subtask1", definition, 10, as_path=True) == []
def test_calculate_total(self): definition = RenderingTaskDefinition() definition.optimize_total = True builder = RenderingTaskBuilder(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=13, min_subtasks=3, max_subtasks=33): self.default_subtasks = default_subtasks self.min_subtasks = min_subtasks self.max_subtasks = max_subtasks defaults = Defaults() assert builder._calculate_total(defaults) == 13 defaults.default_subtasks = 17 assert builder._calculate_total(defaults) == 17 definition.optimize_total = False definition.total_subtasks = 18 assert builder._calculate_total(defaults) == 18 definition.total_subtasks = 2 with self.assertLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 17 definition.total_subtasks = 3 with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 3 definition.total_subtasks = 34 with self.assertLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 17 definition.total_subtasks = 33 with self.assertNoLogs(logger, level="WARNING"): assert builder._calculate_total(defaults) == 33
def __init__(self): self.task_definition = RenderingTaskDefinition() self.task_definition.max_price = 100 self.task_definition.resolution = [200, 100] self.task_definition.full_task_timeout = 10000 self.task_definition.subtask_timeout = 10000 self.task_definition.optimize_total = False self.task_definition.resources = set() self.task_definition.total_tasks = 1 self.task_definition.total_subtasks = 1 self.task_definition.start_task = 1 self.task_definition.end_task = 1 # magic constant obtained experimentally self.normalization_constant = 9500
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 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 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 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 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 _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 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_get_task_border(self): typeinfo = LuxRenderTaskTypeInfo(None, None) definition = RenderingTaskDefinition() definition.resolution = (4, 4) border = typeinfo.get_task_border("subtask1", definition, 10) for i in range(4): assert (i, 0) in border assert (i, 3) in border for j in range(4): assert (0, j) in border assert (3, j) in border definition.resolution = (300, 200) border = typeinfo.get_task_border("subtask1", definition, 10) for i in range(300): assert (i, 0) in border assert (i, 199) in border for j in range(200): assert (0, j) in border assert (299, j) in border assert (300, 199) not in border assert (299, 201) not in border assert (0, 200) not in border assert (300, 0) not in border definition.resolution = (300, 300) border = typeinfo.get_task_border("subtask1", definition, 10) for i in range(200): assert (i, 0) in border assert (i, 199) in border for j in range(200): assert (0, j) in border assert (199, j) in border assert (200, 199) not in border assert (199, 200) not in border assert (0, 200) not in border assert (200, 0) not in border definition.resolution = (1000, 100) border = typeinfo.get_task_border("subtask1", definition, 10) for i in range(300): assert (i, 0) in border assert (i, 29) in border for j in range(30): assert (0, j) in border assert (299, j) in border assert (30, 299) not in border assert (29, 200) not in border assert (0, 30) not in border assert (300, 0) not in border definition.resolution = (100, 1000) border = typeinfo.get_task_border("subtask1", definition, 10) for i in range(20): assert (i, 0) in border assert (i, 199) in border for j in range(200): assert (0, j) in border assert (19, j) in border assert (20, 199) not in border assert (19, 200) not in border assert (20, 0) not in border assert (0, 200) not in border definition.resolution = (0, 4) assert typeinfo.get_task_border("subtask1", definition, 10) == [] definition.resolution = (4, 0) assert typeinfo.get_task_border("subtask1", definition, 10) == [] definition.resolution = (0, 0) assert typeinfo.get_task_border("subtask1", definition, 10) == []
def test_get_task_num_from_pixels(self): typeinfo = LuxRenderTaskTypeInfo(None, None) definition = RenderingTaskDefinition() definition.resolution = (0, 0) assert typeinfo.get_task_num_from_pixels(10, 10, definition, 10) == 1
def test_lux_customizer(self, mock_file_dialog): self.logic.register_new_task_type(LuxRenderTaskTypeInfo( TaskWidget(Ui_LuxWidget), LuxRenderDialogCustomizer)) self.logic.customizer = MainWindowCustomizer(self.gui.main_window, self.logic) self.logic.dir_manager = Mock() self.logic.dir_manager.root_path = self.path 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() lux_customizer = self.logic.customizer.new_task_dialog_customizer.task_customizer assert isinstance(lux_customizer, LuxRenderDialogCustomizer) assert lux_customizer.get_task_name() == "LuxRender" self.logic.customizer.gui.ui.resourceFilesLabel.setText("124") QTest.mouseClick(self.logic.customizer.gui.ui.resetToDefaultButton, Qt.LeftButton) assert self.logic.customizer.gui.ui.resourceFilesLabel.text() == "0" definition = RenderingTaskDefinition() lux_customizer.get_task_specific_options(definition) lux_customizer.load_task_definition(definition) path = u"{}".format(str(lux_customizer.load_setting('main_scene_path', os.path.expanduser('~')))) mock_file_dialog.getOpenFileName.return_value = path, None QTest.mouseClick(lux_customizer.gui.ui.chooseMainSceneFileButton, Qt.LeftButton) mock_file_dialog.getOpenFileName.assert_called_with(lux_customizer.gui, "Choose main scene file", path, u"Scene files (*.LXS *.lxs)") lux_customizer.gui.ui.stopByTimeRadioButton.setChecked(True) lux_customizer.gui.ui.haltTimeLineEdit.setText("60") lux_customizer._change_options() assert lux_customizer.options.haltspp == 0 assert lux_customizer.options.halttime == 60 lux_customizer.gui.ui.haltTimeLineEdit.setText("XYZ") with self.assertLogs(logger, level="ERROR"): lux_customizer._change_options() assert lux_customizer.options.haltspp == 0 lux_customizer.gui.ui.stopBySppRadioButton.setChecked(True) lux_customizer.gui.ui.haltTimeLineEdit.setText("30") lux_customizer.gui.ui.haltSppLineEdit.setText("ABC") with self.assertLogs(logger, level="ERROR"): lux_customizer._change_options() assert lux_customizer.options.halttime == 0 lux_customizer.gui.ui.haltSppLineEdit.setText("25") lux_customizer._change_options() assert lux_customizer.options.halttime == 0 assert lux_customizer.options.haltspp == 25 lux_customizer.options.haltspp = 0 lux_customizer._change_halts_values() assert lux_customizer.gui.ui.stopByTimeRadioButton.isChecked() assert not lux_customizer.gui.ui.stopBySppRadioButton.isChecked() lux_customizer.options.haltspp = 24 lux_customizer._change_halts_values() assert not lux_customizer.gui.ui.stopByTimeRadioButton.isChecked() assert lux_customizer.gui.ui.stopBySppRadioButton.isChecked()
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
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"