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