@@ -560,6 +560,49 @@ def test_format_enum_str(self):
560560 self .assertFormatIsValue ('{:>20}' , Directional .WEST )
561561 self .assertFormatIsValue ('{:<20}' , Directional .WEST )
562562
563+ def test_enum_str_override (self ):
564+ class MyStrEnum (Enum ):
565+ def __str__ (self ):
566+ return 'MyStr'
567+ class MyMethodEnum (Enum ):
568+ def hello (self ):
569+ return 'Hello! My name is %s' % self .name
570+ class Test1Enum (MyMethodEnum , int , MyStrEnum ):
571+ One = 1
572+ Two = 2
573+ self .assertEqual (str (Test1Enum .One ), 'MyStr' )
574+ #
575+ class Test2Enum (MyStrEnum , MyMethodEnum ):
576+ One = 1
577+ Two = 2
578+ self .assertEqual (str (Test2Enum .One ), 'MyStr' )
579+
580+ def test_inherited_data_type (self ):
581+ class HexInt (int ):
582+ def __repr__ (self ):
583+ return hex (self )
584+ class MyEnum (HexInt , enum .Enum ):
585+ A = 1
586+ B = 2
587+ C = 3
588+ self .assertEqual (repr (MyEnum .A ), '<MyEnum.A: 0x1>' )
589+
590+ def test_too_many_data_types (self ):
591+ with self .assertRaisesRegex (TypeError , 'too many data types' ):
592+ class Huh (str , int , Enum ):
593+ One = 1
594+
595+ class MyStr (str ):
596+ def hello (self ):
597+ return 'hello, %s' % self
598+ class MyInt (int ):
599+ def repr (self ):
600+ return hex (self )
601+ with self .assertRaisesRegex (TypeError , 'too many data types' ):
602+ class Huh (MyStr , MyInt , Enum ):
603+ One = 1
604+
605+
563606 def test_hash (self ):
564607 Season = self .Season
565608 dates = {}
0 commit comments