Beispiel #1
0
    def test_run(self):
        dm = DockerTaskThread.docker_manager = DockerManager.install()
        dm.update_config(status_callback=mock.Mock(),
                         done_callback=mock.Mock(),
                         work_dir=self.new_path,
                         in_background=True)
        benchmark = BlenderBenchmark()
        task_definition = benchmark.task_definition

        task_state = TaskDesc()
        task_state.status = TaskStatus.notStarted
        task_state.definition = task_definition

        dir_manager = DirManager(self.path)
        task = blenderrendertask.BlenderRenderTaskBuilder(
            Node(), task_definition, dir_manager).build()

        success = mock.MagicMock()
        error = mock.MagicMock()

        self.br = BenchmarkRunner(task, self.path, success, error, benchmark)
        self.br.run()
        if self.br.tt:
            self.br.tt.join()

        self.assertEqual(success.call_count, 1)
Beispiel #2
0
    def run_benchmark(self,
                      benchmark,
                      task_builder,
                      env_id,
                      success=None,
                      error=None):
        logger.info('Running benchmark for %s', env_id)

        from golem.network.p2p.node import Node

        def success_callback(performance):
            logger.info('%s performance is %.2f', env_id, performance)
            Performance.update_or_create(env_id, performance)
            if success:
                success(performance)

        def error_callback(err: Union[str, Exception]):
            logger.error("Unable to run %s benchmark: %s", env_id, str(err))
            if error:
                if isinstance(err, str):
                    err = Exception(err)
                error(err)

        task_state = TaskDesc()
        task_state.status = TaskStatus.notStarted
        task_state.definition = benchmark.task_definition
        self._validate_task_state(task_state)
        builder = task_builder(Node(), task_state.definition, self.dir_manager)
        task = builder.build()
        br = BenchmarkRunner(task=task,
                             root_path=self.dir_manager.root_path,
                             success_callback=success_callback,
                             error_callback=error_callback,
                             benchmark=benchmark)
        br.run()
    def run_benchmark(self, benchmark, label, cfg_param_name):
        task_state = TaskDesc()
        task_state.status = TaskStatus.notStarted
        task_state.definition = benchmark.task_definition
        self._validate_task_state(task_state)

        tb = self.get_builder(task_state)
        t = Task.build_task(tb)

        reactor = self.__get_reactor()

        self.br = BenchmarkRunner(
            t, self.datadir, lambda p: reactor.callFromThread(
                self._benchmark_computation_success,
                performance=p,
                label=label,
                cfg_param=cfg_param_name), self._benchmark_computation_error,
            benchmark)

        self.progress_dialog = TestingTaskProgressDialog(
            self.customizer.gui.window)
        self.progress_dialog_customizer = TestingTaskProgressDialogCustomizer(
            self.progress_dialog, self)
        self.progress_dialog_customizer.enable_ok_button(
            False)  # disable 'ok' button
        self.customizer.gui.setEnabled('recount',
                                       False)  # disable all 'recount' buttons
        self.progress_dialog.show()

        self.br.run()
    def test_run(self):
        benchmark = BlenderBenchmark()
        task_definition = benchmark.task_definition

        task_state = TaskDesc()
        task_state.status = TaskStatus.notStarted
        task_state.definition = task_definition

        dir_manager = DirManager(self.path)
        task = Task.build_task(
            BlenderRenderTaskBuilder("node name", task_definition, self.path,
                                     dir_manager))

        result = [None]

        def success(*_):
            result[0] = True

        def error(*_):
            result[0] = False

        self.br = BenchmarkRunner(task, self.path, success, error, benchmark)
        self.br.run()
        if self.br.tt:
            self.br.tt.join()

        assert result[0]
    def add_task_from_definition(self, definition):
        task_state = TaskDesc()
        task_state.status = TaskStatus.notStarted

        task_state.definition = definition

        self.add_tasks([task_state])
Beispiel #6
0
 def _get_task_state(task_id="xyz",
                     full_task_timeout=100,
                     subtask_timeout=50):
     task_state = TaskDesc()
     td = TestGuiApplicationLogicWithClient._get_task_definition(
         task_id=task_id,
         full_task_timeout=full_task_timeout,
         subtask_timeout=subtask_timeout)
     task_state.status = TaskStatus.notStarted
     task_state.definition = td
     return task_state
