def test_parse_bool(self): parser = defopt._get_parser(bool) self.assertEqual(parser('t'), True) self.assertEqual(parser('FALSE'), False) self.assertEqual(parser('1'), True) with self.assertRaises(ValueError): parser('foo')
def test_parse_slice(self): parser = defopt._get_parser(slice, {}) self.assertEqual(parser(':'), slice(None)) self.assertEqual(parser(':1'), slice(None, 1)) self.assertEqual(parser('"a":"b":"c"'), slice("a", "b", "c")) with self.assertRaises(ValueError): parser('1')
def test_list_bare(self): with self.assertRaises(ValueError): defopt._get_parser(list)
def test_no_parser(self): with self.assertRaisesRegex(Exception, 'no parser'): defopt._get_parser(object, parsers={type: type})
def test_no_parser(self): with self.assertRaisesRegex(Exception, 'no parser'): defopt._get_parser(object)