Beispiel #1
0
 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)
Beispiel #2
0
 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)
Beispiel #3
0
 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")
Beispiel #4
0
 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)
Beispiel #5
0
 def parse_args(self, pre_args):
     parser = create_argparser()
     args = pre_args + VALID_COMMAND
     return parser.parse_args(args)
Beispiel #6
0
 def test_create_argparser__help(self):
     parser = create_argparser()
     with self.assertRaises(HelpRequested):
         parser.parse_args(["--help"])
Beispiel #7
0
 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)
Beispiel #8
0
 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)
Beispiel #9
0
 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)
Beispiel #10
0
 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)
Beispiel #11
0
 def parse_args(self, pre_args):
     parser = create_argparser()
     args = pre_args + VALID_COMMAND
     return parser.parse_args(args)
Beispiel #12
0
 def parser(self):
     return create_argparser()