def test_enum(self): class MyEnum(enum.Enum): __order__ = 'foo bar' foo = 100 bar = 500 self.assertEqual( self.compile(types.Enum(MyEnum)), "Enum('foo' = 100, 'bar' = 500)" ) self.assertEqual( self.compile(types.Enum16(MyEnum)), "Enum16('foo' = 100, 'bar' = 500)" ) if compat.PY3: data = [" ' t = ", "test"] else: from collections import OrderedDict data = OrderedDict([(" ' t = ", 1), ("test", 2)]) MyEnum = enum.Enum('MyEnum', data) self.assertEqual( self.compile(types.Enum8(MyEnum)), "Enum8(' \\' t = ' = 1, 'test' = 2)" )
def test_enum8(self): enum_options = {'three': 3, "quoted' ": 9, 'comma, ': 14} coltype = self._type_round_trip( types.Enum8(enum.Enum('any8_enum', enum_options)))[0] self.assertIsInstance(coltype, types.Enum8) self.assertEqual({o.name: o.value for o in coltype.enum_class}, enum_options)
def test_enum(self): class MyEnum(enum.Enum): __order__ = 'foo bar' foo = 100 bar = 500 self.assertEqual(self.compile(types.Enum(MyEnum)), "Enum('foo' = 100, 'bar' = 500)") self.assertEqual(self.compile(types.Enum16(MyEnum)), "Enum16('foo' = 100, 'bar' = 500)") MyEnum = enum.Enum('MyEnum', [" ' t = ", "test"]) self.assertEqual(self.compile(types.Enum8(MyEnum)), "Enum8(' \\' t = ' = 1, 'test' = 2)")