Beispiel #7
0
    def load(self, file_name, skip_test):

        try:
            definition = self.__read_from_file(file_name)
        except Exception as exc:
            return CommandResult(
                error="Error reading task from file '{}': {}".format(
                    file_name, exc))

        if hasattr(definition, 'resources'):
            definition.resources = {
                os.path.normpath(res)
                for res in definition.resources
            }
        datadir = sync_wait(Tasks.client.get_datadir())

        # TODO: unify GUI and CLI logic

        rendering_task_state = TaskDesc()
        rendering_task_state.definition = definition
        rendering_task_state.task_state.status = TaskStatus.starting

        if not Tasks.application_logic:
            Tasks.application_logic = CommandAppLogic.instantiate(
                Tasks.client, datadir)

        task_builder = Tasks.application_logic.get_builder(
            rendering_task_state)
        task = Task.build_task(task_builder)
        rendering_task_state.task_state.outputs = task.get_output_names()
        rendering_task_state.task_state.total_subtasks = task.get_total_tasks()
        task.header.task_id = str(uuid.uuid4())

        if not skip_test:

            test_task = Task.build_task(task_builder)
            test_task.header.task_id = str(uuid.uuid4())
            queue = Queue()

            TaskTester(test_task,
                       datadir,
                       success_callback=lambda *a, **kw: queue.put(True),
                       error_callback=lambda *a, **kw: queue.put(a)).run()

            test_result = queue.get()
            if test_result is not True:
                return CommandResult(
                    error="Test failed: {}".format(test_result))

        task_dict = DictSerializer.dump(task)
        task_def = task_dict['task_definition']
        task_def['resources'] = list(task_def.get('task_definition', []))
        deferred = Tasks.client.create_task(task_dict)
        return sync_wait(deferred, timeout=1800)
Beispiel #8
0
 def run_benchmark(self, benchmark, task_builder, datadir, node_name,
                   success_callback, error_callback):
     task_state = TaskDesc()
     task_state.status = TaskStatus.notStarted
     task_state.definition = benchmark.task_definition
     self._validate_task_state(task_state)
     builder = task_builder(node_name, task_state.definition, datadir,
                            self.dir_manager)
     t = Task.build_task(builder)
     br = BenchmarkRunner(t, datadir, success_callback, error_callback,
                          benchmark)
     br.run()
