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'])
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')
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')
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')
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)
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')