@@ -31,6 +31,11 @@ def load_tests(loader, tests, ignore):
31
31
'../../Doc/library/enum.rst' ,
32
32
optionflags = doctest .ELLIPSIS | doctest .NORMALIZE_WHITESPACE ,
33
33
))
34
+ if os .path .exists ('Doc/howto/enum.rst' ):
35
+ tests .addTests (doctest .DocFileSuite (
36
+ '../../Doc/howto/enum.rst' ,
37
+ optionflags = doctest .ELLIPSIS | doctest .NORMALIZE_WHITESPACE ,
38
+ ))
34
39
return tests
35
40
36
41
MODULE = __name__
@@ -66,6 +71,7 @@ class FlagStooges(Flag):
66
71
LARRY = 1
67
72
CURLY = 2
68
73
MOE = 4
74
+ BIG = 389
69
75
except Exception as exc :
70
76
FlagStooges = exc
71
77
@@ -74,17 +80,20 @@ class FlagStoogesWithZero(Flag):
74
80
LARRY = 1
75
81
CURLY = 2
76
82
MOE = 4
83
+ BIG = 389
77
84
78
85
class IntFlagStooges (IntFlag ):
79
86
LARRY = 1
80
87
CURLY = 2
81
88
MOE = 4
89
+ BIG = 389
82
90
83
91
class IntFlagStoogesWithZero (IntFlag ):
84
92
NOFLAG = 0
85
93
LARRY = 1
86
94
CURLY = 2
87
95
MOE = 4
96
+ BIG = 389
88
97
89
98
# for pickle test and subclass tests
90
99
class Name (StrEnum ):
@@ -1942,14 +1951,17 @@ class NEI(NamedInt, Enum):
1942
1951
__qualname__ = 'NEI'
1943
1952
x = ('the-x' , 1 )
1944
1953
y = ('the-y' , 2 )
1945
-
1946
1954
self .assertIs (NEI .__new__ , Enum .__new__ )
1947
1955
self .assertEqual (repr (NEI .x + NEI .y ), "NamedInt('(the-x + the-y)', 3)" )
1948
1956
globals ()['NamedInt' ] = NamedInt
1949
1957
globals ()['NEI' ] = NEI
1950
1958
NI5 = NamedInt ('test' , 5 )
1951
1959
self .assertEqual (NI5 , 5 )
1952
1960
self .assertEqual (NEI .y .value , 2 )
1961
+ with self .assertRaisesRegex (TypeError , "name and value must be specified" ):
1962
+ test_pickle_dump_load (self .assertIs , NEI .y )
1963
+ # fix pickle support and try again
1964
+ NEI .__reduce_ex__ = enum .pickle_by_enum_name
1953
1965
test_pickle_dump_load (self .assertIs , NEI .y )
1954
1966
test_pickle_dump_load (self .assertIs , NEI )
1955
1967
@@ -3252,11 +3264,17 @@ def test_pickle(self):
3252
3264
test_pickle_dump_load (self .assertEqual ,
3253
3265
FlagStooges .CURLY & ~ FlagStooges .CURLY )
3254
3266
test_pickle_dump_load (self .assertIs , FlagStooges )
3267
+ test_pickle_dump_load (self .assertEqual , FlagStooges .BIG )
3268
+ test_pickle_dump_load (self .assertEqual ,
3269
+ FlagStooges .CURLY | FlagStooges .BIG )
3255
3270
3256
3271
test_pickle_dump_load (self .assertIs , FlagStoogesWithZero .CURLY )
3257
3272
test_pickle_dump_load (self .assertEqual ,
3258
3273
FlagStoogesWithZero .CURLY | FlagStoogesWithZero .MOE )
3259
3274
test_pickle_dump_load (self .assertIs , FlagStoogesWithZero .NOFLAG )
3275
+ test_pickle_dump_load (self .assertEqual , FlagStoogesWithZero .BIG )
3276
+ test_pickle_dump_load (self .assertEqual ,
3277
+ FlagStoogesWithZero .CURLY | FlagStoogesWithZero .BIG )
3260
3278
3261
3279
test_pickle_dump_load (self .assertIs , IntFlagStooges .CURLY )
3262
3280
test_pickle_dump_load (self .assertEqual ,
@@ -3266,11 +3284,19 @@ def test_pickle(self):
3266
3284
test_pickle_dump_load (self .assertEqual , IntFlagStooges (0 ))
3267
3285
test_pickle_dump_load (self .assertEqual , IntFlagStooges (0x30 ))
3268
3286
test_pickle_dump_load (self .assertIs , IntFlagStooges )
3287
+ test_pickle_dump_load (self .assertEqual , IntFlagStooges .BIG )
3288
+ test_pickle_dump_load (self .assertEqual , IntFlagStooges .BIG | 1 )
3289
+ test_pickle_dump_load (self .assertEqual ,
3290
+ IntFlagStooges .CURLY | IntFlagStooges .BIG )
3269
3291
3270
3292
test_pickle_dump_load (self .assertIs , IntFlagStoogesWithZero .CURLY )
3271
3293
test_pickle_dump_load (self .assertEqual ,
3272
3294
IntFlagStoogesWithZero .CURLY | IntFlagStoogesWithZero .MOE )
3273
3295
test_pickle_dump_load (self .assertIs , IntFlagStoogesWithZero .NOFLAG )
3296
+ test_pickle_dump_load (self .assertEqual , IntFlagStoogesWithZero .BIG )
3297
+ test_pickle_dump_load (self .assertEqual , IntFlagStoogesWithZero .BIG | 1 )
3298
+ test_pickle_dump_load (self .assertEqual ,
3299
+ IntFlagStoogesWithZero .CURLY | IntFlagStoogesWithZero .BIG )
3274
3300
3275
3301
def test_contains_tf (self ):
3276
3302
Open = self .Open
0 commit comments