def test_early_version(self, stdout): cmd = Command() with self.assertRaises(SystemExit): cmd.early_version(['--version'])
def test_default_on_usage_error(self): cmd = Command() cmd.handle_error = Mock() exc = Exception() cmd.on_usage_error(exc) cmd.handle_error.assert_called_with(exc)
def test_run_interface(self): with self.assertRaises(NotImplementedError): Command().run()
def test_get_options(self): cmd = Command() cmd.option_list = (1, 2, 3) self.assertTupleEqual(cmd.get_options(), (1, 2, 3))
def test_register_callbacks(self): c = Command(on_error=8, on_usage_error=9) self.assertEqual(c.on_error, 8) self.assertEqual(c.on_usage_error, 9)
def test_register_callbacks(self): c = Command(on_error=8, on_usage_error=9) assert c.on_error == 8 assert c.on_usage_error == 9
def test_parse_preload_options_shortopt(self): cmd = Command() cmd.preload_options = (Option('-s', action='store', dest='silent'), ) acc = cmd.parse_preload_options(['-s', 'yes']) self.assertEqual(acc.get('silent'), 'yes')
def test_format_epilog(self): assert Command()._format_epilog('hello') assert not Command()._format_epilog('')
def test_format_description(self): assert Command()._format_description('hello')
def test_early_version(self, stdout): cmd = Command() with pytest.raises(SystemExit): cmd.early_version(['--version'])
def test_get_options(self): cmd = Command() cmd.option_list = (1, 2, 3) assert cmd.get_options() == (1, 2, 3)
def test_run_interface(self): with pytest.raises(NotImplementedError): Command().run()
def test_run_interface(self): self.assertRaises(NotImplementedError, Command().run)
def test_defaults(self): cmd1 = Command(defaults=None) self.assertTrue(cmd1.defaults) cmd2 = Command(defaults=AttributeDict({"foo": "bar"})) self.assertTrue(cmd2.defaults)
def test_early_version(self, stdout): cmd = Command() with self.assertRaises(SystemExit): cmd.early_version(['--version']) stdout.write.assert_called_with(cmd.version + '\n')
def test_parse_options_version_only(self, stdout): cmd = Command() with self.assertRaises(SystemExit): cmd.parse_options('prog', ['--version']) stdout.write.assert_called_with(cmd.version + '\n')