Check ability to override handling for unrecognized aliases
(self)
| 395 | self.assertIn("Equivalent to: [--Foo.name]", hmsg) |
| 396 | |
| 397 | def test_alias_unrecognized(self): |
| 398 | """Check ability to override handling for unrecognized aliases""" |
| 399 | |
| 400 | class StrictLoader(KVArgParseConfigLoader): |
| 401 | def _handle_unrecognized_alias(self, arg): |
| 402 | self.parser.error("Unrecognized alias: %s" % arg) |
| 403 | |
| 404 | class StrictApplication(Application): |
| 405 | def _create_loader(self, argv, aliases, flags, classes): |
| 406 | return StrictLoader(argv, aliases, flags, classes=classes, log=self.log) |
| 407 | |
| 408 | app = StrictApplication() |
| 409 | app.initialize(["--log-level=20"]) # recognized alias |
| 410 | assert app.log_level == 20 |
| 411 | |
| 412 | app = StrictApplication() |
| 413 | with pytest.raises(SystemExit, match="2"): |
| 414 | app.initialize(["--unrecognized=20"]) |
| 415 | |
| 416 | # Ideally we would use pytest capsys fixture, but fixtures are incompatible |
| 417 | # with unittest.TestCase-style classes :( |
| 418 | # stderr = capsys.readouterr().err |
| 419 | # assert "Unrecognized alias: unrecognized" in stderr |
| 420 | |
| 421 | def test_flag_clobber(self): |
| 422 | """test that setting flags doesn't clobber existing settings""" |
nothing calls this directly
no test coverage detected