19
19
20
20
21
21
@pytest .mark .end_to_end ()
22
- def test_collect_filepathnode_with_relative_path (tmp_path ):
23
- source = """
22
+ @pytest .mark .parametrize (
23
+ ("depends_on" , "produces" ),
24
+ [
25
+ ("'in.txt'" , "'out.txt'" ),
26
+ ("Path('in.txt')" , "Path('out.txt')" ),
27
+ ],
28
+ )
29
+ def test_collect_file_with_relative_path (tmp_path , depends_on , produces ):
30
+ source = f"""
24
31
import pytask
32
+ from pathlib import Path
25
33
26
- @pytask.mark.depends_on("in.txt" )
27
- @pytask.mark.produces("out.txt" )
34
+ @pytask.mark.depends_on({ depends_on } )
35
+ @pytask.mark.produces({ produces } )
28
36
def task_write_text(depends_on, produces):
29
37
produces.write_text(depends_on.read_text())
30
38
"""
@@ -37,6 +45,27 @@ def task_write_text(depends_on, produces):
37
45
assert tmp_path .joinpath ("out.txt" ).read_text () == "Relative paths work."
38
46
39
47
48
+ @pytest .mark .end_to_end ()
49
+ def test_relative_path_of_path_node (runner , tmp_path ):
50
+ source = """
51
+ from pathlib import Path
52
+ from typing_extensions import Annotated
53
+ from pytask import Product, PathNode
54
+
55
+ def task_example(
56
+ in_path: Annotated[Path, PathNode(path=Path("in.txt"))],
57
+ path: Annotated[Path, Product, PathNode(path=Path("out.txt"))],
58
+ ) -> None:
59
+ path.write_text("text")
60
+ """
61
+ tmp_path .joinpath ("task_module.py" ).write_text (textwrap .dedent (source ))
62
+ tmp_path .joinpath ("in.txt" ).touch ()
63
+
64
+ result = runner .invoke (cli , [tmp_path .as_posix ()])
65
+ assert result .exit_code == ExitCode .OK
66
+ assert tmp_path .joinpath ("out.txt" ).exists ()
67
+
68
+
40
69
@pytest .mark .end_to_end ()
41
70
def test_collect_depends_on_that_is_not_str_or_path (capsys , tmp_path ):
42
71
"""If a node cannot be parsed because unknown type, raise an error."""
@@ -348,30 +377,22 @@ def task_my_task():
348
377
349
378
350
379
@pytest .mark .end_to_end ()
351
- def test_collect_string_product_with_task_decorator (runner , tmp_path ):
352
- source = """
353
- import pytask
354
-
355
- @pytask.mark.task
356
- def task_write_text(produces="out.txt"):
357
- produces.touch()
358
- """
359
- tmp_path .joinpath ("task_module.py" ).write_text (textwrap .dedent (source ))
360
- result = runner .invoke (cli , [tmp_path .as_posix ()])
361
- assert result .exit_code == ExitCode .OK
362
- assert tmp_path .joinpath ("out.txt" ).exists ()
363
-
380
+ @pytest .mark .parametrize ("decorator" , ["" , "@task" ])
381
+ def test_collect_string_product_with_or_without_task_decorator (
382
+ runner , tmp_path , decorator
383
+ ):
384
+ source = f"""
385
+ from pytask import task
364
386
365
- @pytest .mark .end_to_end ()
366
- def test_collect_string_product_as_function_default (runner , tmp_path ):
367
- source = """
387
+ { decorator }
368
388
def task_write_text(produces="out.txt"):
369
389
produces.touch()
370
390
"""
371
391
tmp_path .joinpath ("task_module.py" ).write_text (textwrap .dedent (source ))
372
392
result = runner .invoke (cli , [tmp_path .as_posix ()])
373
393
assert result .exit_code == ExitCode .OK
374
394
assert tmp_path .joinpath ("out.txt" ).exists ()
395
+ assert "FutureWarning" in result .output
375
396
376
397
377
398
@pytest .mark .end_to_end ()
@@ -443,12 +464,19 @@ def task_example(
443
464
444
465
445
466
@pytest .mark .end_to_end ()
446
- def test_deprecation_warning_for_strings_in_depends_on (runner , tmp_path ):
447
- source = """
467
+ @pytest .mark .parametrize (
468
+ ("depends_on" , "produces" ),
469
+ [("'in.txt'" , "Path('out.txt')" ), ("Path('in.txt')" , "'out.txt'" )],
470
+ )
471
+ def test_deprecation_warning_for_strings_in_former_decorator_args (
472
+ runner , tmp_path , depends_on , produces
473
+ ):
474
+ source = f"""
448
475
import pytask
476
+ from pathlib import Path
449
477
450
- @pytask.mark.depends_on("in.txt" )
451
- @pytask.mark.produces("out.txt" )
478
+ @pytask.mark.depends_on({ depends_on } )
479
+ @pytask.mark.produces({ produces } )
452
480
def task_write_text(depends_on, produces):
453
481
produces.touch()
454
482
"""
@@ -472,7 +500,6 @@ def task_write_text(depends_on, produces=Path("out.txt")):
472
500
473
501
result = runner .invoke (cli , [tmp_path .as_posix ()])
474
502
assert "FutureWarning" not in result .output
475
- assert "Using 'produces' as an argument name" not in result .output
476
503
477
504
478
505
@pytest .mark .end_to_end ()
@@ -537,26 +564,6 @@ def task_example(path: Annotated[Path, Product, node]) -> None:
537
564
assert "ValueError: The value for the parameter 'path'" in result .output
538
565
539
566
540
- @pytest .mark .end_to_end ()
541
- def test_relative_path_of_path_node (runner , tmp_path ):
542
- source = """
543
- from pathlib import Path
544
- from typing_extensions import Annotated
545
- from pytask import Product, PathNode
546
-
547
- def task_example(
548
- path: Annotated[Path, Product, PathNode(path=Path("out.txt"), name="product")],
549
- ) -> None:
550
- path.write_text("text")
551
- """
552
- tmp_path .joinpath ("subfolder" ).mkdir ()
553
- tmp_path .joinpath ("subfolder" , "task_module.py" ).write_text (textwrap .dedent (source ))
554
-
555
- result = runner .invoke (cli , [tmp_path .as_posix ()])
556
- assert result .exit_code == ExitCode .OK
557
- assert tmp_path .joinpath ("subfolder" , "out.txt" ).exists ()
558
-
559
-
560
567
@pytest .mark .end_to_end ()
561
568
def test_error_when_using_kwargs_and_node_in_annotation (runner , tmp_path ):
562
569
source = """
0 commit comments