Beispiel #9
0
    def __test_task_button_clicked(self):
        self.task_state = TaskDesc()
        self.task_state.status = TaskStatus.notStarted
        self.task_state.definition = self._query_task_definition()

        if not self.logic.run_test_task(self.task_state):
            logger.error("Task not tested properly")
    def test_update_preview(self):
        customizer = MainWindowCustomizer(self.gui.get_main_window(),
                                          MagicMock())
        rts = TaskDesc(definition_class=RenderingTaskDefinition)
        rts.definition.output_file = "bla"
        customizer.update_task_additional_info(rts)
        assert customizer.gui.ui.outputFile.text() == "bla"
        assert not customizer.gui.ui.previewsSlider.isVisible()
        assert customizer.preview_controller.last_preview_path == customizer.preview_controller.preview_path
        assert customizer.gui.ui.previewLabel.pixmap().width() == 298
        assert customizer.gui.ui.previewLabel.pixmap().height() == 200

        img = Image.new("RGB", (250, 123), "white")
        img_path = os.path.join(self.path, "image1.png")
        img.save(img_path)
        rts.task_state.extra_data = {"result_preview": img_path}
        customizer.update_task_additional_info(rts)
        assert customizer.gui.ui.previewLabel.pixmap().width() == 250
        assert customizer.gui.ui.previewLabel.pixmap().height() == 123

        img = Image.new("RGB", (301, 206), "white")
        img.save(img_path)
        customizer.update_task_additional_info(rts)
        assert customizer.gui.ui.previewLabel.pixmap().width() == 301
        assert customizer.gui.ui.previewLabel.pixmap().height() == 206

        rts.definition.task_type = u"Blender"
        rts.definition.options = MagicMock()
        rts.definition.options.use_frames = True
        rts.definition.options.frames = range(10)
        rts.task_state.outputs = ["result"] * 10
        rts.task_state.extra_data = {"result_preview": [img_path]}
        customizer.update_task_additional_info(rts)
 def test_show_task_result(self, mock_messagebox):
     customizer = MainWindowCustomizer(self.gui.get_main_window(),
                                       MagicMock())
     td = TaskDesc()
     td.definition.task_type = "Blender"
     td.definition.options.use_frames = True
     td.definition.output_file = os.path.join(self.path, "output.png")
     td.task_state.outputs = [
         os.path.join(self.path, u"output0011.png"),
         os.path.join(self.path, u"output0014.png"),
         os.path.join(self.path, u"output0017.png")
     ]
     td.definition.options.frames = [11, 14, 17]
     customizer.logic.get_task.return_value = td
     customizer.current_task_highlighted = td
     customizer.gui.ui.previewsSlider.setRange(1, 3)
     mock_messagebox.Critical = "CRITICAL"
     customizer.show_task_result("abc")
     expected_file = td.task_state.outputs[0]
     mock_messagebox.assert_called_with(mock_messagebox.Critical, "Error",
                                        expected_file + u" is not a file",
                                        ANY, ANY)
     customizer.gui.ui.previewsSlider.setValue(2)
     customizer.show_task_result("abc")
     expected_file = td.task_state.outputs[1]
     mock_messagebox.assert_called_with(mock_messagebox.Critical, "Error",
                                        expected_file + u" is not a file",
                                        ANY, ANY)
     customizer.gui.ui.previewsSlider.setValue(3)
     customizer.show_task_result("abc")
     expected_file = td.task_state.outputs[2]
     mock_messagebox.assert_called_with(mock_messagebox.Critical, "Error",
                                        expected_file + u" is not a file",
                                        ANY, ANY)
