def test_update_parser(self, update_parser): apm = argument.ArgumentParseManager('exe', {}) apm.update_parser() self.assertEqual(len(update_parser.mock_calls), 0) expd = dict(k1=argument.Argument(0, parsed_name='-a'), k2=argument.Argument(0, parsed_name='-b')) apm.update_parser(expd) self.assertEqual(len(update_parser.mock_calls), 2)
def test___init__(self): self.assertRaises(ValueError, argument.Argument, 'non-integer') self.assertRaises(AssertionError, argument.Argument, 1) self.assertRaises(AssertionError, argument.Argument, 0, 'noname') self.assertRaises(AssertionError, argument.Argument, 0, '--no name') self.assertRaises(AssertionError, argument.Argument, 0, ['-n', 'n m']) for arity, help, parsed_name, default in ((0, 'help 0', '--zero', None), (1, 'help 1', ['--one', '-o'], 'lala'), (-1, 'help -1', [ '--help', '--or', '--more' ], 0), (0, 'help 0 again', [ '--again', ], True)): a = argument.Argument(arity, help, parsed_name, default) if arity: self.assertEqual(arity, a.arity) self.assertEqual(help, a.help) exp_name = parsed_name if (isinstance(parsed_name, list)) else [ parsed_name, ] self.assertEqual(exp_name, a.parsed_name) if default or arity: self.assertEqual(default or None, a.default) else: self.assertFalse(a.default)
def test_update_parser(self): for i, arity in enumerate((-1, 0, 1)): arp = argument.ArgumentParser() pname, aname = '--pname%s' % i, 'a_name_%s' % i a = argument.Argument(arity, 'args', pname, 42) a.update_parser(arp, aname) f = StringIO() arp.print_usage(file=f), f.seek(0) usage, exp = f.readline(), '[%s%s]\n' % (pname, (' %s' % aname.upper()) if arity else '') self.assertEqual(usage[-len(exp):], exp) del arp
def test_value(self): a = argument.Argument(1, parsed_name='--value') for value in (None, '', 0, 0.1, -12, [1, 'a', 2.8], (3, 'lala'), 'pi'): a.value = value self.assertEqual(value, a.value)