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_enum16(self): enum_options = {'first': 1024, 'second': 2048} coltype = self._type_round_trip( types.Enum16(enum.Enum('any16_enum', enum_options)))[0] self.assertIsInstance(coltype, types.Enum16) 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)")