Beispiel #12
0
 def __init_basic_customizer(self):
     task_dialog = TaskDetailsDialog(self.gui.main_window.window)
     task_state = TaskDesc()
     ss1 = SubtaskState()
     ss1.subtask_id = "abc"
     ss1.computer.node_name ="ABC"
     ss1.computer.ip_address = "10.10.10.10"
     ss1.computer.performance = "1000"
     ss1.subtask_definition = "DEF 1"
     ss1.subtask_status = SubtaskStatus.downloading
     ss2 = SubtaskState()
     ss2.subtask_id = "def"
     ss2.computer.node_name = "DEF"
     ss2.computer.ip_address = "10.10.10.20"
     ss2.computer.performance = "2000"
     ss2.subtask_definition = "DEF 2"
     ss2.subtask_status = SubtaskStatus.starting
     ss3 = SubtaskState()
     ss3.subtask_id = "xyz"
     ss3.computer.node_name = "XYZ"
     ss3.computer.ip_address = "10.10.10.30"
     ss3.computer.performance = "3000"
     ss3.subtask_definition = "DEF 3"
     ss3.subtask_status = SubtaskStatus.finished
     task_state.task_state.subtask_states["abc"] = ss1
     task_state.task_state.subtask_states["def"] = ss2
     task_state.task_state.subtask_states["xyz"] = ss3
     task_state.task_state.progress = 0.33
     task_state.task_state.remaining_time = 34
     task_state.task_state.elapsed_time = 12
     customizer = TaskDetailsDialogCustomizer(task_dialog, self.logic, task_state)
     return customizer
    def test_table(self):
        customizer = MainWindowCustomizer(self.gui.get_main_window(),
                                          MagicMock())
        task1 = TaskDesc()
        task1.definition.task_id = "TASK ID 1"
        task1.status = "Finished"
        task1.definition.task_name = "TASK NAME 1"
        customizer.logic.get_task.return_value = task1
        customizer.add_task(task1)
        assert customizer.gui.ui.taskTableWidget.item(
            0, ItemMap.Id).text() == "TASK ID 1"
        assert customizer.gui.ui.taskTableWidget.item(
            0, ItemMap.Name).text() == "TASK NAME 1"
        assert customizer.gui.ui.taskTableWidget.item(
            0, ItemMap.Status).text() == "Finished"
        assert customizer.gui.ui.taskTableWidget.item(
            0, ItemMap.Cost).text() == "0.000000"
        assert customizer.gui.ui.taskTableWidget.item(
            0, ItemMap.Time).text() == "00:00:00"
        task2 = TaskDesc()
        task2.definition.task_id = "TASK ID 2"
        task2.status = "Waiting"
        task2.definition.task_name = "TASK NAME 2"
        customizer.logic.get_task.return_value = task2
        customizer.add_task(task2)
        assert customizer.gui.ui.taskTableWidget.item(
            1, ItemMap.Id).text() == "TASK ID 2"
        assert customizer.gui.ui.taskTableWidget.item(
            1, ItemMap.Name).text() == "TASK NAME 2"
        assert customizer.gui.ui.taskTableWidget.item(
            1, ItemMap.Status).text() == "Waiting"
        assert customizer.gui.ui.taskTableWidget.item(
            1, ItemMap.Cost).text() == "0.000000"
        assert customizer.gui.ui.taskTableWidget.item(
            1, ItemMap.Time).text() == "00:00:00"
        customizer.update_time()
        assert customizer.gui.ui.taskTableWidget.item(
            0, ItemMap.Time).text() == "00:00:00"
        time_ = customizer.gui.ui.taskTableWidget.item(1, ItemMap.Time).text()
        assert time_ != "00:00:00"
        task1.task_state.status = "Computing"
        task2.task_state.progress = 0.3
        task2.task_state.status = "Paused"
        task2.task_state.progress = 1.0
        customizer.logic.get_cost_for_task_id.return_value = 2.342 * denoms.ether
        tasks = {'TASK ID 1': task1, 'TASK ID 2': task2}
        customizer.update_tasks(tasks)
        customizer.update_time()
        assert customizer.gui.ui.taskTableWidget.item(
            1, ItemMap.Cost).text() == "2.342000"
        assert customizer.gui.ui.taskTableWidget.item(
            0, ItemMap.Time).text() != "00:00:00"
        assert customizer.gui.ui.taskTableWidget.item(
            1, ItemMap.Time).text() == time_
        customizer.remove_task("TASK ID 2")

        customizer.logic.get_task.return_value = TaskDesc()
        customizer.show_change_task_dialog("ABC")
        customizer.change_task_dialog.close()
    def test_pixmap(self):
        maincontroller = MagicMock()
        pc = PreviewController(self.gui.get_main_window(), self.logic, maincontroller)
        td = TaskDesc()
        pc.set_preview(td)
        point_10_10 = MagicPoint(10, 10)
        pc._PreviewController__pixmap_clicked(point_10_10)
        pc.maincontroller.show_subtask_details_dialog.assert_not_called()

        pc.maincontroller.current_task_highlighted = td
        pc._PreviewController__pixmap_clicked(point_10_10)
        pc.maincontroller.show_subtask_details_dialog.assert_not_called()

        td.definition.task_type = "TASKTYPE"
        td.definition.task_id = "XYZ"
        pc.logic.get_task.return_value = td

        pc._PreviewController__pixmap_clicked(point_10_10)
        pc.maincontroller.show_subtask_details_dialog.assert_not_called()

        task_type_mock = MagicMock()
        pc.logic.get_task_type.return_value = task_type_mock
        task_type_mock.get_task_num_from_pixels.return_value = 1
        subtask_mock = MagicMock()
        subtask_mock.extra_data = {'start_task': 4, 'end_task': 5}
        subtask_mock.subtask_status = SubtaskStatus.finished
        td.task_state.subtask_states["abc"] = subtask_mock

        pc._PreviewController__pixmap_clicked(point_10_10)
        pc.maincontroller.show_subtask_details_dialog.assert_not_called()

        point_0_0 = MagicPoint(0, 0)
        pc._PreviewController__pixmap_clicked(point_0_0)
        pc.maincontroller.show_subtask_details_dialog.assert_not_called()

        subtask_mock.extra_data = {'start_task': 1, 'end_task': 2}
        pc._PreviewController__pixmap_clicked(point_10_10)
        pc.maincontroller.show_subtask_details_dialog.assert_called_with(subtask_mock)

        td.task_state.outputs = ["output1", "output2"]
        pc._PreviewController__pixmap_clicked(point_10_10)
        assert pc.maincontroller.show_subtask_details_dialog.call_count == 2

        pc._PreviewController__mouse_on_pixmap_moved(point_0_0)
        assert task_type_mock.get_task_border.call_count == 0

        pc._PreviewController__mouse_on_pixmap_moved(point_10_10)
        assert task_type_mock.get_task_border.call_count == 1

        td.task_state.outputs = ["output1"]
        pc._PreviewController__mouse_on_pixmap_moved(point_10_10)
        assert task_type_mock.get_task_border.call_count == 2
