Пример #1
0
 def test_serialize_parse(self, value, lowercase, expected):
     serializer = _argument_parser.EnumClassSerializer(lowercase=lowercase)
     parser = _argument_parser.EnumClassParser(Fruit,
                                               case_sensitive=not lowercase)
     serialized = serializer.serialize(value)
     self.assertEqual(serialized, expected)
     self.assertEqual(value, parser.parse(expected))
Пример #2
0
 def __init__(self, name, default, help, enum_class,  # pylint: disable=redefined-builtin
              short_name=None, **args):
   p = _argument_parser.EnumClassParser(enum_class)
   g = _argument_parser.EnumClassSerializer()
   super(EnumClassFlag, self).__init__(
       p, g, name, default, help, short_name, **args)
   self.help = '<%s>: %s' % ('|'.join(enum_class.__members__), self.help)
 def test_serialize_parse(self):
     serializer = _argument_parser.EnumClassSerializer()
     val1 = Fruit.BANANA
     parser = _argument_parser.EnumClassParser(Fruit)
     serialized = serializer.serialize(val1)
     self.assertEqual(serialized, 'BANANA')
     val2 = parser.parse(serialized)
     self.assertEqual(val1, val2)
 def __init__(
         self,
         name,
         default,
         help,  # pylint: disable=redefined-builtin
         enum_class,
         short_name=None,
         case_sensitive=False,
         **args):
     p = _argument_parser.EnumClassParser(enum_class,
                                          case_sensitive=case_sensitive)
     g = _argument_parser.EnumClassSerializer(lowercase=not case_sensitive)
     super(EnumClassFlag, self).__init__(p, g, name, default, help,
                                         short_name, **args)
     self.help = '<%s>: %s' % ('|'.join(p.member_names), self.help)