Skip to content

Commit 2ce7e24

Browse files
committed
Shorten args for test formatting between py 3.13 and earlier versions.
1 parent 2e6bba3 commit 2ce7e24

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

tests/test_source_cli.py

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,32 +2296,32 @@ class WithUnion(BaseSettings):
22962296

22972297
def test_cli_kebab_case(capsys, monkeypatch):
22982298
class DeepSubModel(BaseModel):
2299-
deep_submodel_positional_arg: CliPositionalArg[str]
2300-
deep_submodel_arg: str
2299+
deep_pos_arg: CliPositionalArg[str]
2300+
deep_arg: str
23012301

23022302
class SubModel(BaseModel):
2303-
submodel_subcommand: CliSubCommand[DeepSubModel]
2304-
submodel_arg: str
2303+
sub_subcmd: CliSubCommand[DeepSubModel]
2304+
sub_arg: str
23052305

23062306
class Root(BaseModel):
2307-
root_subcommand: CliSubCommand[SubModel]
2307+
root_subcmd: CliSubCommand[SubModel]
23082308
root_arg: str
23092309

23102310
assert CliApp.run(
23112311
Root,
23122312
cli_args=[
23132313
'--root-arg=hi',
2314-
'root-subcommand',
2315-
'--submodel-arg=hello',
2316-
'submodel-subcommand',
2314+
'root-subcmd',
2315+
'--sub-arg=hello',
2316+
'sub-subcmd',
23172317
'hey',
2318-
'--deep-submodel-arg=bye',
2318+
'--deep-arg=bye',
23192319
],
23202320
).model_dump() == {
23212321
'root_arg': 'hi',
2322-
'root_subcommand': {
2323-
'submodel_arg': 'hello',
2324-
'submodel_subcommand': {'deep_submodel_positional_arg': 'hey', 'deep_submodel_arg': 'bye'},
2322+
'root_subcmd': {
2323+
'sub_arg': 'hello',
2324+
'sub_subcmd': {'deep_pos_arg': 'hey', 'deep_arg': 'bye'},
23252325
},
23262326
}
23272327

@@ -2331,51 +2331,47 @@ class Root(BaseModel):
23312331
CliApp.run(Root)
23322332
assert (
23332333
capsys.readouterr().out
2334-
== f"""usage: example.py [-h] --root-arg str {{root-subcommand}} ...
2334+
== f"""usage: example.py [-h] --root-arg str {{root-subcmd}} ...
23352335
23362336
{ARGPARSE_OPTIONS_TEXT}:
2337-
-h, --help show this help message and exit
2338-
--root-arg str (required)
2337+
-h, --help show this help message and exit
2338+
--root-arg str (required)
23392339
23402340
subcommands:
2341-
{{root-subcommand}}
2342-
root-subcommand
2341+
{{root-subcmd}}
2342+
root-subcmd
23432343
"""
23442344
)
23452345

2346-
m.setattr(sys, 'argv', ['example.py', 'root-subcommand', '--help'])
2346+
m.setattr(sys, 'argv', ['example.py', 'root-subcmd', '--help'])
23472347
with pytest.raises(SystemExit):
23482348
CliApp.run(Root)
23492349
assert (
23502350
capsys.readouterr().out
2351-
== f"""usage: example.py root-subcommand [-h] --submodel-arg str
2352-
{{submodel-subcommand}} ...
2351+
== f"""usage: example.py root-subcmd [-h] --sub-arg str {{sub-subcmd}} ...
23532352
23542353
{ARGPARSE_OPTIONS_TEXT}:
2355-
-h, --help show this help message and exit
2356-
--submodel-arg str (required)
2354+
-h, --help show this help message and exit
2355+
--sub-arg str (required)
23572356
23582357
subcommands:
2359-
{{submodel-subcommand}}
2360-
submodel-subcommand
2358+
{{sub-subcmd}}
2359+
sub-subcmd
23612360
"""
23622361
)
23632362

2364-
m.setattr(sys, 'argv', ['example.py', 'root-subcommand', 'submodel-subcommand', '--help'])
2363+
m.setattr(sys, 'argv', ['example.py', 'root-subcmd', 'sub-subcmd', '--help'])
23652364
with pytest.raises(SystemExit):
23662365
CliApp.run(Root)
23672366
assert (
23682367
capsys.readouterr().out
2369-
== f"""usage: example.py root-subcommand submodel-subcommand [-h]
2370-
--deep-submodel-arg str
2371-
DEEP-SUBMODEL-POSITIONAL-ARG
2368+
== f"""usage: example.py root-subcmd sub-subcmd [-h] --deep-arg str DEEP-POS-ARG
23722369
23732370
positional arguments:
2374-
DEEP-SUBMODEL-POSITIONAL-ARG
2371+
DEEP-POS-ARG
23752372
23762373
{ARGPARSE_OPTIONS_TEXT}:
2377-
-h, --help show this help message and exit
2378-
--deep-submodel-arg str
2379-
(required)
2374+
-h, --help show this help message and exit
2375+
--deep-arg str (required)
23802376
"""
23812377
)

0 commit comments

Comments
 (0)