Beispiel #15
0
 def test_start_task(self):
     logic = GuiApplicationLogic()
     logic.customizer = Mock()
     logic.client = Mock()
     task_desc = TaskDesc()
     task_desc.task_state.status = TaskStatus.notStarted
     task_desc.definition.task_type = "TASKTYPE1"
     task_type = Mock()
     task_type.task_builder_type.return_value = TTaskBuilder(self.path)
     logic.task_types["TASKTYPE1"] = task_type
     logic.tasks["xyz"] = task_desc
     logic.start_task("xyz")
     assert task_desc.task_state.status == TaskStatus.starting
     assert task_desc.task_state.outputs == [
         "output1", "output2", "output3"
     ]
Beispiel #16
0
    def test_menu(self, mock_action):
        td = TaskDesc()
        TASK_ID = "TESTTTASK"
        td.definition.task_id = TASK_ID
        status = [
            TaskStatus.notStarted, TaskStatus.sending, TaskStatus.waiting,
            TaskStatus.starting, TaskStatus.computing, TaskStatus.finished,
            TaskStatus.finished, TaskStatus.aborted, TaskStatus.timeout,
            TaskStatus.paused
        ]
        menu = None
        for st in status:
            td.task_state.status = st
            menu = TaskContextMenuCustomizer(Mock(), Mock(), td)

        assert menu is not None
        menu._TaskContextMenuCustomizer__abort_task_triggered()
        menu.logic.abort_task.assert_called_with(TASK_ID)

        menu._TaskContextMenuCustomizer__restart_task_triggered()
        menu.logic.restart_task.assert_called_with(TASK_ID)

        menu._TaskContextMenuCustomizer__delete_task_triggered()
        menu.logic.delete_task.assert_called_with(TASK_ID)

        menu._TaskContextMenuCustomizer__clone_task_triggered()
        menu.logic.clone_task.assert_called_with(TASK_ID)

        menu._TaskContextMenuCustomizer__start_task_triggered()
        menu.logic.start_task.assert_called_with(TASK_ID)

        menu._TaskContextMenuCustomizer__pause_task_triggered()
        menu.logic.pause_task.assert_called_with(TASK_ID)

        menu._TaskContextMenuCustomizer__resume_task_triggered()
        menu.logic.resume_task.assert_called_with(TASK_ID)

        menu._TaskContextMenuCustomizer__show_task_details_triggered()
        menu.logic.show_task_details.assert_called_with(TASK_ID)

        menu._TaskContextMenuCustomizer__change_task_triggered()
        menu.logic.change_task.assert_called_with(TASK_ID)

        menu._TaskContextMenuCustomizer__show_result_triggered()
        menu.logic.show_task_result.assert_called_with(TASK_ID)
    def test_output_file(self):
        maincontroller = MagicMock()
        pc = PreviewController(self.gui.get_main_window(), self.logic, maincontroller)
        td = TaskDesc()

        # Test output color
        pc.set_preview(td)
        assert pc.gui.ui.outputFile.styleSheet() == "color: black"
        files = self.additional_dir_content([3])
        td.definition.output_file = files[0]
        pc.set_preview(td)
        assert pc.gui.ui.outputFile.styleSheet() == "color: blue"

        td.task_state.outputs = files
        pc.maincontroller.current_task_highlighted = td
        pc.set_preview(td)
        pc.gui.ui.previewsSlider.setValue(1)
        assert pc.gui.ui.outputFile.text() == files[0]
        pc.gui.ui.previewsSlider.setRange(1, 6)
        pc.gui.ui.previewsSlider.setValue(4)
        assert pc.gui.ui.outputFile.text() == ""
