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