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