Beispiel #18
0
    def test_sorting(self):
        task_dialog = TaskDetailsDialog(self.gui.main_window.window)
        task_state = TaskDesc()
        customizer = TaskDetailsDialogCustomizer(task_dialog, self.logic, task_state)
        self.assertEqual(customizer.sorting, -1)
        self.assertIsNone(customizer.sorting_order)
        task_state.task_state.progress = 0.33
        task_state.task_state.remaining_time = 34
        task_state.task_state.elapsed_time = 12
        ss1 = SubtaskState()
        ss1.computer.node_name = "ABC"
        ss1.subtask_id = "def"
        ss1.subtask_status = SubtaskStatus.finished
        task_state.task_state.subtask_states['def'] = ss1
        ss2 = SubtaskState()
        ss2.computer.node_name = "DEF"
        ss2.subtask_id = "abc"
        ss2.subtask_status = SubtaskStatus.finished
        task_state.task_state.subtask_states['abc'] = ss2
        customizer.update_view(task_state.task_state)
        self.assertEqual(customizer.sorting, -1)
        self.assertIsNone(customizer.sorting_order)
        self.assertEqual(len(customizer.subtask_table_elements), 2)
        ids = [str(customizer.gui.ui.nodesTableWidget.item(i, 1).text()) for i in range(2)]
        self.assertIn('def', ids)
        self.assertIn('abc', ids)

        customizer._TaskDetailsDialogCustomizer__header_clicked(1)
        self.assertEqual(customizer.sorting, 1)
        self.assertEqual(customizer.sorting_order, SortingOrder.ascending)
        self.assertEqual(len(customizer.subtask_table_elements), 2)
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 0).text()), "DEF")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 0).text()), "ABC")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 1).text()), "abc")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 1).text()), "def")

        customizer._TaskDetailsDialogCustomizer__header_clicked(1)
        self.assertEqual(customizer.sorting, 1)
        self.assertEqual(customizer.sorting_order, SortingOrder.descending)
        self.assertEqual(len(customizer.subtask_table_elements), 2)
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 0).text()), "ABC")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 0).text()), "DEF")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 1).text()), "def")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 1).text()), "abc")

        ss3 = SubtaskState()
        ss3.computer.node_name = "FGH"
        ss3.subtask_id = "fgh"
        ss3.subtask_status = SubtaskStatus.finished
        task_state.task_state.subtask_states['fgh'] = ss3
        customizer.update_view(task_state.task_state)

        self.assertEqual(customizer.sorting, 1)
        self.assertEqual(customizer.sorting_order, SortingOrder.descending)
        self.assertEqual(len(customizer.subtask_table_elements), 3)
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 0).text()), "FGH")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 0).text()), "ABC")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(2, 0).text()), "DEF")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 1).text()), "fgh")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 1).text()), "def")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(2, 1).text()), "abc")

        customizer._TaskDetailsDialogCustomizer__header_clicked(0)
        self.assertEqual(customizer.sorting, 0)
        self.assertEqual(customizer.sorting_order, SortingOrder.ascending)
        self.assertEqual(len(customizer.subtask_table_elements), 3)
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 0).text()), "ABC")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 0).text()), "DEF")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(2, 0).text()), "FGH")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 1).text()), "def")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 1).text()), "abc")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(2, 1).text()), "fgh")

        customizer._TaskDetailsDialogCustomizer__header_clicked(0)
        self.assertEqual(customizer.sorting, 0)
        self.assertEqual(customizer.sorting_order, SortingOrder.descending)
        self.assertEqual(len(customizer.subtask_table_elements), 3)
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 0).text()), "FGH")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 0).text()), "DEF")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(2, 0).text()), "ABC")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 1).text()), "fgh")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 1).text()), "abc")
        self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(2, 1).text()), "def")
