@@ -1093,108 +1093,6 @@ def task_copy(
1093
1093
assert tmp_path .joinpath ("b-copy.txt" ).exists ()
1094
1094
1095
1095
1096
- @pytest .mark .end_to_end ()
1097
- def test_delayed_task_generation_with_generator (runner , tmp_path ):
1098
- source = """
1099
- from typing_extensions import Annotated
1100
- from pytask import DirectoryNode, task
1101
- from pathlib import Path
1102
-
1103
- def task_produces() -> Annotated[None, DirectoryNode(pattern="[ab].txt")]:
1104
- path = Path(__file__).parent
1105
- path.joinpath("a.txt").write_text("Hello, ")
1106
- path.joinpath("b.txt").write_text("World!")
1107
-
1108
- @task(after=task_produces, is_generator=True)
1109
- def task_depends(
1110
- paths = DirectoryNode(pattern="[ab].txt")
1111
- ) -> ...:
1112
- for path in paths:
1113
-
1114
- @task
1115
- def task_copy(
1116
- path: Path = path
1117
- ) -> Annotated[str, path.with_name(path.stem + "-copy.txt")]:
1118
- return path.read_text()
1119
-
1120
- yield task_copy
1121
- """
1122
- tmp_path .joinpath ("task_module.py" ).write_text (textwrap .dedent (source ))
1123
-
1124
- result = runner .invoke (cli , [tmp_path .as_posix ()])
1125
- assert result .exit_code == ExitCode .OK
1126
- assert "4 Collected tasks" in result .output
1127
- assert "4 Succeeded" in result .output
1128
- assert tmp_path .joinpath ("a-copy.txt" ).exists ()
1129
- assert tmp_path .joinpath ("b-copy.txt" ).exists ()
1130
-
1131
-
1132
- @pytest .mark .end_to_end ()
1133
- def test_delayed_task_generation_with_single_function (runner , tmp_path ):
1134
- source = """
1135
- from typing_extensions import Annotated
1136
- from pytask import DirectoryNode, task
1137
- from pathlib import Path
1138
-
1139
- def task_produces() -> Annotated[None, DirectoryNode(pattern="[a].txt")]:
1140
- path = Path(__file__).parent
1141
- path.joinpath("a.txt").write_text("Hello, ")
1142
-
1143
- @task(after=task_produces, is_generator=True)
1144
- def task_depends(
1145
- paths = DirectoryNode(pattern="[a].txt")
1146
- ) -> ...:
1147
- path = paths[0]
1148
-
1149
- def task_copy(
1150
- path: Path = path
1151
- ) -> Annotated[str, path.with_name(path.stem + "-copy.txt")]:
1152
- return path.read_text()
1153
- return task_copy
1154
- """
1155
- tmp_path .joinpath ("task_module.py" ).write_text (textwrap .dedent (source ))
1156
-
1157
- result = runner .invoke (cli , [tmp_path .as_posix ()])
1158
- assert result .exit_code == ExitCode .OK
1159
- assert "3 Collected tasks" in result .output
1160
- assert "3 Succeeded" in result .output
1161
- assert tmp_path .joinpath ("a-copy.txt" ).exists ()
1162
-
1163
-
1164
- @pytest .mark .end_to_end ()
1165
- def test_delayed_task_generation_with_task_node (runner , tmp_path ):
1166
- source = """
1167
- from typing_extensions import Annotated
1168
- from pytask import DirectoryNode, TaskWithoutPath, task, PathNode
1169
- from pathlib import Path
1170
-
1171
- def task_produces() -> Annotated[None, DirectoryNode(pattern="[a].txt")]:
1172
- path = Path(__file__).parent
1173
- path.joinpath("a.txt").write_text("Hello, ")
1174
-
1175
- @task(after=task_produces, is_generator=True)
1176
- def task_depends(
1177
- paths = DirectoryNode(pattern="[a].txt")
1178
- ) -> ...:
1179
- path = paths[0]
1180
-
1181
- task_copy = TaskWithoutPath(
1182
- name="task_copy",
1183
- function=lambda path: path.read_text(),
1184
- depends_on={"path": PathNode(path=path)},
1185
- produces={"return": PathNode(path=path.with_name(path.stem + "-copy.txt"))},
1186
- )
1187
- return task_copy
1188
- """
1189
- tmp_path .joinpath ("task_module.py" ).write_text (textwrap .dedent (source ))
1190
-
1191
- result = runner .invoke (cli , [tmp_path .as_posix ()])
1192
- assert result .exit_code == ExitCode .OK
1193
- assert "3 Collected tasks" in result .output
1194
- assert "3 Succeeded" in result .output
1195
- assert tmp_path .joinpath ("a-copy.txt" ).exists ()
1196
-
1197
-
1198
1096
@pytest .mark .end_to_end ()
1199
1097
def test_gracefully_fail_when_task_generator_raises_error (runner , tmp_path ):
1200
1098
source = """
0 commit comments