diff --git a/hrqb/base/task.py b/hrqb/base/task.py index 9eae539..2f536c8 100644 --- a/hrqb/base/task.py +++ b/hrqb/base/task.py @@ -334,8 +334,12 @@ def requires(self) -> Iterator[luigi.Task]: def verify_include_and_exclude_tasks_exist(self) -> None: """Verify that included and excluded tasks exist in the pipeline.""" filter_tasks = (self.include_tasks or ()) + (self.exclude_tasks or ()) + all_pipeline_tasks = { + task.name: task + for _, task in self.pipeline_tasks_iter(use_default_requires=True) + } for task_name in filter_tasks: - if self.get_task(task_name) is None: + if task_name not in all_pipeline_tasks: raise TaskNotInPipelineScopeError(task_name) @staticmethod diff --git a/hrqb/cli.py b/hrqb/cli.py index 834d1e4..189355a 100644 --- a/hrqb/cli.py +++ b/hrqb/cli.py @@ -138,7 +138,7 @@ def pipeline( pipeline_parameters=pipeline_parameters, ) except TaskNotInPipelineScopeError as exc: - message = f"--include-tasks or --exclude-task are invalid: {exc}, exiting" + message = f"CLI options --include or --exclude are invalid: {exc} Exiting." raise click.ClickException(message) from exc ctx.obj["PIPELINE_TASK"] = pipeline_task @@ -161,6 +161,8 @@ def remove_data(ctx: click.Context) -> None: pipeline_task = ctx.obj["PIPELINE_TASK"] pipeline_task.remove_pipeline_targets() logger.info("Successfully removed target data(s).") + logger.info("Updated status after data cleanup:") + logger.info(pipeline_task.pipeline_as_ascii()) @pipeline.command() @@ -183,5 +185,3 @@ def run( if cleanup: ctx.invoke(remove_data) - logger.info("Updated status after data cleanup:") - logger.info(pipeline_task.pipeline_as_ascii()) diff --git a/tests/test_cli.py b/tests/test_cli.py index 7fe3994..b644582 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -105,8 +105,8 @@ def test_cli_pipeline_remove_data_task_not_found( result = runner.invoke(cli.main, args) assert result.exit_code == ERROR_RESULT_CODE assert ( - "--include-tasks or --exclude-task are invalid: Task 'BadTask' not found in " - "pipeline" in result.output + "CLI options --include or --exclude are invalid: Task 'BadTask' not found in " + "pipeline. Exiting." in result.output ) @@ -211,8 +211,8 @@ def test_cli_pipeline_run_start_task_not_found_error(caplog, runner): result = runner.invoke(cli.main, args) assert result.exit_code == ERROR_RESULT_CODE assert ( - "--include-tasks or --exclude-task are invalid: Task 'BadTask' not found in " - "pipeline" in result.output + "CLI options --include or --exclude are invalid: Task 'BadTask' not found in " + "pipeline. Exiting." in result.output ) diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py new file mode 100644 index 0000000..852deb1 --- /dev/null +++ b/tests/test_exceptions.py @@ -0,0 +1,16 @@ +from hrqb.exceptions import ExcludedTaskRequiredError, TaskNotInPipelineScopeError + +TASK_NAME = "TaskFoo" + + +def test_excluded_task_required_exception_message(): + exc = ExcludedTaskRequiredError("TaskFoo") + assert str(exc) == ( + f"Task '{TASK_NAME}' was required by pipeline but is explicitly " + "excluded and does not have pre-existing target data." + ) + + +def test_task_not_in_pipeline_scope_exception_message(): + exc = TaskNotInPipelineScopeError("TaskFoo") + assert str(exc) == f"Task '{TASK_NAME}' not found in pipeline."