7
7
from pytask import ExitCode
8
8
from pytask import build
9
9
from pytask import cli
10
- from pytask_parallel .backends import PARALLEL_BACKENDS
11
10
from pytask_parallel .backends import ParallelBackend
12
11
from pytask_parallel .execute import _Sleeper
13
12
@@ -19,18 +18,18 @@ class Session:
19
18
20
19
21
20
@pytest .mark .end_to_end ()
22
- @pytest .mark .parametrize ("parallel_backend" , PARALLEL_BACKENDS )
21
+ @pytest .mark .parametrize ("parallel_backend" , ParallelBackend )
23
22
def test_parallel_execution (tmp_path , parallel_backend ):
24
23
source = """
25
- import pytask
24
+ from pytask import Product
25
+ from pathlib import Path
26
+ from typing_extensions import Annotated
26
27
27
- @pytask.mark.produces("out_1.txt")
28
- def task_1(produces):
29
- produces.write_text("1")
28
+ def task_1(path: Annotated[Path, Product] = Path("out_1.txt")):
29
+ path.write_text("1")
30
30
31
- @pytask.mark.produces("out_2.txt")
32
- def task_2(produces):
33
- produces.write_text("2")
31
+ def task_2(path: Annotated[Path, Product] = Path("out_2.txt")):
32
+ path.write_text("2")
34
33
"""
35
34
tmp_path .joinpath ("task_example.py" ).write_text (textwrap .dedent (source ))
36
35
session = build (paths = tmp_path , n_workers = 2 , parallel_backend = parallel_backend )
@@ -41,18 +40,18 @@ def task_2(produces):
41
40
42
41
43
42
@pytest .mark .end_to_end ()
44
- @pytest .mark .parametrize ("parallel_backend" , PARALLEL_BACKENDS )
43
+ @pytest .mark .parametrize ("parallel_backend" , ParallelBackend )
45
44
def test_parallel_execution_w_cli (runner , tmp_path , parallel_backend ):
46
45
source = """
47
- import pytask
46
+ from pytask import Product
47
+ from pathlib import Path
48
+ from typing_extensions import Annotated
48
49
49
- @pytask.mark.produces("out_1.txt")
50
- def task_1(produces):
51
- produces.write_text("1")
50
+ def task_1(path: Annotated[Path, Product] = Path("out_1.txt")):
51
+ path.write_text("1")
52
52
53
- @pytask.mark.produces("out_2.txt")
54
- def task_2(produces):
55
- produces.write_text("2")
53
+ def task_2(path: Annotated[Path, Product] = Path("out_2.txt")):
54
+ path.write_text("2")
56
55
"""
57
56
tmp_path .joinpath ("task_example.py" ).write_text (textwrap .dedent (source ))
58
57
result = runner .invoke (
@@ -71,7 +70,7 @@ def task_2(produces):
71
70
72
71
73
72
@pytest .mark .end_to_end ()
74
- @pytest .mark .parametrize ("parallel_backend" , PARALLEL_BACKENDS )
73
+ @pytest .mark .parametrize ("parallel_backend" , ParallelBackend )
75
74
def test_stop_execution_when_max_failures_is_reached (tmp_path , parallel_backend ):
76
75
source = """
77
76
import time
@@ -99,7 +98,7 @@ def task_3(): time.sleep(3)
99
98
100
99
101
100
@pytest .mark .end_to_end ()
102
- @pytest .mark .parametrize ("parallel_backend" , PARALLEL_BACKENDS )
101
+ @pytest .mark .parametrize ("parallel_backend" , ParallelBackend )
103
102
def test_task_priorities (tmp_path , parallel_backend ):
104
103
source = """
105
104
import pytask
@@ -140,7 +139,7 @@ def task_5():
140
139
141
140
142
141
@pytest .mark .end_to_end ()
143
- @pytest .mark .parametrize ("parallel_backend" , PARALLEL_BACKENDS )
142
+ @pytest .mark .parametrize ("parallel_backend" , ParallelBackend )
144
143
@pytest .mark .parametrize ("show_locals" , [True , False ])
145
144
def test_rendering_of_tracebacks_with_rich (
146
145
runner , tmp_path , parallel_backend , show_locals
@@ -173,12 +172,12 @@ def task_raising_error():
173
172
)
174
173
def test_collect_warnings_from_parallelized_tasks (runner , tmp_path , parallel_backend ):
175
174
source = """
176
- import pytask
175
+ from pytask import task
177
176
import warnings
178
177
179
178
for i in range(2):
180
179
181
- @pytask.mark. task(id=str(i), kwargs={"produces": f"{i}.txt"})
180
+ @task(id=str(i), kwargs={"produces": f"{i}.txt"})
182
181
def task_example(produces):
183
182
warnings.warn("This is a warning.")
184
183
produces.touch()
@@ -222,7 +221,7 @@ def test_sleeper():
222
221
223
222
224
223
@pytest .mark .end_to_end ()
225
- @pytest .mark .parametrize ("parallel_backend" , PARALLEL_BACKENDS )
224
+ @pytest .mark .parametrize ("parallel_backend" , ParallelBackend )
226
225
def test_task_that_return (runner , tmp_path , parallel_backend ):
227
226
source = """
228
227
from pathlib import Path
@@ -242,7 +241,7 @@ def task_example() -> Annotated[str, Path("file.txt")]:
242
241
243
242
244
243
@pytest .mark .end_to_end ()
245
- @pytest .mark .parametrize ("parallel_backend" , PARALLEL_BACKENDS )
244
+ @pytest .mark .parametrize ("parallel_backend" , ParallelBackend )
246
245
def test_task_without_path_that_return (runner , tmp_path , parallel_backend ):
247
246
source = """
248
247
from pathlib import Path
@@ -264,7 +263,7 @@ def test_task_without_path_that_return(runner, tmp_path, parallel_backend):
264
263
265
264
@pytest .mark .end_to_end ()
266
265
@pytest .mark .parametrize ("flag" , ["--pdb" , "--trace" , "--dry-run" ])
267
- @pytest .mark .parametrize ("parallel_backend" , PARALLEL_BACKENDS )
266
+ @pytest .mark .parametrize ("parallel_backend" , ParallelBackend )
268
267
def test_parallel_execution_is_deactivated (runner , tmp_path , flag , parallel_backend ):
269
268
tmp_path .joinpath ("task_example.py" ).write_text ("def task_example(): pass" )
270
269
result = runner .invoke (
@@ -278,7 +277,7 @@ def test_parallel_execution_is_deactivated(runner, tmp_path, flag, parallel_back
278
277
@pytest .mark .end_to_end ()
279
278
@pytest .mark .parametrize ("code" , ["breakpoint()" , "import pdb; pdb.set_trace()" ])
280
279
@pytest .mark .parametrize (
281
- "parallel_backend" , [i for i in PARALLEL_BACKENDS if i != ParallelBackend .THREADS ]
280
+ "parallel_backend" , [i for i in ParallelBackend if i != ParallelBackend .THREADS ]
282
281
)
283
282
def test_raise_error_on_breakpoint (runner , tmp_path , code , parallel_backend ):
284
283
tmp_path .joinpath ("task_example.py" ).write_text (f"def task_example(): { code } " )
@@ -290,7 +289,7 @@ def test_raise_error_on_breakpoint(runner, tmp_path, code, parallel_backend):
290
289
291
290
292
291
@pytest .mark .end_to_end ()
293
- @pytest .mark .parametrize ("parallel_backend" , PARALLEL_BACKENDS )
292
+ @pytest .mark .parametrize ("parallel_backend" , ParallelBackend )
294
293
def test_task_partialed (runner , tmp_path , parallel_backend ):
295
294
source = """
296
295
from pathlib import Path
0 commit comments