Beispiel #19
0
    def test_messages(self, msg_box):
        msg_box.return_value = msg_box
        logic = self.logic
        self.logic.datadir = self.path
        logic.customizer = MainWindowCustomizer(self.app.main_window, logic)
        logic.customizer.show_error_window = Mock()
        logic.customizer.show_warning_window = Mock()
        logic.customizer.current_task_highlighted = Mock()
        logic.client = Mock()
        self.logic.dir_manager = DirManager(self.path)
        register_task_types(logic)

        rts = TaskDesc()
        self.assertIsInstance(rts, TaskDesc)
        f = self.additional_dir_content([3])
        rts.definition.task_type = "Blender"
        rts.definition.output_file = f[0]
        rts.definition.main_program_file = f[1]
        rts.definition.main_scene_file = f[2]
        self.assertTrue(logic._validate_task_state(rts))
        m = Mock()

        broken_benchmark = BlenderBenchmark()
        broken_benchmark.task_definition.main_program_file = u'Bździągwa'
        logic.customizer.show_error_window = Mock()
        logic.run_benchmark(broken_benchmark, m, m)
        logic.progress_dialog.close()
        if logic.br.tt:
            logic.br.tt.join()
        logic.customizer.show_error_window.assert_called_with(
            u"Main program file does not exist: Bździągwa")

        broken_benchmark = BlenderBenchmark()
        broken_benchmark.task_definition.output_file = u'/x/y/Bździągwa'
        logic.run_benchmark(broken_benchmark, m, m)
        logic.progress_dialog.close()
        if logic.br.tt:
            logic.br.tt.join()
        logic.customizer.show_error_window.assert_called_with(
            u"Cannot open output file: /x/y/Bździągwa")

        broken_benchmark = BlenderBenchmark()
        broken_benchmark.task_definition.main_scene_file = "NOT EXISTING"
        output_file = os.path.join(self.path, str(uuid.uuid4()))
        broken_benchmark.task_definition.output_file = output_file
        logic.run_benchmark(broken_benchmark, m, m)
        logic.progress_dialog.close()
        if logic.br.tt:
            logic.br.tt.join()
        logic.customizer.show_error_window.assert_called_with(
            u"Main scene file NOT EXISTING is not properly set")

        logic.test_task_computation_error(u"Bździągwa")
        text = logic.progress_dialog_customizer.gui.ui.message.text()
        assert text == u"Task test computation failure. Bździągwa"
        logic.test_task_computation_error(u"500 server error")
        text = logic.progress_dialog_customizer.gui.ui.message.text()
        assert text == u"Task test computation failure. [500 server error] " \
            u"There is a chance that you RAM limit is too low. " \
            u"Consider increasing max memory usage"
        logic.test_task_computation_error(None)
        text = logic.progress_dialog_customizer.gui.ui.message.text()
        assert text == u"Task test computation failure. "
        logic.test_task_computation_success([], 10000, 1021, {})
        text = logic.progress_dialog_customizer.gui.ui.message.text()
        assert text.startswith(u"Task tested successfully")
        logic.test_task_computation_success([], 10000, 1021,
                                            {"warnings": "Warning message"})
        text = logic.progress_dialog_customizer.gui.ui.message.text()
        assert text.startswith(u"Task tested successfully")
        logic.customizer.show_warning_window.assert_called_with(
            "Warning message")

        rts.definition = BlenderBenchmark().task_definition
        rts.definition.output_file = 1342
        self.assertFalse(logic._validate_task_state(rts))

        self.assertEqual(logic._format_stats_message(("STAT1", 2424)),
                         u"Session: STAT1; All time: 2424")
        self.assertEqual(logic._format_stats_message(["STAT1"]), u"Error")
        self.assertEqual(logic._format_stats_message(13131), u"Error")

        ts = TaskDesc()
        ts.definition.task_type = "Blender"
        ts.definition.main_program_file = "nonexisting"
        self.assertFalse(logic._validate_task_state(ts))
        logic.customizer.show_error_window.assert_called_with(
            u"Main program file does not exist: nonexisting")

        with self.assertLogs(logger, level="WARNING"):
            logic.set_current_task_type("unknown task")

        def query_task_state(*_):
            deferred = Deferred()
            deferred.callback(True)
            return deferred

        logic.client.query_task_state = query_task_state
        with self.assertLogs(logger, level="WARNING"):
            logic.task_status_changed("unknown id")

        task_type = Mock()
        task_type.name = "NAME1"
        logic.register_new_task_type(task_type)
        with self.assertLogs(int_logger, level="ERROR"):
            logic.register_new_task_type(task_type)

        logic.register_new_test_task_type(task_type)
        with self.assertRaises(RuntimeError):
            logic.register_new_test_task_type(task_type)
