|
6 | 6 | import sys |
7 | 7 | import textwrap |
8 | 8 | from contextlib import ExitStack as does_not_raise # noqa: N813 |
| 9 | +from types import SimpleNamespace |
9 | 10 |
|
10 | 11 | import click |
11 | 12 | import pytest |
@@ -104,6 +105,50 @@ def task_example(): |
104 | 105 | _flush(child) |
105 | 106 |
|
106 | 107 |
|
| 108 | +def test_import_pdb_cls_uses_import_module(monkeypatch): |
| 109 | + class CustomPdb(pdb.Pdb): |
| 110 | + pass |
| 111 | + |
| 112 | + module = SimpleNamespace(CustomPdb=CustomPdb) |
| 113 | + imported = [] |
| 114 | + |
| 115 | + def import_module(name): |
| 116 | + imported.append(name) |
| 117 | + return module |
| 118 | + |
| 119 | + monkeypatch.setattr("importlib.import_module", import_module) |
| 120 | + monkeypatch.setattr( |
| 121 | + PytaskPDB, "_config", {"pdbcls": ("package.debuggers", "CustomPdb")} |
| 122 | + ) |
| 123 | + monkeypatch.setattr(PytaskPDB, "_wrapped_pdb_cls", None) |
| 124 | + |
| 125 | + wrapped = PytaskPDB._import_pdb_cls(None, None) # type: ignore[arg-type] |
| 126 | + |
| 127 | + assert imported == ["package.debuggers"] |
| 128 | + assert issubclass(wrapped, CustomPdb) |
| 129 | + |
| 130 | + |
| 131 | +@pytest.mark.skipif(not IS_PEXPECT_INSTALLED, reason="pexpect is not installed.") |
| 132 | +@pytest.mark.skipif(sys.platform == "win32", reason="pexpect cannot spawn on Windows.") |
| 133 | +def test_pdb_after_readline_is_imported_during_capture(tmp_path): |
| 134 | + source = """ |
| 135 | + from pathlib import Path |
| 136 | +
|
| 137 | + def task_example(): |
| 138 | + import readline |
| 139 | +
|
| 140 | + breakpoint() |
| 141 | + Path(__file__).with_name("continued.txt").touch() |
| 142 | + """ |
| 143 | + tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source)) |
| 144 | + |
| 145 | + child = pexpect.spawn(f"pytask {tmp_path.as_posix()}") |
| 146 | + child.expect("Pdb") |
| 147 | + child.sendline("continue") |
| 148 | + _flush(child) |
| 149 | + assert tmp_path.joinpath("continued.txt").exists() |
| 150 | + |
| 151 | + |
107 | 152 | @pytest.mark.skipif(not IS_PEXPECT_INSTALLED, reason="pexpect is not installed.") |
108 | 153 | @pytest.mark.skipif(sys.platform == "win32", reason="pexpect cannot spawn on Windows.") |
109 | 154 | @pytest.mark.skipif( |
|
0 commit comments