diff --git a/docs/source/changes.rst b/docs/source/changes.rst index e1f5223a..2edd9aee 100644 --- a/docs/source/changes.rst +++ b/docs/source/changes.rst @@ -11,6 +11,7 @@ all releases are available on `PyPI `_ and ------------------ - :gh:`186` enhance live displays by deactivating auto-refresh among other things. +- :gh:`188` refactors some code related to :class:`_pytask.enums.ExitCode`. 0.1.4 - 2022-01-04 diff --git a/src/_pytask/build.py b/src/_pytask/build.py index 80512109..f7ec28e6 100644 --- a/src/_pytask/build.py +++ b/src/_pytask/build.py @@ -7,11 +7,11 @@ import click from _pytask.config import hookimpl from _pytask.console import console -from _pytask.enums import ExitCode from _pytask.exceptions import CollectionError from _pytask.exceptions import ConfigurationError from _pytask.exceptions import ExecutionError from _pytask.exceptions import ResolvingDependenciesError +from _pytask.outcomes import ExitCode from _pytask.pluginmanager import get_plugin_manager from _pytask.session import Session diff --git a/src/_pytask/clean.py b/src/_pytask/clean.py index 7b668b22..6abd7307 100644 --- a/src/_pytask/clean.py +++ b/src/_pytask/clean.py @@ -20,9 +20,9 @@ from _pytask.config import hookimpl from _pytask.config import IGNORED_TEMPORARY_FILES_AND_FOLDERS from _pytask.console import console -from _pytask.enums import ExitCode from _pytask.exceptions import CollectionError from _pytask.nodes import MetaTask +from _pytask.outcomes import ExitCode from _pytask.path import find_common_ancestor from _pytask.path import relative_to from _pytask.pluginmanager import get_plugin_manager diff --git a/src/_pytask/collect_command.py b/src/_pytask/collect_command.py index 5b1ee29b..5e813338 100644 --- a/src/_pytask/collect_command.py +++ b/src/_pytask/collect_command.py @@ -15,12 +15,12 @@ from _pytask.console import format_task_id from _pytask.console import PYTHON_ICON from _pytask.console import TASK_ICON -from _pytask.enums import ExitCode from _pytask.exceptions import CollectionError from _pytask.exceptions import ConfigurationError from _pytask.exceptions import ResolvingDependenciesError from _pytask.mark import select_by_keyword from _pytask.mark import select_by_mark +from _pytask.outcomes import ExitCode from _pytask.path import find_common_ancestor from _pytask.path import relative_to from _pytask.pluginmanager import get_plugin_manager diff --git a/src/_pytask/enums.py b/src/_pytask/enums.py deleted file mode 100644 index 90328998..00000000 --- a/src/_pytask/enums.py +++ /dev/null @@ -1,20 +0,0 @@ -"""Enumerations for pytask.""" -import enum - - -class ExitCode(enum.IntEnum): - """Exit codes for pytask.""" - - OK = 0 - """Tasks were executed successfully.""" - - FAILED = 1 - """Failed while executing tasks.""" - - CONFIGURATION_FAILED = 2 - - COLLECTION_FAILED = 3 - """Failed while collecting tasks.""" - - RESOLVING_DEPENDENCIES_FAILED = 4 - """Failed while resolving dependencies.""" diff --git a/src/_pytask/graph.py b/src/_pytask/graph.py index 6734b5f1..29c3ce12 100644 --- a/src/_pytask/graph.py +++ b/src/_pytask/graph.py @@ -13,10 +13,10 @@ from _pytask.config import hookimpl from _pytask.console import console from _pytask.dag import descending_tasks -from _pytask.enums import ExitCode from _pytask.exceptions import CollectionError from _pytask.exceptions import ConfigurationError from _pytask.exceptions import ResolvingDependenciesError +from _pytask.outcomes import ExitCode from _pytask.pluginmanager import get_plugin_manager from _pytask.session import Session from _pytask.shared import get_first_non_none_value diff --git a/src/_pytask/live.py b/src/_pytask/live.py index a47400fa..d0582b7e 100644 --- a/src/_pytask/live.py +++ b/src/_pytask/live.py @@ -265,20 +265,24 @@ class LiveCollection: @hookimpl(hookwrapper=True) def pytask_collect(self) -> Generator[None, None, None]: + """Start the status of the cllection.""" self._live_manager.start() yield @hookimpl def pytask_collect_file_log(self, reports: List[CollectionReport]) -> None: + """Update the status after a file is collected.""" self._update_statistics(reports) self._update_status() @hookimpl(hookwrapper=True) def pytask_collect_log(self) -> Generator[None, None, None]: + """Stop the live display when all tasks have been collected.""" self._live_manager.stop(transient=True) yield def _update_statistics(self, reports: List[CollectionReport]) -> None: + """Update the statistics on collected tasks and errors.""" if reports is None: reports = [] for report in reports: @@ -288,10 +292,12 @@ def _update_statistics(self, reports: List[CollectionReport]) -> None: self._n_errors += 1 def _update_status(self) -> None: + """Update the status.""" status = self._generate_status() self._live_manager.update(status) def _generate_status(self) -> Status: + """Generate the status.""" msg = f"Collected {self._n_collected_tasks} tasks." if self._n_errors > 0: msg += f" {self._n_errors} errors." diff --git a/src/_pytask/logging.py b/src/_pytask/logging.py index 13cc9c6f..29e5b7f0 100644 --- a/src/_pytask/logging.py +++ b/src/_pytask/logging.py @@ -56,6 +56,7 @@ def pytask_parse_config( config_from_file: Dict[str, Any], config_from_cli: Dict[str, Any], ) -> None: + """Parse configuration.""" config["show_locals"] = get_first_non_none_value( config_from_cli, config_from_file, @@ -138,6 +139,7 @@ def pytask_log_session_footer( def _format_duration(duration: float) -> str: + """Format the duration.""" duration_tuples = _humanize_time(duration, "seconds", short_label=False) # Remove seconds if the execution lasted days or hours. diff --git a/src/_pytask/mark/__init__.py b/src/_pytask/mark/__init__.py index b1a576e8..8b3b5123 100644 --- a/src/_pytask/mark/__init__.py +++ b/src/_pytask/mark/__init__.py @@ -11,7 +11,6 @@ from _pytask.config import hookimpl from _pytask.console import console from _pytask.dag import task_and_preceding_tasks -from _pytask.enums import ExitCode from _pytask.exceptions import ConfigurationError from _pytask.mark.expression import Expression from _pytask.mark.expression import ParseError @@ -20,6 +19,7 @@ from _pytask.mark.structures import MarkDecorator from _pytask.mark.structures import MarkGenerator from _pytask.nodes import MetaTask +from _pytask.outcomes import ExitCode from _pytask.pluginmanager import get_plugin_manager from _pytask.session import Session from _pytask.shared import convert_truthy_or_falsy_to_bool diff --git a/src/_pytask/outcomes.py b/src/_pytask/outcomes.py index 308bf63f..394fa05d 100644 --- a/src/_pytask/outcomes.py +++ b/src/_pytask/outcomes.py @@ -1,6 +1,7 @@ """This module contains code related to outcomes.""" from enum import auto from enum import Enum +from enum import IntEnum from typing import Dict from typing import Optional from typing import Sequence @@ -99,6 +100,7 @@ class TaskOutcome(Enum): @property def symbol(self) -> str: + """The symbol of an outcome.""" symbols = { TaskOutcome.SUCCESS: ".", TaskOutcome.PERSISTENCE: "p", @@ -112,6 +114,7 @@ def symbol(self) -> str: @property def description(self) -> str: + """A description of an outcome used in the summary panel.""" descriptions = { TaskOutcome.SUCCESS: "Succeeded", TaskOutcome.PERSISTENCE: "Persisted", @@ -125,6 +128,7 @@ def description(self) -> str: @property def style(self) -> str: + """Return the style of an outcome.""" styles = { TaskOutcome.SUCCESS: "success", TaskOutcome.PERSISTENCE: "success", @@ -138,6 +142,7 @@ def style(self) -> str: @property def style_textonly(self) -> str: + """Return the style of an outcome when only the text is colored.""" styles_textonly = { TaskOutcome.SUCCESS: "success.textonly", TaskOutcome.PERSISTENCE: "success.textonly", @@ -169,6 +174,24 @@ def count_outcomes( } +class ExitCode(IntEnum): + """Exit codes for pytask.""" + + OK = 0 + """Tasks were executed successfully.""" + + FAILED = 1 + """Failed while executing tasks.""" + + CONFIGURATION_FAILED = 2 + + COLLECTION_FAILED = 3 + """Failed while collecting tasks.""" + + RESOLVING_DEPENDENCIES_FAILED = 4 + """Failed while resolving dependencies.""" + + class PytaskOutcome(Exception): """Base outcome of a task.""" diff --git a/src/_pytask/profile.py b/src/_pytask/profile.py index 89ae79c6..2003f475 100644 --- a/src/_pytask/profile.py +++ b/src/_pytask/profile.py @@ -20,11 +20,11 @@ from _pytask.console import console from _pytask.console import format_task_id from _pytask.database import db -from _pytask.enums import ExitCode from _pytask.exceptions import CollectionError from _pytask.exceptions import ConfigurationError from _pytask.nodes import FilePathNode from _pytask.nodes import MetaTask +from _pytask.outcomes import ExitCode from _pytask.outcomes import TaskOutcome from _pytask.pluginmanager import get_plugin_manager from _pytask.report import ExecutionReport diff --git a/src/_pytask/session.py b/src/_pytask/session.py index a2fe8109..dc74eb09 100644 --- a/src/_pytask/session.py +++ b/src/_pytask/session.py @@ -6,7 +6,7 @@ import attr import networkx as nx -from _pytask.enums import ExitCode +from _pytask.outcomes import ExitCode # Location was moved from pluggy v0.13.1 to v1.0.0. diff --git a/src/pytask/__init__.py b/src/pytask/__init__.py index 91b40312..e6d25448 100644 --- a/src/pytask/__init__.py +++ b/src/pytask/__init__.py @@ -1,3 +1,4 @@ +"""This module contains the main namespace for pytask.""" from _pytask import __version__ from _pytask.build import main from _pytask.cli import cli diff --git a/tests/test_build.py b/tests/test_build.py index dbf02c5d..2574f9ec 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -1,6 +1,7 @@ import textwrap import pytest +from _pytask.outcomes import ExitCode from pytask import cli @@ -13,13 +14,13 @@ def task_raises(): tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source)) result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 1 + assert result.exit_code == ExitCode.FAILED @pytest.mark.end_to_end def test_configuration_failed(runner, tmp_path): result = runner.invoke(cli, [tmp_path.joinpath("non_existent_path").as_posix()]) - assert result.exit_code == 2 + assert result.exit_code == ExitCode.CONFIGURATION_FAILED @pytest.mark.end_to_end @@ -30,7 +31,7 @@ def test_collection_failed(runner, tmp_path): tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source)) result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 3 + assert result.exit_code == ExitCode.COLLECTION_FAILED @pytest.mark.end_to_end @@ -51,4 +52,4 @@ def task_passes_2(): tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source)) result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 4 + assert result.exit_code == ExitCode.RESOLVING_DEPENDENCIES_FAILED diff --git a/tests/test_capture.py b/tests/test_capture.py index 3bbd684e..8914a45c 100644 --- a/tests/test_capture.py +++ b/tests/test_capture.py @@ -17,6 +17,7 @@ from _pytask.capture import CaptureManager from _pytask.capture import CaptureResult from _pytask.capture import MultiCapture +from _pytask.outcomes import ExitCode from pytask import cli @@ -78,7 +79,7 @@ def task_show_capture(): cmd_arg = "-s" if show_capture == "s" else f"--show-capture={show_capture}" result = runner.invoke(cli, [tmp_path.as_posix(), cmd_arg]) - assert result.exit_code == 1 + assert result.exit_code == ExitCode.FAILED if show_capture in ["no", "s"]: assert "Captured" not in result.output @@ -197,7 +198,7 @@ def task_unicode(): result = runner.invoke(cli, [tmp_path.as_posix(), f"--capture={method}"]) assert "1 Succeeded" in result.output - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK @pytest.mark.end_to_end @@ -214,7 +215,7 @@ def task_unicode(): result = runner.invoke(cli, [tmp_path.as_posix(), f"--capture={method}"]) assert "1 Succeeded" in result.output - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK @pytest.mark.end_to_end @@ -739,7 +740,7 @@ def task_stdin(): tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source)) result = runner.invoke(cli, [tmp_path.as_posix(), "--capture=fd"]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK assert "3 Succeeded" in result.output def test_fdcapture_invalid_fd_with_fd_reuse(self, tmp_path): diff --git a/tests/test_clean.py b/tests/test_clean.py index 31dd4ef2..4873f3c8 100644 --- a/tests/test_clean.py +++ b/tests/test_clean.py @@ -1,6 +1,7 @@ import textwrap import pytest +from _pytask.outcomes import ExitCode from pytask import cli @@ -153,7 +154,7 @@ def test_configuration_failed(runner, tmp_path): result = runner.invoke( cli, ["clean", tmp_path.joinpath("non_existent_path").as_posix()] ) - assert result.exit_code == 2 + assert result.exit_code == ExitCode.CONFIGURATION_FAILED @pytest.mark.end_to_end @@ -164,4 +165,4 @@ def test_collection_failed(runner, tmp_path): tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source)) result = runner.invoke(cli, ["clean", tmp_path.as_posix()]) - assert result.exit_code == 3 + assert result.exit_code == ExitCode.COLLECTION_FAILED diff --git a/tests/test_collect.py b/tests/test_collect.py index 60114ff9..5c280a67 100644 --- a/tests/test_collect.py +++ b/tests/test_collect.py @@ -10,6 +10,7 @@ from _pytask.nodes import create_task_name from _pytask.nodes import PythonFunctionTask from _pytask.outcomes import CollectionOutcome +from _pytask.outcomes import ExitCode from _pytask.session import Session from pytask import cli from pytask import main @@ -78,7 +79,7 @@ def task_1(depends_on, produces): result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK assert tmp_path.joinpath("out_0.txt").read_text() == "in root" assert tmp_path.joinpath("out_1.txt").read_text() == "in sub" diff --git a/tests/test_database.py b/tests/test_database.py index 73f1a8fa..e1102544 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -4,6 +4,7 @@ import pytest from _pytask.database import create_database from _pytask.database import State +from _pytask.outcomes import ExitCode from pony import orm from pytask import cli @@ -27,7 +28,7 @@ def task_write(produces): os.chdir(tmp_path) result = runner.invoke(cli) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK with orm.db_session: diff --git a/tests/test_debugging.py b/tests/test_debugging.py index 682a98e3..16231702 100644 --- a/tests/test_debugging.py +++ b/tests/test_debugging.py @@ -6,6 +6,7 @@ import pytest from _pytask.debugging import _pdbcls_callback +from _pytask.outcomes import ExitCode from pytask import cli try: @@ -442,7 +443,7 @@ def helper(): tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source)) result = runner.invoke(cli, [tmp_path.as_posix(), "--show-locals"]) - assert result.exit_code == 1 + assert result.exit_code == ExitCode.FAILED captured = result.output assert " locals " in captured diff --git a/tests/test_execute.py b/tests/test_execute.py index 70372335..20ef1363 100644 --- a/tests/test_execute.py +++ b/tests/test_execute.py @@ -4,6 +4,7 @@ import pytest from _pytask.exceptions import NodeNotFoundError +from _pytask.outcomes import ExitCode from _pytask.outcomes import TaskOutcome from pytask import cli from pytask import main @@ -149,7 +150,7 @@ def task_example(depends_on, produces): result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK @pytest.mark.end_to_end @@ -177,7 +178,7 @@ def task_example(depends_on, produces): result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK @pytest.mark.end_to_end @@ -280,7 +281,7 @@ def task_mixed(): pass result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 4 + assert result.exit_code == ExitCode.RESOLVING_DEPENDENCIES_FAILED assert "Failures during resolving dependencies" in result.output assert "'try_first' and 'try_last' cannot be applied" in result.output @@ -299,7 +300,7 @@ def task_error(): raise ValueError args.append("--show-errors-immediately") result = runner.invoke(cli, args) - assert result.exit_code == 1 + assert result.exit_code == ExitCode.FAILED assert "::task_succeed │ ." in result.output matches_traceback = re.findall("Traceback", result.output) diff --git a/tests/test_graph.py b/tests/test_graph.py index 3bf27b01..0e014909 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -2,6 +2,7 @@ import textwrap import pytest +from _pytask.outcomes import ExitCode from pytask import cli try: @@ -54,7 +55,7 @@ def task_example(): pass ], ) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK assert tmp_path.joinpath(f"dag.{format_}").exists() @@ -82,7 +83,7 @@ def task_create_graph(): result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK assert tmp_path.joinpath(f"dag.{format_}").exists() @@ -113,7 +114,7 @@ def task_example(): pass ["dag", tmp_path.as_posix(), "-o", tmp_path.joinpath("dag.png"), "-l", "dot"], ) - assert result.exit_code == 1 + assert result.exit_code == ExitCode.FAILED assert "pytask requires the optional dependency 'pydot'." in result.output assert "pip or conda" in result.output assert "Traceback" not in result.output @@ -144,7 +145,7 @@ def task_create_graph(): result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 1 + assert result.exit_code == ExitCode.FAILED assert "pytask requires the optional dependency 'pydot'." in result.output assert "pip or conda" in result.output assert "Traceback" in result.output @@ -174,7 +175,7 @@ def task_example(): pass ["dag", tmp_path.as_posix(), "-o", tmp_path.joinpath("dag.png"), "-l", "dot"], ) - assert result.exit_code == 1 + assert result.exit_code == ExitCode.FAILED assert "pytask requires the optional program 'dot'." in result.output assert "conda" in result.output assert "Traceback" not in result.output @@ -205,7 +206,7 @@ def task_create_graph(): result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 1 + assert result.exit_code == ExitCode.FAILED assert "pytask requires the optional program 'dot'." in result.output assert "conda" in result.output assert "Traceback" in result.output diff --git a/tests/test_live.py b/tests/test_live.py index 03624b08..46205620 100644 --- a/tests/test_live.py +++ b/tests/test_live.py @@ -6,6 +6,7 @@ from _pytask.live import LiveExecution from _pytask.live import LiveManager from _pytask.nodes import PythonFunctionTask +from _pytask.outcomes import ExitCode from _pytask.outcomes import TaskOutcome from _pytask.report import ExecutionReport from pytask import cli @@ -215,7 +216,7 @@ def task_create_file(produces): cli, [tmp_path.joinpath("d").as_posix(), "--n-entries-in-table=1"] ) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK for i in range(4): assert f"{i}.txt" in result.output @@ -238,5 +239,5 @@ def func(): ... tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source)) result = runner.invoke(cli, [tmp_path.joinpath("task_module.py").as_posix()]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK assert "task_func" in result.output diff --git a/tests/test_mark.py b/tests/test_mark.py index 23d64ea7..112e6d62 100644 --- a/tests/test_mark.py +++ b/tests/test_mark.py @@ -4,6 +4,7 @@ import pytask import pytest from _pytask.mark import MarkGenerator +from _pytask.outcomes import ExitCode from pytask import cli from pytask import main @@ -282,7 +283,7 @@ def test_configuration_failed(runner, tmp_path): result = runner.invoke( cli, ["markers", "-c", tmp_path.joinpath("non_existent_path").as_posix()] ) - assert result.exit_code == 2 + assert result.exit_code == ExitCode.CONFIGURATION_FAILED @pytest.mark.end_to_end @@ -303,7 +304,7 @@ def task_second(depends_on): result = runner.invoke(cli, [tmp_path.as_posix(), "-k", "second"]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK assert "2 Succeeded" in result.output @@ -325,7 +326,7 @@ def task_second(depends_on): result = runner.invoke(cli, [tmp_path.as_posix(), "-m", "wip"]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK assert "2 Succeeded" in result.output @@ -345,7 +346,7 @@ def task_second(): result = runner.invoke(cli, [tmp_path.as_posix(), "-k", "second"]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK assert "1 Succeeded" in result.output assert "1 Skipped" in result.output @@ -367,6 +368,6 @@ def task_second(): result = runner.invoke(cli, [tmp_path.as_posix(), "-m", "wip"]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK assert "1 Succeeded" in result.output assert "1 Skipped" in result.output diff --git a/tests/test_parametrize.py b/tests/test_parametrize.py index 110ae91f..375e305c 100644 --- a/tests/test_parametrize.py +++ b/tests/test_parametrize.py @@ -6,6 +6,7 @@ import pytask import pytest from _pytask.mark import Mark +from _pytask.outcomes import ExitCode from _pytask.parametrize import _arg_value_to_id_component from _pytask.parametrize import _parse_arg_names from _pytask.parametrize import _parse_parametrize_markers @@ -402,6 +403,6 @@ def task_func(): result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 3 + assert result.exit_code == ExitCode.COLLECTION_FAILED for c in content: assert c in result.output diff --git a/tests/test_profile.py b/tests/test_profile.py index 623f9163..a31b48ae 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -4,6 +4,7 @@ import pytest from _pytask.cli import cli from _pytask.database import create_database +from _pytask.outcomes import ExitCode from _pytask.profile import Runtime from pony import orm from pytask import main @@ -40,7 +41,7 @@ def task_example(): time.sleep(2) def test_profile_if_no_tasks_are_collected(tmp_path, runner): result = runner.invoke(cli, ["profile", tmp_path.as_posix()]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK assert "No information is stored on the collected tasks." in result.output @@ -54,7 +55,7 @@ def task_example(): time.sleep(2) result = runner.invoke(cli, ["profile", tmp_path.as_posix()]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK assert "Collected 1 task." in result.output assert "No information is stored on the collected tasks." in result.output @@ -71,7 +72,7 @@ def task_example(): time.sleep(2) result = runner.invoke(cli, ["profile", tmp_path.as_posix()]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK assert "Collected 1 task." in result.output assert "Duration (in s)" in result.output assert "0." in result.output @@ -91,7 +92,7 @@ def task_example(): time.sleep(2) os.chdir(tmp_path) result = runner.invoke(cli, ["profile", tmp_path.as_posix(), "--export", export]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK assert "Collected 1 task." in result.output assert "Duration (in s)" in result.output assert "0." in result.output diff --git a/tests/test_resolve_dependencies.py b/tests/test_resolve_dependencies.py index dd369b15..34c65bd3 100644 --- a/tests/test_resolve_dependencies.py +++ b/tests/test_resolve_dependencies.py @@ -9,6 +9,7 @@ from _pytask.exceptions import ResolvingDependenciesError from _pytask.nodes import FilePathNode from _pytask.nodes import PythonFunctionTask +from _pytask.outcomes import ExitCode from _pytask.resolve_dependencies import _check_if_root_nodes_are_available from _pytask.resolve_dependencies import pytask_resolve_dependencies_create_dag from pytask import cli @@ -89,7 +90,7 @@ def task_d(produces): result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 4 + assert result.exit_code == ExitCode.RESOLVING_DEPENDENCIES_FAILED assert "Failures during resolving dependencies" in result.output # Ensure that node names are reduced. @@ -119,7 +120,7 @@ def task_d(produces): result = runner.invoke(cli, [tmp_path.joinpath("src").as_posix()]) - assert result.exit_code == 4 + assert result.exit_code == ExitCode.RESOLVING_DEPENDENCIES_FAILED assert "Failures during resolving dependencies" in result.output # Ensure that node names are reduced. @@ -150,7 +151,7 @@ def task_2(produces): result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 4 + assert result.exit_code == ExitCode.RESOLVING_DEPENDENCIES_FAILED assert "Failures during resolving dependencies" in result.output assert "The DAG contains cycles which means a dependency" in result.output @@ -172,7 +173,7 @@ def task_2(produces): result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 4 + assert result.exit_code == ExitCode.RESOLVING_DEPENDENCIES_FAILED assert "Failures during resolving dependencies" in result.output assert "There are some tasks which produce the same output." in result.output @@ -199,9 +200,9 @@ def task_example(produces): tmp_path.joinpath("task_example.py").write_text(textwrap.dedent(source)) result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK tmp_path.joinpath("file.txt").unlink() result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 0 + assert result.exit_code == ExitCode.OK diff --git a/tests/test_skipping.py b/tests/test_skipping.py index 1c1e9745..b02e6620 100644 --- a/tests/test_skipping.py +++ b/tests/test_skipping.py @@ -3,6 +3,7 @@ import pytest from _pytask.mark import Mark +from _pytask.outcomes import ExitCode from _pytask.outcomes import Skipped from _pytask.outcomes import SkippedAncestorFailed from _pytask.outcomes import SkippedUnchanged @@ -145,7 +146,7 @@ def task_second(): result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == 4 + assert result.exit_code == ExitCode.RESOLVING_DEPENDENCIES_FAILED assert "in.txt" in result.output assert "task_first" not in result.output assert "task_second" in result.output diff --git a/tests/test_traceback.py b/tests/test_traceback.py index b954f1ea..49c30775 100644 --- a/tests/test_traceback.py +++ b/tests/test_traceback.py @@ -1,6 +1,7 @@ import textwrap import pytest +from _pytask.outcomes import ExitCode from pytask import cli @@ -23,5 +24,5 @@ def helper(): result = runner.invoke(cli, [tmp_path.as_posix(), "--show-locals"]) - assert result.exit_code == 1 + assert result.exit_code == ExitCode.FAILED assert ("This variable should not be shown." in result.output) is not is_hidden