Skip to content

Test _pytask.mark_utils. #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
systems.
- :gh:`200` implements the :func:`@pytask.mark.task <_pytask.task.task>` decorator to
mark functions as tasks regardless whether they are prefixed with ``task_`` or not.
- :gh:`201` adds tests for ``_pytask.mark_utils``.


0.1.5 - 2022-01-10
Expand Down
1 change: 1 addition & 0 deletions tests/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def test_pytask_collect_node_does_not_raise_error_if_path_is_not_normalized(
assert not record


@pytest.mark.unit
def test_find_shortest_uniquely_identifiable_names_for_tasks(tmp_path):
tasks = []
expected = {}
Expand Down
3 changes: 3 additions & 0 deletions tests/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def test_render_to_string(color_system, text, strip_styles, expected):
_THIS_FILE = Path(__file__)


@pytest.mark.unit
@pytest.mark.parametrize(
"base_name, short_name, editor_url_scheme, use_short_name, relative_to, expected",
[
Expand Down Expand Up @@ -175,6 +176,7 @@ def test_format_task_id(
assert result == expected


@pytest.mark.unit
@pytest.mark.parametrize(
"task_func, skipped_paths, expected",
[
Expand All @@ -196,6 +198,7 @@ def test_get_file(task_func, skipped_paths, expected):
assert result == expected


@pytest.mark.unit
@pytest.mark.parametrize(
"task_func, expected",
[
Expand Down
1 change: 1 addition & 0 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def test_humanize_time(amount, unit, short_label, expectation, expected):
assert result == expected


@pytest.mark.end_to_end
@pytest.mark.parametrize("show_traceback", ["no", "yes"])
def test_show_traceback(runner, tmp_path, show_traceback):
source = "def task_raises(): raise Exception"
Expand Down
134 changes: 134 additions & 0 deletions tests/test_mark_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import attr
import pytask
import pytest
from _pytask.mark_utils import get_marks_from_obj
from _pytask.mark_utils import get_specific_markers_from_task
from _pytask.mark_utils import has_marker
from _pytask.mark_utils import remove_markers_from_func
from _pytask.nodes import MetaTask


@attr.s
class Task(MetaTask):
markers = attr.ib(factory=list)

def execute(self):
...

def state(self):
...

def add_report_section(self):
...


@pytest.mark.unit
@pytest.mark.parametrize(
"markers, marker_name, expected",
[
([], "not_found", []),
(
[pytask.mark.produces(), pytask.mark.depends_on()],
"produces",
[pytask.mark.produces()],
),
(
[pytask.mark.produces(), pytask.mark.produces(), pytask.mark.depends_on()],
"produces",
[pytask.mark.produces(), pytask.mark.produces()],
),
],
)
def test_get_specific_markers_from_task(markers, marker_name, expected):
task = Task()
task.markers = markers
result = get_specific_markers_from_task(task, marker_name)
assert result == expected


@pytest.mark.unit
@pytest.mark.parametrize(
"markers, marker_name, expected",
[
(None, "not_found", []),
([], "not_found", []),
(
[pytask.mark.produces(), pytask.mark.depends_on()],
"produces",
[pytask.mark.produces()],
),
(
[pytask.mark.produces(), pytask.mark.produces(), pytask.mark.depends_on()],
"produces",
[pytask.mark.produces(), pytask.mark.produces()],
),
],
)
def test_get_marks_from_obj(markers, marker_name, expected):
def func():
...

if markers is not None:
func.pytaskmark = markers

result = get_marks_from_obj(func, marker_name)
assert result == expected


@pytest.mark.unit
@pytest.mark.parametrize(
"markers, marker_name, expected",
[
(None, "not_found", False),
([], "not_found", False),
([pytask.mark.produces(), pytask.mark.depends_on()], "produces", True),
(
[pytask.mark.produces(), pytask.mark.produces(), pytask.mark.depends_on()],
"produces",
True,
),
],
)
def test_has_marker(markers, marker_name, expected):
def func():
...

if markers is not None:
func.pytaskmark = markers

result = has_marker(func, marker_name)
assert result == expected


@pytest.mark.unit
@pytest.mark.parametrize(
"markers, marker_name, expected_markers, expected_others",
[
(None, "not_found", [], []),
([], "not_found", [], []),
(
[pytask.mark.produces(), pytask.mark.depends_on()],
"produces",
[pytask.mark.produces()],
[pytask.mark.depends_on()],
),
(
[pytask.mark.produces(), pytask.mark.produces(), pytask.mark.depends_on()],
"produces",
[pytask.mark.produces(), pytask.mark.produces()],
[pytask.mark.depends_on()],
),
],
)
def test_remove_markers_from_func(
markers, marker_name, expected_markers, expected_others
):
def func():
...

if markers is not None:
func.pytaskmark = markers

obj, result_markers = remove_markers_from_func(func, marker_name)
assert obj.pytaskmark == expected_others
assert result_markers == expected_markers
2 changes: 2 additions & 0 deletions tests/test_outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from _pytask.report import ExecutionReport


@pytest.mark.unit
@pytest.mark.parametrize("outcome_in_report", CollectionOutcome)
def test_count_outcomes_collection(outcome_in_report):
reports = [CollectionReport(outcome_in_report, None, None)]
Expand All @@ -19,6 +20,7 @@ def test_count_outcomes_collection(outcome_in_report):
assert count == 0


@pytest.mark.unit
@pytest.mark.parametrize("outcome_in_report", TaskOutcome)
def test_count_outcomes_tasks(outcome_in_report):
reports = [ExecutionReport(None, outcome_in_report, None, None)]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pytask import main


@pytest.mark.unit
@pytest.mark.parametrize("func_name", ["task_example", "func"])
@pytest.mark.parametrize("task_name", ["the_only_task", None])
def test_task_with_task_decorator(tmp_path, func_name, task_name):
Expand Down Expand Up @@ -34,6 +35,7 @@ def {func_name}(produces):
)


@pytest.mark.unit
@pytest.mark.parametrize("func_name", ["task_example", "func"])
@pytest.mark.parametrize("task_name", ["the_only_task", None])
def test_task_with_task_decorator_with_parametrize(tmp_path, func_name, task_name):
Expand Down