MCPcopy Index your code
hub / github.com/python/cpython / test_test_simple_enum

Method test_test_simple_enum

Lib/test/test_enum.py:5210–5321  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5208 )
5209
5210 def test_test_simple_enum(self):
5211 @_simple_enum(Enum)
5212 class SimpleColor:
5213 CYAN = 1
5214 MAGENTA = 2
5215 YELLOW = 3
5216 @bltns.property
5217 def zeroth(self):
5218 return 'zeroed %s' % self.name
5219 class CheckedColor(Enum):
5220 CYAN = 1
5221 MAGENTA = 2
5222 YELLOW = 3
5223 @bltns.property
5224 def zeroth(self):
5225 return 'zeroed %s' % self.name
5226 _test_simple_enum(CheckedColor, SimpleColor)
5227 SimpleColor.MAGENTA._value_ = 9
5228 self.assertRaisesRegex(
5229 TypeError, "enum mismatch",
5230 _test_simple_enum, CheckedColor, SimpleColor,
5231 )
5232 #
5233 #
5234 class CheckedMissing(IntFlag, boundary=KEEP):
5235 SIXTY_FOUR = 64
5236 ONE_TWENTY_EIGHT = 128
5237 TWENTY_FORTY_EIGHT = 2048
5238 ALL = 2048 + 128 + 64 + 12
5239 CM = CheckedMissing
5240 self.assertEqual(list(CheckedMissing), [CM.SIXTY_FOUR, CM.ONE_TWENTY_EIGHT, CM.TWENTY_FORTY_EIGHT])
5241 #
5242 @_simple_enum(IntFlag, boundary=KEEP)
5243 class Missing:
5244 SIXTY_FOUR = 64
5245 ONE_TWENTY_EIGHT = 128
5246 TWENTY_FORTY_EIGHT = 2048
5247 ALL = 2048 + 128 + 64 + 12
5248 M = Missing
5249 self.assertEqual(list(CheckedMissing), [M.SIXTY_FOUR, M.ONE_TWENTY_EIGHT, M.TWENTY_FORTY_EIGHT])
5250 _test_simple_enum(CheckedMissing, Missing)
5251 #
5252 #
5253 class CheckedUnhashable(Enum):
5254 ONE = dict()
5255 TWO = set()
5256 name = 'python'
5257 self.assertIn(dict(), CheckedUnhashable)
5258 self.assertIn('python', CheckedUnhashable)
5259 self.assertEqual(CheckedUnhashable.name.value, 'python')
5260 self.assertEqual(CheckedUnhashable.name.name, 'name')
5261 #
5262 @_simple_enum()
5263 class Unhashable:
5264 ONE = dict()
5265 TWO = set()
5266 name = 'python'
5267 self.assertIn(dict(), Unhashable)

Callers

nothing calls this directly

Calls 6

_test_simple_enumFunction · 0.90
listClass · 0.85
assertRaisesRegexMethod · 0.80
assertInMethod · 0.80
assertEqualMethod · 0.45
assertIsMethod · 0.45

Tested by

no test coverage detected