|
21 | 21 | IS_PEXPECT_INSTALLED = True
|
22 | 22 |
|
23 | 23 |
|
| 24 | +def _escape_ansi(line): |
| 25 | + """Escape ANSI sequences produced by rich.""" |
| 26 | + ansi_escape = re.compile(r"(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]") |
| 27 | + return ansi_escape.sub("", line) |
| 28 | + |
| 29 | + |
24 | 30 | @pytest.mark.unit()
|
25 | 31 | @pytest.mark.parametrize(
|
26 | 32 | ("value", "expected", "expectation"),
|
@@ -487,7 +493,40 @@ def test_function():
|
487 | 493 | _flush(child)
|
488 | 494 |
|
489 | 495 |
|
490 |
| -def _escape_ansi(line): |
491 |
| - """Escape ANSI sequences produced by rich.""" |
492 |
| - ansi_escape = re.compile(r"(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]") |
493 |
| - return ansi_escape.sub("", line) |
| 496 | +@pytest.mark.end_to_end() |
| 497 | +@pytest.mark.skipif(not IS_PEXPECT_INSTALLED, reason="pexpect is not installed.") |
| 498 | +@pytest.mark.skipif(sys.platform == "win32", reason="pexpect cannot spawn on Windows.") |
| 499 | +def test_pdb_with_task_that_returns(tmp_path, runner): |
| 500 | + source = """ |
| 501 | + from typing_extensions import Annotated |
| 502 | + from pathlib import Path |
| 503 | +
|
| 504 | + def task_example() -> Annotated[str, Path("data.txt")]: |
| 505 | + return "1" |
| 506 | + """ |
| 507 | + tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source)) |
| 508 | + |
| 509 | + result = runner.invoke(cli, [tmp_path.as_posix(), "--pdb"]) |
| 510 | + assert result.exit_code == ExitCode.OK |
| 511 | + assert tmp_path.joinpath("data.txt").read_text() == "1" |
| 512 | + |
| 513 | + |
| 514 | +@pytest.mark.end_to_end() |
| 515 | +@pytest.mark.skipif(not IS_PEXPECT_INSTALLED, reason="pexpect is not installed.") |
| 516 | +@pytest.mark.skipif(sys.platform == "win32", reason="pexpect cannot spawn on Windows.") |
| 517 | +def test_trace_with_task_that_returns(tmp_path): |
| 518 | + source = """ |
| 519 | + from typing_extensions import Annotated |
| 520 | + from pathlib import Path |
| 521 | +
|
| 522 | + def task_example() -> Annotated[str, Path("data.txt")]: |
| 523 | + return "1" |
| 524 | + """ |
| 525 | + tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source)) |
| 526 | + |
| 527 | + child = pexpect.spawn(f"pytask {tmp_path.as_posix()}") |
| 528 | + child.sendline("c") |
| 529 | + rest = child.read().decode("utf8") |
| 530 | + assert "1 Succeeded" in _escape_ansi(rest) |
| 531 | + assert tmp_path.joinpath("data.txt").read_text() == "1" |
| 532 | + _flush(child) |
0 commit comments