예제 #1
0
 def testMalformedFunction(self):
   with self.assertRaises(TypeError):
     self.parser.add_argument(
         '--testarg',
         action=calliope_actions._PreActionHook(self.custom_action,
                                                lambda x, y, z: True),
         help='Test help')
     self.parser.parse_args(['--testarg', 'foo'])
예제 #2
0
 def testInvalidFunction(self):
   error_str = r'func should be a callable of the form func\(value\)'
   with self.assertRaisesRegex(TypeError, error_str):
     self.parser.add_argument(
         '--testarg',
         action=calliope_actions._PreActionHook(self.custom_action,
                                                'non-func'),
         help='Test help')
예제 #3
0
  def testInvalidAction(self):
    error_str = ('action should be either a subclass of argparse.Action or a '
                 'string representing one of the default argparse Action Types')

    with self.assertRaisesRegex(TypeError, error_str):
      self.parser.add_argument(
          'test-arg',
          action=calliope_actions._PreActionHook(object, lambda _: False),
          help='Test help')
예제 #4
0
 def testPreActionHook(self):
   self.parser.add_argument(
       '--testarg',
       action=calliope_actions._PreActionHook(self.custom_action,
                                              self.func_test),
       help='Test help')
   self.parser.parse_args(['--testarg', 'foo'])
   self.assertEqual(self.action_call_stack[0], 'Calling Wrapper on foo')
   self.assertEqual(self.action_call_stack[1], 'customTestAction')
예제 #5
0
 def testAdditionalHelp(self):
   arg = self.parser.add_argument(
       '--testarg',
       action=calliope_actions._PreActionHook(
           self.custom_action, self.func_test,
           calliope_actions._AdditionalHelp(label='TESTING',
                                            message='Test Additional Help')),
       help='Test help')
   self.parser.parse_args(['--testarg', 'foo'])
   help_str = r'TESTING Test help.[+\s]*Test Additional Help'
   self.assertRegexpMatches(arg.help.replace('\n', ' '), help_str)
예제 #6
0
 def testInvalidActionString(self):
   with self.assertRaisesRegex(ValueError, 'unknown action "foo"'):
     self.parser.add_argument(
         'test_arg',
         action=calliope_actions._PreActionHook('foo', lambda _: False),
         help='Test help')