88from pytask_latex .collect import DEFAULT_OPTIONS
99from pytask_latex .collect import latex
1010from pytask_latex .collect import pytask_collect_task
11+ from pytask_latex .collect import pytask_collect_task_teardown
1112
1213
1314class DummyClass :
@@ -53,6 +54,24 @@ def test_latex(latex_args, expected):
5354 assert options == expected
5455
5556
57+ @pytest .mark .unit
58+ @pytest .mark .parametrize (
59+ "name, expected" ,
60+ [("task_dummy" , True ), ("invalid_name" , None )],
61+ )
62+ def test_pytask_collect_task (name , expected ):
63+ session = DummyClass ()
64+ path = Path ("some_path" )
65+ task_dummy .pytaskmark = [Mark ("latex" , (), {})]
66+
67+ task = pytask_collect_task (session , path , name , task_dummy )
68+
69+ if expected :
70+ assert task
71+ else :
72+ assert not task
73+
74+
5675@pytest .mark .unit
5776@pytest .mark .parametrize (
5877 "depends_on, produces, expectation" ,
@@ -68,25 +87,12 @@ def test_latex(latex_args, expected):
6887 (["document.tex" ], ["document.out" , "document.pdf" ], pytest .raises (ValueError )),
6988 ],
7089)
71- def test_pytask_collect_task (monkeypatch , depends_on , produces , expectation ):
72- session = DummyClass ()
73- path = Path ("some_path" )
74-
75- task_dummy .pytaskmark = [Mark ("latex" , (), {})] + [
76- Mark ("depends_on" , tuple (d for d in depends_on ), {}),
77- Mark ("produces" , tuple (d for d in produces ), {}),
78- ]
79-
90+ def test_pytask_collect_task_teardown (depends_on , produces , expectation ):
8091 task = DummyClass ()
8192 task .depends_on = [FilePathNode (n .split ("." )[0 ], Path (n )) for n in depends_on ]
8293 task .produces = [FilePathNode (n .split ("." )[0 ], Path (n )) for n in produces ]
8394 task .markers = [Mark ("latex" , (), {})]
8495 task .function = task_dummy
8596
86- monkeypatch .setattr (
87- "pytask_latex.collect.PythonFunctionTask.from_path_name_function_session" ,
88- lambda * x : task ,
89- )
90-
9197 with expectation :
92- pytask_collect_task ( session , path , "task_dummy" , task_dummy )
98+ pytask_collect_task_teardown ( task )
0 commit comments