MCPcopy Create free account
hub / github.com/ipython/traitlets / test_alias_unrecognized

Method test_alias_unrecognized

tests/config/test_application.py:397–419  ·  view source on GitHub ↗

Check ability to override handling for unrecognized aliases

(self)

Source from the content-addressed store, hash-verified

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"""

Callers

nothing calls this directly

Calls 2

StrictApplicationClass · 0.85
initializeMethod · 0.45

Tested by

no test coverage detected