10
10
from _pytask .nodes import _convert_objects_to_node_dictionary
11
11
from _pytask .nodes import _create_task_name
12
12
from _pytask .nodes import _extract_nodes_from_function_markers
13
- from _pytask .nodes import _find_closest_ancestor
14
- from _pytask .nodes import _relative_to
15
13
from _pytask .nodes import depends_on
16
14
from _pytask .nodes import FilePathNode
17
15
from _pytask .nodes import MetaNode
@@ -203,37 +201,6 @@ def test_create_task_name(path, name, expected):
203
201
assert result == expected
204
202
205
203
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
-
237
204
@attr .s
238
205
class DummyTask (MetaTask ):
239
206
path = attr .ib ()
@@ -259,19 +226,21 @@ class FalseNode:
259
226
@pytest .mark .parametrize (
260
227
"node, paths, expectation, expected" ,
261
228
[
262
- (
229
+ pytest . param (
263
230
FilePathNode .from_path (_ROOT .joinpath ("src/module.py" )),
264
231
[_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'" ,
267
235
),
268
- (
236
+ pytest . param (
269
237
FalseNode (_ROOT .joinpath ("src/module.py" )),
270
238
[_ROOT .joinpath ("src" )],
271
239
pytest .raises (ValueError , match = "Unknown node" ),
272
240
None ,
241
+ id = "throw error on unknown node type." ,
273
242
),
274
- (
243
+ pytest . param (
275
244
DummyTask (
276
245
_ROOT .joinpath ("top/src/module.py" ),
277
246
_ROOT .joinpath ("top/src/module.py" ).as_posix () + "::task_func" ,
@@ -280,14 +249,16 @@ class FalseNode:
280
249
[_ROOT .joinpath ("top/src" )],
281
250
does_not_raise (),
282
251
"src/module.py::task_func" ,
252
+ id = "make task name relative to 'paths'." ,
283
253
),
284
- (
254
+ pytest . param (
285
255
FilePathNode .from_path (_ROOT .joinpath ("top/src/module.py" )),
286
256
[_ROOT .joinpath ("top/src" )],
287
257
does_not_raise (),
288
258
"src/module.py" ,
259
+ id = "make filepathnode relative to 'paths'." ,
289
260
),
290
- (
261
+ pytest . param (
291
262
PythonFunctionTask (
292
263
"task_d" ,
293
264
_ROOT .joinpath ("top/src/module.py" ).as_posix () + "::task_d" ,
@@ -297,6 +268,7 @@ class FalseNode:
297
268
[_ROOT .joinpath ("top/src/module.py" )],
298
269
does_not_raise (),
299
270
"module.py::task_d" ,
271
+ id = "shorten task name when task module is passed to 'paths'." ,
300
272
),
301
273
],
302
274
)
0 commit comments