1010from _pytask .nodes import _convert_objects_to_node_dictionary
1111from _pytask .nodes import _create_task_name
1212from _pytask .nodes import _extract_nodes_from_function_markers
13- from _pytask .nodes import _find_closest_ancestor
14- from _pytask .nodes import _relative_to
1513from _pytask .nodes import depends_on
1614from _pytask .nodes import FilePathNode
1715from _pytask .nodes import MetaNode
@@ -203,37 +201,6 @@ def test_create_task_name(path, name, expected):
203201 assert result == expected
204202
205203
206- @pytest .mark .unit
207- @pytest .mark .parametrize (
208- "path, source, include_source, expected" ,
209- [
210- (Path ("src/hello.py" ), Path ("src" ), True , Path ("src/hello.py" )),
211- (Path ("src/hello.py" ), Path ("src" ), False , Path ("hello.py" )),
212- ],
213- )
214- def test_relative_to (path , source , include_source , expected ):
215- result = _relative_to (path , source , include_source )
216- assert result == expected
217-
218-
219- @pytest .mark .unit
220- @pytest .mark .parametrize (
221- "path, potential_ancestors, expected" ,
222- [
223- (Path ("src/task.py" ), [Path ("src" ), Path ("bld" )], Path ("src" )),
224- (Path ("tasks/task.py" ), [Path ("src" ), Path ("bld" )], None ),
225- (Path ("src/ts/task.py" ), [Path ("src" ), Path ("src/ts" )], Path ("src/ts" )),
226- (Path ("src/in.txt" ), [Path ("src/task_d.py" )], Path ("src" )),
227- (Path ("src/task.py" ), [Path ("src/task.py" )], Path ("src/task.py" )),
228- ],
229- )
230- def test_find_closest_ancestor (monkeypatch , path , potential_ancestors , expected ):
231- # Ensures that files are detected by an existing suffix not if they also exist.
232- monkeypatch .setattr ("_pytask.nodes.pathlib.Path.is_file" , lambda x : bool (x .suffix ))
233- result = _find_closest_ancestor (path , potential_ancestors )
234- assert result == expected
235-
236-
237204@attr .s
238205class DummyTask (MetaTask ):
239206 path = attr .ib ()
@@ -259,19 +226,21 @@ class FalseNode:
259226@pytest .mark .parametrize (
260227 "node, paths, expectation, expected" ,
261228 [
262- (
229+ pytest . param (
263230 FilePathNode .from_path (_ROOT .joinpath ("src/module.py" )),
264231 [_ROOT .joinpath ("alternative_src" )],
265- pytest .raises (ValueError , match = "A node must be" ),
266- None ,
232+ does_not_raise (),
233+ "pytask/src/module.py" ,
234+ id = "Common path found for FilePathNode not in 'paths' and 'paths'" ,
267235 ),
268- (
236+ pytest . param (
269237 FalseNode (_ROOT .joinpath ("src/module.py" )),
270238 [_ROOT .joinpath ("src" )],
271239 pytest .raises (ValueError , match = "Unknown node" ),
272240 None ,
241+ id = "throw error on unknown node type." ,
273242 ),
274- (
243+ pytest . param (
275244 DummyTask (
276245 _ROOT .joinpath ("top/src/module.py" ),
277246 _ROOT .joinpath ("top/src/module.py" ).as_posix () + "::task_func" ,
@@ -280,14 +249,16 @@ class FalseNode:
280249 [_ROOT .joinpath ("top/src" )],
281250 does_not_raise (),
282251 "src/module.py::task_func" ,
252+ id = "make task name relative to 'paths'." ,
283253 ),
284- (
254+ pytest . param (
285255 FilePathNode .from_path (_ROOT .joinpath ("top/src/module.py" )),
286256 [_ROOT .joinpath ("top/src" )],
287257 does_not_raise (),
288258 "src/module.py" ,
259+ id = "make filepathnode relative to 'paths'." ,
289260 ),
290- (
261+ pytest . param (
291262 PythonFunctionTask (
292263 "task_d" ,
293264 _ROOT .joinpath ("top/src/module.py" ).as_posix () + "::task_d" ,
@@ -297,6 +268,7 @@ class FalseNode:
297268 [_ROOT .joinpath ("top/src/module.py" )],
298269 does_not_raise (),
299270 "module.py::task_d" ,
271+ id = "shorten task name when task module is passed to 'paths'." ,
300272 ),
301273 ],
302274)
0 commit comments