class TestBlenderRenderDialogCustomizer(TestDirFixture): def setUp(self): super(TestBlenderRenderDialogCustomizer, self).setUp() self.logic = GuiApplicationLogic() self.gui = Gui(Mock(), AppMainWindow) def tearDown(self): super(TestBlenderRenderDialogCustomizer, self).tearDown() self.gui.app.exit(0) self.gui.app.deleteLater() @patch("gui.controller.customizer.QMessageBox") 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)
class TestLuxRenderDialogCustomizer(TestDirFixture, LogTestCase): def setUp(self): super(TestLuxRenderDialogCustomizer, self).setUp() self.logic = GuiApplicationLogic() self.gui = Gui(Mock(), AppMainWindow) def tearDown(self): super(TestLuxRenderDialogCustomizer, self).tearDown() self.gui.app.exit(0) self.gui.app.deleteLater() @patch("apps.rendering.gui.controller.renderercustomizer.QFileDialog") 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()
class TestNewTaskDialogCustomizer(TempDirFixture, LogTestCase): def setUp(self): super(TestNewTaskDialogCustomizer, self).setUp() self.logic = GuiApplicationLogic() self.gui = Gui(self.logic, AppMainWindow) def tearDown(self): super(TestNewTaskDialogCustomizer, self).tearDown() self.gui.app.exit(0) self.gui.app.deleteLater() def test_customizer(self): 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 tti = TaskTypeInfo("Nice task", TaskDefinition, CoreTaskDefaults(), Mock(), Mock(), Mock(), Mock()) self.logic.register_new_task_type(tti) self.gui.main_window.ui.taskSpecificLayout = Mock() self.gui.main_window.ui.taskSpecificLayout.count.return_value = 2 customizer = NewTaskDialogCustomizer(self.gui.main_window, self.logic) self.assertIsInstance(customizer, NewTaskDialogCustomizer) assert customizer.gui.ui.showAdvanceNewTaskButton.text() == customizer.SHOW_ADVANCE_BUTTON_MESSAGE[0] assert not customizer.gui.ui.advanceNewTaskWidget.isVisible() customizer._advance_settings_button_clicked() QTest.mouseClick(customizer.gui.ui.showAdvanceNewTaskButton, Qt.LeftButton) task_name = "Some Nice Task" td = TaskDefinition() td.resources = ["/abc/./def", "/ghi/jik"] td.main_program_file = "/a/b/c/" td.task_name = task_name td.main_scene_file = 'a/b/c/d e/file.blend' td.task_type = "Nice task" td.output_file = 'a/b/c/d e/result.jpeg' win_norm_resources = {"\\abc\\def", "\\ghi\\jik"} oth_norm_resources = {"/abc/def", "/ghi/jik"} customizer.load_task_definition(td) if is_windows(): assert customizer.add_task_resource_dialog_customizer.resources == win_norm_resources else: assert customizer.add_task_resource_dialog_customizer.resources == oth_norm_resources assert customizer.gui.ui.taskNameLineEdit.text() == task_name assert td.resources == ["/abc/./def", "/ghi/jik"] customizer._read_basic_task_params(td) if is_windows(): assert td.resources == win_norm_resources else: assert td.resources == oth_norm_resources assert td.task_name == task_name reg = re.compile('Nice task_[0-2]\d:[0-5]\d:[0-5]\d_20\d\d-[0-1]\d\-[0-3]\d') td.task_name = None customizer.load_task_definition(td) name = "{}".format(customizer.gui.ui.taskNameLineEdit.text()) assert re.match(reg, name) is not None, "Task name does not match: {}".format(name) td.task_name = "" customizer.load_task_definition(td) name = "{}".format(customizer.gui.ui.taskNameLineEdit.text()) assert re.match(reg, name) is not None, "Task name does not match: {}".format(name) @patch('apps.core.gui.controller.newtaskdialogcustomizer.QFileDialog') 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()