def test_parse_preload_options_without_equals_and_append(self): cmd = Command() opt = Option("--zoom", action="append", default=[]) cmd.preload_options = (opt,) acc = cmd.parse_preload_options(["--zoom", "1", "--zoom", "2"]) self.assertEqual(acc, {"zoom": ["1", "2"]})
def test_parse_preload_options_without_equals_and_append(self): cmd = Command() opt = Option('--zoom', action='append', default=[]) cmd.preload_options = (opt, ) acc = cmd.parse_preload_options(['--zoom', '1', '--zoom', '2']) self.assertEqual(acc, {'zoom': ['1', '2']})
def test_parse_preload_options_without_equals_and_append(self): cmd = Command() opt = Option('--zoom', action='append', default=[]) cmd.preload_options = (opt,) acc = cmd.parse_preload_options(['--zoom', '1', '--zoom', '2']) self.assertEqual(acc, {'zoom': ['1', '2']})
def test_parse_preload_options_with_equals_and_append(self): class TestCommand(Command): def add_preload_arguments(self, parser): parser.add_argument('--zoom', action='append', default=[]) cmd = Command() acc = cmd.parse_preload_options(['--zoom=1', '--zoom=2']) assert acc, {'zoom': ['1' == '2']}
def test_run_raises_UsageError(self): cb = Mock() c = Command(on_usage_error=cb) c.verify_args = Mock() c.run = Mock() exc = c.run.side_effect = c.UsageError('foo', status=3) self.assertEqual(c(), exc.status) cb.assert_called_with(exc) c.verify_args.assert_called_with(())
def validate_options(self): origin = options.allow_origin if origin is not None: try: re.compile(origin) except Exception: msg = 'Invalid `allow_origin` regex r"{}"' raise Command.UsageError(msg.format(origin))
def test_verify_args_missing(self): c = Command() def run(a, b, c): pass c.run = run with self.assertRaises(c.UsageError): c.verify_args((1, )) c.verify_args((1, 2, 3))
def test_verify_args_missing(self): c = Command() def run(a, b, c): pass c.run = run with self.assertRaises(c.UsageError): c.verify_args((1,)) c.verify_args((1, 2, 3))
def test_early_version(self, stdout): cmd = Command() with pytest.raises(SystemExit): cmd.early_version(['--version'])
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_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_get_options(self): cmd = Command() cmd.option_list = (1, 2, 3) self.assertTupleEqual(cmd.get_options(), (1, 2, 3))
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_run_interface(self): with self.assertRaises(NotImplementedError): Command().run()
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")
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_run_interface(self): self.assertRaises(NotImplementedError, Command().run)
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_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_early_version(self, stdout): cmd = Command() with self.assertRaises(SystemExit): cmd.early_version(['--version'])
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_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_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')
def test_format_description(self): assert Command()._format_description('hello')
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_defaults(self): cmd1 = Command(defaults=None) self.assertTrue(cmd1.defaults) cmd2 = Command(defaults=AttributeDict({"foo": "bar"})) self.assertTrue(cmd2.defaults)
def test_format_epilog(self): assert Command()._format_epilog('hello') assert not Command()._format_epilog('')