예제 #1
0
    def test_create_pos(self):

        curr_path = os.getcwd()
        dir_name = "new_test_dir"
        dir_path = os.path.join(curr_path, dir_name)
        self.DIRS_TO_REMOVE.append(dir_path)

        args = {
            "--destination": None,
            "--download": False,
            "--remote": False,
            "--upload": False,
            "--verbose": False,
            "<file_name>": None,
            "<dir_name>": dir_name,
            "create": True,
            "run": False,
        }

        app_ctrl = TaskController(args)
        app_ctrl.invoke()

        exp_result = os.path.join(dir_path, TaskController.DEFAULT_NEW_APP_FILENAME)

        self.assertTrue(os.path.isdir(dir_path))
        self.assertTrue(os.path.isfile(exp_result))
예제 #2
0
    def test_run_pos(self):

        filename = os.path.join("examples", "echo_task", "app.py")

        args = {
            "--destination": None,
            "--download": False,
            "--remote": False,
            "--upload": False,
            "--verbose": True,
            "<file_name>": filename,
            "<dir_name>": None,
            "create": False,
            "run": True,
        }

        app_ctrl = TaskController(args)
        app_ctrl.invoke()
        self.assertTrue(True)  # Test passes if no exception raised...

        # test with filename the doesn't exist
        args["<file_name>"] = "does_not_exist.py"

        app_ctrl = TaskController(args)

        try:
            app_ctrl.invoke()
        except ValueError as e:
            self.assertTrue("does not exist" in e.message)
예제 #3
0
    def test_create_dest_pos_abs(self):
        # Test with absolute destination.
        dir_name = "new_test_dir"
        dest_name = os.path.join(os.path.dirname(os.path.abspath(__file__)), "input", "data")
        dir_path = os.path.join(dest_name, dir_name)
        self.DIRS_TO_REMOVE.append(dir_path)

        args = {
            "--destination": dest_name,
            "--download": False,
            "--remote": False,
            "--upload": False,
            "--verbose": False,
            "<file_name>": None,
            "<dir_name>": dir_name,
            "create": True,
            "run": False,
        }

        app_ctrl = TaskController(args)
        app_ctrl.invoke()

        exp_result = os.path.join(dir_path, TaskController.DEFAULT_NEW_APP_FILENAME)

        self.assertTrue(os.path.isdir(dir_path))
        self.assertTrue(os.path.isfile(exp_result))
예제 #4
0
    def test_create_dest_neg(self):

        dir_name = "new_test_dir"

        bad_destinations = ["relative/path", ""]  # relative paths have to exist  # Empty string not allowed

        args = {
            "--download": False,
            "--remote": False,
            "--upload": False,
            "--verbose": False,
            "<file_name>": None,
            "<dir_name>": dir_name,
            "create": True,
            "run": False,
        }

        for baddest in bad_destinations:
            args["--destination"] = baddest
            app_ctrl = TaskController(args)

            try:
                app_ctrl.invoke()
                self.assertTrue(False)
            except ValueError as e:
                self.assertTrue("not a directory" in e.message or "path is empty" in e.message)
예제 #5
0
    def test_create_neg(self):

        bad_dir_names = ["/new_test_app", "my/dir"]  # abs paths not allowed  # No path seperators allowed.

        args = {
            "--destination": None,
            "--download": False,
            "--remote": False,
            "--upload": False,
            "--verbose": False,
            "<file_name>": None,
            "create": True,
            "run": False,
        }

        for baddir in bad_dir_names:
            args["<dir_name>"] = baddir
            app_ctrl = TaskController(args)

            try:
                app_ctrl.invoke()
                self.assertTrue(False)
            except ValueError as e:
                self.assertTrue("Directory name is invalid" in e.message)
예제 #6
0
    def upload_input_ports(self):
        """
        Upload any local ports the users account storage prior to the
        execution of the workflow.

        Args:
            None

        Returns:
            None
        """
        task_ctl = TaskController(
            {
                '--remote': True,  # Flag that the task is to be run remotely.
                '--upload': True,  # Flag to upload the ports before execution
                '--dry-run': True,  # Flag to skip the execution of the task.
                '<file_name>': self.task_template,
                'create': False,
                'register': False,
                'run': True
            }
        )

        # There are 2 versions of the input ports. The ones defined in the cloud-harness.TaskTemplate subclass,
        #  and the ones defined through gbdxtools.Task. If the input port is overridden by gbdxtools.Task, then the
        #  value in the class cloud-harness.TaskTemplate must be replaced.s

        # Task ports before uploading.
        ch_input_ports = self.task.input_ports

        for port in ch_input_ports:
            gbdx_task_port = self._get_input_port(port.name)

            if gbdx_task_port is not None and gbdx_task_port.value is not None:
                # Overwrite the cloud-harness value with the gbdxtools value.
                port.value = gbdx_task_port.value

        task = task_ctl.invoke()

        # Get uploaded port locations
        ch_input_ports = task.input_ports

        for port in ch_input_ports:
            gbdx_task_port = self._get_input_port(port.name)

            if gbdx_task_port is not None and gbdx_task_port.value != port.value:
                # If there is no gbdxtools value, use the cloud-harness value (after uploading).
                gbdx_task_port.value = port.value