(tmp_path: Path)
| 355 | |
| 356 | |
| 357 | def test_base_reloader_run(tmp_path: Path): |
| 358 | calls: list[str] = [] |
| 359 | step = 0 |
| 360 | |
| 361 | class CustomReload(BaseReload): |
| 362 | def startup(self): |
| 363 | calls.append("startup") |
| 364 | |
| 365 | def restart(self): |
| 366 | calls.append("restart") |
| 367 | |
| 368 | def shutdown(self): |
| 369 | calls.append("shutdown") |
| 370 | |
| 371 | def should_restart(self): |
| 372 | nonlocal step |
| 373 | step += 1 |
| 374 | if step == 1: |
| 375 | return None |
| 376 | elif step == 2: |
| 377 | return [tmp_path / "foobar.py"] |
| 378 | else: |
| 379 | raise StopIteration() |
| 380 | |
| 381 | config = Config(app="tests.test_config:asgi_app", reload=True) |
| 382 | reloader = CustomReload(config, target=run, sockets=[]) |
| 383 | reloader.run() |
| 384 | |
| 385 | assert calls == ["startup", "restart", "shutdown"] |
| 386 | |
| 387 | |
| 388 | def test_base_reloader_should_exit(tmp_path: Path): |
nothing calls this directly
no test coverage detected