Test choices validation of Settables
(base_app)
| 267 | |
| 268 | |
| 269 | def 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 | |
| 288 | class OnChangeHookApp(cmd2.Cmd): |
nothing calls this directly
no test coverage detected
searching dependent graphs…