Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init(self):
"""
InputArgument.__init__() behaves properly
"""
argument = InputArgument('foo')
self.assertEqual('foo', argument.get_name(), msg='__init__() takes a name as its first argument')
# mode argument
argument = InputArgument('foo')
self.assertFalse(argument.is_required(), msg='__init__() gives a "InputArgument.OPTIONAL" mode by default')
argument = InputArgument('foo', None)
self.assertFalse(argument.is_required(), msg='__init__() can take "InputArgument.OPTIONAL" as its mode')
argument = InputArgument('foo', InputArgument.OPTIONAL)
self.assertFalse(argument.is_required(), msg='__init__() can take "InputArgument.OPTIONAL" as its mode')
argument = InputArgument('foo', InputArgument.REQUIRED)
self.assertTrue(argument.is_required(), msg='__init__() can take "InputArgument.REQUIRED" as its mode')
self.assertRaises(Exception, InputArgument, 'foo', 'ANOTHER_MODE')
self.assertRaises(Exception, InputArgument, 'foo', -1)
validator = Integer()
argument = InputArgument('foo', None, validator=validator)
def test_init(self):
"""
InputArgument.__init__() behaves properly
"""
argument = InputArgument('foo')
self.assertEqual('foo', argument.get_name(), msg='__init__() takes a name as its first argument')
# mode argument
argument = InputArgument('foo')
self.assertFalse(argument.is_required(), msg='__init__() gives a "InputArgument.OPTIONAL" mode by default')
argument = InputArgument('foo', None)
self.assertFalse(argument.is_required(), msg='__init__() can take "InputArgument.OPTIONAL" as its mode')
argument = InputArgument('foo', InputArgument.OPTIONAL)
self.assertFalse(argument.is_required(), msg='__init__() can take "InputArgument.OPTIONAL" as its mode')
argument = InputArgument('foo', InputArgument.REQUIRED)
self.assertTrue(argument.is_required(), msg='__init__() can take "InputArgument.REQUIRED" as its mode')
self.assertRaises(Exception, InputArgument, 'foo', 'ANOTHER_MODE')
def test_init(self):
"""
InputArgument.__init__() behaves properly
"""
argument = InputArgument('foo')
self.assertEqual('foo', argument.get_name(), msg='__init__() takes a name as its first argument')
# mode argument
argument = InputArgument('foo')
self.assertFalse(argument.is_required(), msg='__init__() gives a "InputArgument.OPTIONAL" mode by default')
argument = InputArgument('foo', None)
self.assertFalse(argument.is_required(), msg='__init__() can take "InputArgument.OPTIONAL" as its mode')
argument = InputArgument('foo', InputArgument.OPTIONAL)
self.assertFalse(argument.is_required(), msg='__init__() can take "InputArgument.OPTIONAL" as its mode')
argument = InputArgument('foo', InputArgument.REQUIRED)
self.assertTrue(argument.is_required(), msg='__init__() can take "InputArgument.REQUIRED" as its mode')
self.assertRaises(Exception, InputArgument, 'foo', 'ANOTHER_MODE')
self.assertRaises(Exception, InputArgument, 'foo', -1)
validator = Integer()
argument = InputArgument('foo', None, validator=validator)
self.assertEqual(validator, argument.get_validator())
# Named validator
validator = 'integer'
argument = InputArgument('foo', None, validator=validator)
self.assertIsInstance(argument.get_validator(), Integer)
InputArgument.__init__() behaves properly
"""
argument = InputArgument('foo')
self.assertEqual('foo', argument.get_name(), msg='__init__() takes a name as its first argument')
# mode argument
argument = InputArgument('foo')
self.assertFalse(argument.is_required(), msg='__init__() gives a "InputArgument.OPTIONAL" mode by default')
argument = InputArgument('foo', None)
self.assertFalse(argument.is_required(), msg='__init__() can take "InputArgument.OPTIONAL" as its mode')
argument = InputArgument('foo', InputArgument.OPTIONAL)
self.assertFalse(argument.is_required(), msg='__init__() can take "InputArgument.OPTIONAL" as its mode')
argument = InputArgument('foo', InputArgument.REQUIRED)
self.assertTrue(argument.is_required(), msg='__init__() can take "InputArgument.REQUIRED" as its mode')
self.assertRaises(Exception, InputArgument, 'foo', 'ANOTHER_MODE')
self.assertRaises(Exception, InputArgument, 'foo', -1)
validator = Integer()
argument = InputArgument('foo', None, validator=validator)
self.assertEqual(validator, argument.get_validator())
# Named validator
validator = 'integer'
argument = InputArgument('foo', None, validator=validator)
self.assertIsInstance(argument.get_validator(), Integer)
# Native type
validator = int
def test_get_description(self):
"""
InputArgument.get_description() returns the message description
"""
argument = InputArgument('foo', None, 'Some description')
self.assertEqual('Some description', argument.get_description(),
msg='.get_description() returns the message description')
def test_is_list(self):
"""
InputArgument.is_list() returns true if the argument can be an array'
"""
argument = InputArgument('foo', InputArgument.IS_LIST)
self.assertTrue(argument.is_list())
argument = InputArgument('foo', InputArgument.OPTIONAL | InputArgument.IS_LIST)
self.assertTrue(argument.is_list())
argument = InputArgument('foo', InputArgument.OPTIONAL)
self.assertFalse(argument.is_list())
def test_is_list(self):
"""
InputArgument.is_list() returns true if the argument can be an array'
"""
argument = InputArgument('foo', InputArgument.IS_LIST)
self.assertTrue(argument.is_list())
argument = InputArgument('foo', InputArgument.OPTIONAL | InputArgument.IS_LIST)
self.assertTrue(argument.is_list())
argument = InputArgument('foo', InputArgument.OPTIONAL)
self.assertFalse(argument.is_list())
self.assertRaises(Exception, InputArgument, 'foo', 'ANOTHER_MODE')
self.assertRaises(Exception, InputArgument, 'foo', -1)
validator = Integer()
argument = InputArgument('foo', None, validator=validator)
self.assertEqual(validator, argument.get_validator())
# Named validator
validator = 'integer'
argument = InputArgument('foo', None, validator=validator)
self.assertIsInstance(argument.get_validator(), Integer)
# Native type
validator = int
argument = InputArgument('foo', None, validator=validator)
self.assertIsInstance(argument.get_validator(), Integer)
:param required: Whether the argument is required or not.
:type required: bool
:param default: The default value of the argument.
:type default: mixed
:param is_list: Whether the argument should be a list or not.
:type list: bool
:param validator: An optional validator.
:type validator: Validator or str
:rtype: InputArgument
"""
mode = InputArgument.OPTIONAL
if required:
mode = InputArgument.REQUIRED
if is_list:
mode |= InputArgument.IS_LIST
return InputArgument(name, mode, description, default, validator)
:param is_list: Whether the argument should be a list or not.
:type list: bool
:param validator: An optional validator.
:type validator: Validator or str
:rtype: InputArgument
"""
mode = InputArgument.OPTIONAL
if required:
mode = InputArgument.REQUIRED
if is_list:
mode |= InputArgument.IS_LIST
return InputArgument(name, mode, description, default, validator)