(capsys, monkeypatch)
| 535 | |
| 536 | |
| 537 | def test_cli_help_string_format(capsys, monkeypatch): |
| 538 | class Cfg(BaseSettings, cli_parse_args=True, cli_prog_name='example.py'): |
| 539 | date_str: str = '%Y-%m-%d' |
| 540 | |
| 541 | class MultilineDoc(BaseSettings, cli_parse_args=True, cli_prog_name='example.py'): |
| 542 | """ |
| 543 | My |
| 544 | Multiline |
| 545 | Doc |
| 546 | """ |
| 547 | |
| 548 | with monkeypatch.context() as m: |
| 549 | m.setattr(sys, 'argv', ['example.py', '--help']) |
| 550 | |
| 551 | with pytest.raises(SystemExit): |
| 552 | Cfg() |
| 553 | |
| 554 | assert ( |
| 555 | re.sub(r'0x\w+', '0xffffffff', capsys.readouterr().out, flags=re.MULTILINE) |
| 556 | == f"""usage: example.py [-h] [--date_str str] |
| 557 | |
| 558 | {ARGPARSE_OPTIONS_TEXT}: |
| 559 | -h, --help show this help message and exit |
| 560 | --date_str str (default: %Y-%m-%d) |
| 561 | """ |
| 562 | ) |
| 563 | |
| 564 | with pytest.raises(SystemExit): |
| 565 | MultilineDoc() |
| 566 | assert ( |
| 567 | capsys.readouterr().out |
| 568 | == f"""usage: example.py [-h] |
| 569 | |
| 570 | My |
| 571 | Multiline |
| 572 | Doc |
| 573 | |
| 574 | {ARGPARSE_OPTIONS_TEXT}: |
| 575 | -h, --help show this help message and exit |
| 576 | """ |
| 577 | ) |
| 578 | |
| 579 | with pytest.raises(SystemExit): |
| 580 | cli_settings_source = CliSettingsSource(MultilineDoc, formatter_class=argparse.HelpFormatter) |
| 581 | MultilineDoc(_cli_settings_source=cli_settings_source(args=True)) |
| 582 | assert ( |
| 583 | capsys.readouterr().out |
| 584 | == f"""usage: example.py [-h] |
| 585 | |
| 586 | My Multiline Doc |
| 587 | |
| 588 | {ARGPARSE_OPTIONS_TEXT}: |
| 589 | -h, --help show this help message and exit |
| 590 | """ |
| 591 | ) |
| 592 | |
| 593 | |
| 594 | def test_cli_help_union_of_models(capsys, monkeypatch): |
nothing calls this directly
no test coverage detected
searching dependent graphs…