MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / test_set_with_choices

Function test_set_with_choices

tests/test_cmd2.py:269–285  ·  view source on GitHub ↗

Test choices validation of Settables

(base_app)

Source from the content-addressed store, hash-verified

267
268
269def test_set_with_choices(base_app) -> None:
270 """Test choices validation of Settables"""
271 fake_choices = ["valid", "choices"]
272 base_app.fake = fake_choices[0]
273
274 fake_settable = cmd2.Settable("fake", type(base_app.fake), "fake description", base_app, choices=fake_choices)
275 base_app.add_settable(fake_settable)
276
277 # Try a valid choice
278 _out, err = run_cmd(base_app, f"set fake {fake_choices[1]}")
279 assert base_app.last_result is True
280 assert not err
281
282 # Try an invalid choice
283 _out, err = run_cmd(base_app, "set fake bad_value")
284 assert base_app.last_result is False
285 assert err[0].startswith("Error setting fake: invalid choice")
286
287
288class OnChangeHookApp(cmd2.Cmd):

Callers

nothing calls this directly

Calls 2

run_cmdFunction · 0.85
add_settableMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…