11from __future__ import annotations
22
33import textwrap
4- from contextlib import ExitStack as does_not_raise # noqa: N813
54from pathlib import Path
65
7- import networkx as nx
86import pytest
9- from _pytask .dag import _check_if_root_nodes_are_available
107from _pytask .dag import pytask_dag_create_dag
11- from _pytask .exceptions import NodeNotFoundError
12- from _pytask .exceptions import ResolvingDependenciesError
138from attrs import define
149from pytask import cli
1510from pytask import ExitCode
11+ from pytask import NodeNotFoundError
1612from pytask import PathNode
1713from pytask import Task
1814
@@ -46,36 +42,8 @@ def test_pytask_dag_create_dag():
4642 )
4743
4844
49- @pytest .mark .unit ()
50- @pytest .mark .xfail (reason = "session object is missing." )
51- def test_check_if_root_nodes_are_available ():
52- dag = nx .DiGraph ()
53-
54- root = Path .cwd () / "src"
55-
56- path = root .joinpath ("task_dummy" )
57- task = Task (base_name = "task" , path = path , function = None )
58- task .path = path
59- task .base_name = "task_dummy"
60- dag .add_node (task .name , task = task )
61-
62- available_node = Node .from_path (root .joinpath ("available_node" ))
63- dag .add_node (available_node .name , node = available_node )
64- dag .add_edge (available_node .name , task .name )
65-
66- with does_not_raise ():
67- _check_if_root_nodes_are_available (dag )
68-
69- missing_node = Node .from_path (root .joinpath ("missing_node" ))
70- dag .add_node (missing_node .name , node = missing_node )
71- dag .add_edge (missing_node .name , task .name )
72-
73- with pytest .raises (ResolvingDependenciesError ):
74- _check_if_root_nodes_are_available (dag )
75-
76-
7745@pytest .mark .end_to_end ()
78- def test_check_if_root_nodes_are_available_end_to_end (tmp_path , runner ):
46+ def test_check_if_root_nodes_are_available (tmp_path , runner ):
7947 source = """
8048 import pytask
8149
@@ -101,9 +69,35 @@ def task_d(produces):
10169
10270
10371@pytest .mark .end_to_end ()
104- def test_check_if_root_nodes_are_available_with_separate_build_folder_end_to_end (
105- tmp_path , runner
106- ):
72+ def test_check_if_root_nodes_are_available_w_name (tmp_path , runner ):
73+ source = """
74+ from pathlib import Path
75+ from typing_extensions import Annotated, Any
76+ from pytask import PathNode, PythonNode
77+
78+ node1 = PathNode(name="input1", path=Path(__file__).parent / "in.txt")
79+ node2 = PythonNode(name="input2")
80+
81+ def task_e(in1_: Annotated[Path, node1], in2_: Annotated[Any, node2]): ...
82+ """
83+ tmp_path .joinpath ("task_e.py" ).write_text (textwrap .dedent (source ))
84+
85+ result = runner .invoke (cli , [tmp_path .as_posix ()])
86+
87+ assert result .exit_code == ExitCode .DAG_FAILED
88+ assert "Failures during resolving dependencies" in result .output
89+
90+ # Ensure that node names are reduced.
91+ assert "Failures during resolving dependencies" in result .output
92+ assert "Some dependencies do not exist or are" in result .output
93+ assert tmp_path .joinpath ("task_e.py" ).as_posix () + "::task_e" not in result .output
94+ assert "task_e.py::task_e" in result .output
95+ assert tmp_path .joinpath ("in.txt" ).as_posix () not in result .output
96+ assert tmp_path .name + "/in.txt" in result .output
97+
98+
99+ @pytest .mark .end_to_end ()
100+ def test_check_if_root_nodes_are_available_with_separate_build_folder (tmp_path , runner ):
107101 tmp_path .joinpath ("src" ).mkdir ()
108102 tmp_path .joinpath ("bld" ).mkdir ()
109103 source = """
0 commit comments