()
| 2538 | |
| 2539 | |
| 2540 | def test_cli_app_exceptions(): |
| 2541 | with pytest.raises( |
| 2542 | SettingsError, match='Error: NotPydanticModel is not subclass of BaseModel or pydantic.dataclasses.dataclass' |
| 2543 | ): |
| 2544 | |
| 2545 | class NotPydanticModel: ... |
| 2546 | |
| 2547 | CliApp.run(NotPydanticModel) |
| 2548 | |
| 2549 | with pytest.raises( |
| 2550 | SettingsError, |
| 2551 | match=re.escape('Error: `cli_args` must be list[str] or None when `cli_settings_source` is not used'), |
| 2552 | ): |
| 2553 | |
| 2554 | class Cfg(BaseModel): ... |
| 2555 | |
| 2556 | CliApp.run(Cfg, cli_args={'my_arg': 'hello'}) |
| 2557 | |
| 2558 | with pytest.raises(SettingsError, match='Error: Child class is missing cli_cmd entrypoint'): |
| 2559 | |
| 2560 | class Child(BaseModel): |
| 2561 | val: str |
| 2562 | |
| 2563 | class Root(BaseModel): |
| 2564 | child: CliSubCommand[Child] |
| 2565 | |
| 2566 | def cli_cmd(self) -> None: |
| 2567 | CliApp.run_subcommand(self) |
| 2568 | |
| 2569 | CliApp.run(Root, cli_args=['child', '--val=hello']) |
| 2570 | |
| 2571 | |
| 2572 | def test_cli_suppress(capsys, monkeypatch): |
nothing calls this directly
no test coverage detected
searching dependent graphs…