@@ -1756,6 +1756,14 @@ def MAX(cls):
1756
1756
class StrMixin :
1757
1757
def __str__ (self ):
1758
1758
return self ._name_ .lower ()
1759
+ class SomeEnum (Enum ):
1760
+ def behavior (self ):
1761
+ return 'booyah'
1762
+ class AnotherEnum (Enum ):
1763
+ def behavior (self ):
1764
+ return 'nuhuh!'
1765
+ def social (self ):
1766
+ return "what's up?"
1759
1767
class Color (MaxMixin , Enum ):
1760
1768
RED = auto ()
1761
1769
GREEN = auto ()
@@ -1783,6 +1791,56 @@ class Color(StrMixin, MaxMixin, Enum):
1783
1791
self .assertEqual (Color .BLUE .value , 3 )
1784
1792
self .assertEqual (Color .MAX , 3 )
1785
1793
self .assertEqual (str (Color .BLUE ), 'blue' )
1794
+ class CoolColor (StrMixin , SomeEnum , Enum ):
1795
+ RED = auto ()
1796
+ GREEN = auto ()
1797
+ BLUE = auto ()
1798
+ self .assertEqual (CoolColor .RED .value , 1 )
1799
+ self .assertEqual (CoolColor .GREEN .value , 2 )
1800
+ self .assertEqual (CoolColor .BLUE .value , 3 )
1801
+ self .assertEqual (str (CoolColor .BLUE ), 'blue' )
1802
+ self .assertEqual (CoolColor .RED .behavior (), 'booyah' )
1803
+ class CoolerColor (StrMixin , AnotherEnum , Enum ):
1804
+ RED = auto ()
1805
+ GREEN = auto ()
1806
+ BLUE = auto ()
1807
+ self .assertEqual (CoolerColor .RED .value , 1 )
1808
+ self .assertEqual (CoolerColor .GREEN .value , 2 )
1809
+ self .assertEqual (CoolerColor .BLUE .value , 3 )
1810
+ self .assertEqual (str (CoolerColor .BLUE ), 'blue' )
1811
+ self .assertEqual (CoolerColor .RED .behavior (), 'nuhuh!' )
1812
+ self .assertEqual (CoolerColor .RED .social (), "what's up?" )
1813
+ class CoolestColor (StrMixin , SomeEnum , AnotherEnum ):
1814
+ RED = auto ()
1815
+ GREEN = auto ()
1816
+ BLUE = auto ()
1817
+ self .assertEqual (CoolestColor .RED .value , 1 )
1818
+ self .assertEqual (CoolestColor .GREEN .value , 2 )
1819
+ self .assertEqual (CoolestColor .BLUE .value , 3 )
1820
+ self .assertEqual (str (CoolestColor .BLUE ), 'blue' )
1821
+ self .assertEqual (CoolestColor .RED .behavior (), 'booyah' )
1822
+ self .assertEqual (CoolestColor .RED .social (), "what's up?" )
1823
+ class ConfusedColor (StrMixin , AnotherEnum , SomeEnum ):
1824
+ RED = auto ()
1825
+ GREEN = auto ()
1826
+ BLUE = auto ()
1827
+ self .assertEqual (ConfusedColor .RED .value , 1 )
1828
+ self .assertEqual (ConfusedColor .GREEN .value , 2 )
1829
+ self .assertEqual (ConfusedColor .BLUE .value , 3 )
1830
+ self .assertEqual (str (ConfusedColor .BLUE ), 'blue' )
1831
+ self .assertEqual (ConfusedColor .RED .behavior (), 'nuhuh!' )
1832
+ self .assertEqual (ConfusedColor .RED .social (), "what's up?" )
1833
+ class ReformedColor (StrMixin , IntEnum , SomeEnum , AnotherEnum ):
1834
+ RED = auto ()
1835
+ GREEN = auto ()
1836
+ BLUE = auto ()
1837
+ self .assertEqual (ReformedColor .RED .value , 1 )
1838
+ self .assertEqual (ReformedColor .GREEN .value , 2 )
1839
+ self .assertEqual (ReformedColor .BLUE .value , 3 )
1840
+ self .assertEqual (str (ReformedColor .BLUE ), 'blue' )
1841
+ self .assertEqual (ReformedColor .RED .behavior (), 'booyah' )
1842
+ self .assertEqual (ConfusedColor .RED .social (), "what's up?" )
1843
+ self .assertTrue (issubclass (ReformedColor , int ))
1786
1844
1787
1845
1788
1846
class TestOrder (unittest .TestCase ):
0 commit comments