예제 #1
0
    def test_template(self) -> None:
        tasks = Tasks()

        with patch('sys.stdout', io.StringIO()) as mock_io:
            tasks.template(None)
            output = mock_io.getvalue()

        self.assertIn("bid", output)
        self.assertIn("0.0", output)
        self.assertIn('"subtask_timeout": "0:00:00"', output)

        self.assertEqual(json.loads(output), TaskDefinition().to_dict())

        temp = self.temp_file_name("test_template")
        tasks.template(temp)
        with open(temp) as f:
            content = f.read()
            self.assertEqual(content, output)

        with client_ctx(Tasks, self.client):
            Tasks.client.get_task.return_value = TaskDefinition().to_dict()
            tasks.dump('id', temp)

        with open(temp) as f:
            content_dump = f.read()
            self.assertEqual(content, content_dump)
예제 #2
0
 def __init__(self):
     TaskDefinition.__init__(self)
     self.resolution = [0, 0]
     self.renderer = None
     self.options = None
     self.main_scene_file = ""
     self.output_format = ""
예제 #3
0
    def test_create(self) -> None:
        client = self.client

        definition = TaskDefinition()
        definition.name = "The greatest task ever"
        def_str = json.dumps(definition.to_dict())

        with client_ctx(Tasks, client):
            tasks = Tasks()
            # pylint: disable=no-member
            tasks._Tasks__create_from_json(def_str)  # type: ignore
            # pylint: enable=no-member
            client._call.assert_called_once_with(
                'comp.task.create',
                definition.to_dict(),
            )

            client._call.reset_mock()
            patched_open = "golem.interface.client.tasks.open"
            with patch(patched_open,
                       mock_open(read_data='{"name": "Golem task"}')):
                client._call.return_value = ('task_id', None)
                tasks.create("foo")
                task_def = json.loads('{"name": "Golem task"}')
                client._call.assert_called_once_with(
                    'comp.task.create',
                    task_def,
                    force=False,
                )
예제 #4
0
 def _get_task_definition(task_id="xyz",
                          full_task_timeout=100,
                          subtask_timeout=50):
     td = TaskDefinition()
     td.task_id = task_id
     td.full_task_timeout = full_task_timeout
     td.subtask_timeout = subtask_timeout
     return td
예제 #5
0
    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)
예제 #6
0
 def _get_core_task_definition():
     task_definition = TaskDefinition()
     task_definition.max_price = 100
     task_definition.task_id = "xyz"
     task_definition.estimated_memory = 1024
     task_definition.timeout = 3000
     task_definition.subtask_timeout = 30
     return task_definition
예제 #7
0
    def __init__(self, defaults=None):
        TaskDefinition.__init__(self)

        self.options = DummyTaskOptions()
        self.task_type = 'DUMMY'

        # subtask data
        self.shared_data_files = []

        # subtask code
        self.code_dir = os.path.join(get_golem_path(), "apps", "dummy",
                                     "resources", "code_dir")
        self.code_files = []

        self.result_size = 256  # length of result hex number
        self.out_file_basename = "out"

        if defaults:
            self.set_defaults(defaults)
예제 #8
0
    def test_preset(self):
        tdf = TaskDefinition()
        tdf.subtasks_count = 12
        tdf.options.name = "OptionsName"
        tdf.optimize_total = True
        tdf.verification_options = "Option"
        preset = tdf.make_preset()
        assert len(preset) == 4
        assert preset["options"].name == "OptionsName"
        assert preset["verification_options"] == "Option"
        assert preset["subtasks_count"] == 12
        assert preset["optimize_total"]

        tdf2 = TaskDefinition()
        assert tdf2.options.name == ""
        assert tdf2.verification_options is None
        assert tdf2.subtasks_count == 0
        assert not tdf2.optimize_total

        tdf2.load_preset(preset)
        assert tdf2.options.name == "OptionsName"
        assert tdf2.verification_options == "Option"
        assert tdf2.subtasks_count == 12
        assert tdf2.optimize_total
예제 #9
0
 def _get_core_task(self):
     task_definition = TaskDefinition()
     task_definition.max_price = 100
     task_definition.task_id = "xyz"
     task_definition.estimated_memory = 1024
     task_definition.full_task_timeout = 3000
     task_definition.subtask_timeout = 30
     task = CoreTask(
         src_code="src code",
         task_definition=task_definition,
         node_name="ABC",
         owner_address="10.10.10.10",
         owner_port=123,
         owner_key_id="key",
         environment="environment",
         resource_size=1024,
     )
     dm = DirManager(self.path)
     task.initialize(dm)
     return task
예제 #10
0
파일: taskbase.py 프로젝트: U0001F3A2/golem
 def build_dictionary(definition: TaskDefinition) -> dict:
     return definition.to_dict()
예제 #11
0
 def setUp(self):
     self.task_definition = TaskDefinition()
     self.assertTrue(hasattr(self.task_definition, 'compute_on'))
     self.assertTrue(hasattr(self.task_definition, 'concent_enabled'))
     super().setUp()
예제 #12
0
 def setUp(self):
     self.task_definition = TaskDefinition()
     self.assertTrue(hasattr(self.task_definition, 'name'))
     self.assertTrue(hasattr(self.task_definition, 'timeout'))
     self.assertTrue(hasattr(self.task_definition, 'subtasks_count'))
     super().setUp()
예제 #13
0
 def template(self, outfile: Optional[str]) -> None:
     template = TaskDefinition()
     self.__dump_dict(template.to_dict(), outfile)
예제 #14
0
 def __init__(self):
     super(TTaskWithDef, self).__init__()
     self.task_definition = TaskDefinition()
     self.task_definition.max_price = "ABCDEFGHT"
예제 #15
0
 def __init__(self):
     super(TTaskWithDef, self).__init__()
     self.task_definition = TaskDefinition()
     self.task_definition.max_price = 100 * denoms.ether
예제 #16
0
    def setUp(self):
        super(TestRenderingTask, self).setUp()
        files = self.additional_dir_content([3])
        task_definition = TaskDefinition()
        task_definition.max_price = 1000
        task_definition.task_id = "xyz"
        task_definition.estimated_memory = 1024
        task_definition.full_task_timeout = 3600
        task_definition.subtask_timeout = 600
        task_definition.main_scene_file = files[1]
        task_definition.resolution = [800, 600]
        task_definition.output_file = files[2]
        task_definition.output_format = ".png"

        task = RenderingTaskMock(
            main_program_file=files[0],
            node_name="ABC",
            task_definition=task_definition,
            total_tasks=100,
            root_path=self.path,
            owner_address="10.10.10.10",
            owner_port=1023,
            owner_key_id="keyid",
        )

        dm = DirManager(self.path)
        task.initialize(dm)
        self.task = task
예제 #17
0
 def test_get_output_path(self):
     td = TaskDefinition()
     td.name = "MY task"
     tdict = {'options': {'output_path': '/dir3/dir4', 'format': 'txt'}}
     assert RenderingTaskBuilder.get_output_path(tdict, td) == \
         path.join("/dir3/dir4", "MY task.txt")