Beispiel #20
0
    def test_run_test_task(self, *_):
        logic = self.logic
        gui = self.app

        rpc_session = MockRPCSession(self.client, CORE_METHOD_MAP)
        rpc_client = rpc.session.Client(rpc_session, CORE_METHOD_MAP)
        rpc_publisher = MockRPCPublisher()

        logic.root_path = self.path
        logic.client = rpc_client

        self.client.datadir = logic.root_path
        self.client.rpc_publisher = rpc_publisher

        logic.customizer = MainWindowCustomizer(gui.main_window, logic)
        logic.customizer.new_task_dialog_customizer = Mock()
        logic.customizer.show_warning_window = Mock()

        ts = TaskDesc()
        files = self.additional_dir_content([1])
        ts.definition.main_program_file = files[0]
        ts.definition.task_type = "TESTTASK"
        f = self.additional_dir_content([2])
        ts.definition.output_file = f[0]
        ts.definition.main_scene_file = f[1]  # FIXME Remove me

        task_type = Mock()
        ttb = TTaskBuilder(self.path)
        task_type.task_builder_type.return_value = ttb
        logic.task_types["TESTTASK"] = task_type

        rpc_publisher.reset()
        sync_wait(logic.run_test_task(ts))
        logic.progress_dialog.close()
        logic.test_task_started(True)
        self.assertTrue(
            logic.progress_dialog_customizer.gui.ui.abortButton.isEnabled())
        time.sleep(0.5)
        self.assertTrue(rpc_publisher.success)

        ttb.src_code = "import time\ntime.sleep(0.1)\n" \
                       "output = {'data': n, 'result_type': 0}"
        rpc_publisher.reset()
        sync_wait(logic.run_test_task(ts))
        logic.progress_dialog.close()
        time.sleep(0.5)
        self.assertTrue(rpc_publisher.success)

        # since PythonTestVM does not support end_comp() method,
        # this is only a smoke test instead of actual test
        ttb.src_code = "import time\ntime.sleep(0.1)\n" \
                       "output = {'data': n, 'result_type': 0}"
        rpc_publisher.reset()
        sync_wait(logic.run_test_task(ts))
        logic.progress_dialog.close()
        time.sleep(0.5)
        logic.abort_test_task()

        ttb.src_code = "raise Exception('some error')"
        rpc_publisher.reset()
        sync_wait(logic.run_test_task(ts))
        logic.progress_dialog.close()
        time.sleep(1)
        self.assertFalse(rpc_publisher.success)

        rpc_publisher.reset()
        sync_wait(logic.run_test_task(ts))
        logic.progress_dialog.close()
        self.assertFalse(rpc_publisher.success)

        ctr = logic.customizer.new_task_dialog_customizer
        prev_call_count = ctr.task_settings_changed.call_count
        logic.task_settings_changed()
        self.assertGreater(ctr.task_settings_changed.call_count,
                           prev_call_count)

        logic.tasks["xyz"] = ts
        logic.clone_task("xyz")

        self.assertEqual(
            logic.customizer.new_task_dialog_customizer.load_task_definition.
            call_args[0][0], ts.definition)

        ttb = TTaskBuilder(self.path, TTaskWithDef)
        logic.task_types["TESTTASK"].task_builder_type.return_value = ttb
        assert sync_wait(logic.run_test_task(ts))

        ttb = TTaskBuilder(self.path, TTaskWithError)
        logic.task_types["TESTTASK"].task_builder_type.return_value = ttb
        assert not sync_wait(logic.run_test_task(ts))
Beispiel #21
0
 def _finish_button_clicked(self):
     self.task_state = TaskDesc()
     self.task_state.status = TaskStatus.notStarted
     self.task_state.definition = self._query_task_definition()
     self._add_current_task()
     self.load_task_definition(self.task_state.definition)
Beispiel #22
0
 def test_init(self):
     td = TaskDesc()
     self.assertIsInstance(td, TaskDesc)