def test_main_status__exception(self): parser = create_argparser() # TODO: check stdout. def do_func(args): raise Exception("foo") with open(os.devnull, "w") as f: self.assertEqual(main_status(parser, [], log_file=f), 2)
def test_safe_get_log_level__invalid_command(self): """Check that passing invalid command syntax returns the error level.""" parser = create_argparser() with self.assertRaises(UsageException): parser.parse_args([]) actual = parser.safe_get_log_level([], error_level=42) self.assertEqual(actual, 42)
def test_create_argparser(self): parser = create_argparser() with self.assertRaises(UsageException) as cm: parser.parse_args([]) err = cm.exception self.assertEqual(err.args, ('the following arguments are required: COMMAND', )) parser = err.parser self.assertEqual(type(parser), RcvArgumentParser) self.assertEqual(parser.prog, "rcv")
def test_safe_get_log_level__invalid_command(self): """Check that passing invalid command syntax returns the error level.""" bad_args = ['bad_command'] parser = create_argparser() # First double-check that the args are bad and raise a UsageException. with self.assertRaises(UsageException): parser.parse_args(bad_args) actual = parser.safe_get_log_level(bad_args, error_level=42) self.assertEqual(actual, 42)
def parse_args(self, pre_args): parser = create_argparser() args = pre_args + VALID_COMMAND return parser.parse_args(args)
def test_create_argparser__help(self): parser = create_argparser() with self.assertRaises(HelpRequested): parser.parse_args(["--help"])
def test_safe_get_log_level__no_level(self): """Check not passing the --log-level option.""" parser = create_argparser() actual = parser.safe_get_log_level(VALID_COMMAND, error_level=42) self.assertEqual(actual, 20)
def call_safe_get_log_level_default_error_level(self, level): parser = create_argparser() args = self._get_valid_args(level) return parser.safe_get_log_level(args)
def parser(self): return create_argparser()