MCPcopy Create free account
hub / github.com/cloudpipe/cloudpickle / test_locally_defined_enum

Method test_locally_defined_enum

tests/cloudpickle_test.py:2362–2391  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2360 assert data.x == pickle_depickle(data, protocol=self.protocol).x == 42
2361
2362 def test_locally_defined_enum(self):
2363 class StringEnum(str, enum.Enum):
2364 """Enum when all members are also (and must be) strings"""
2365
2366 class Color(StringEnum):
2367 """3-element color space"""
2368
2369 RED = "1"
2370 GREEN = "2"
2371 BLUE = "3"
2372
2373 def is_green(self):
2374 return self is Color.GREEN
2375
2376 green1, green2, ClonedColor = pickle_depickle(
2377 [Color.GREEN, Color.GREEN, Color], protocol=self.protocol
2378 )
2379 assert green1 is green2
2380 assert green1 is ClonedColor.GREEN
2381 assert green1 is not ClonedColor.BLUE
2382 assert isinstance(green1, str)
2383 assert green1.is_green()
2384
2385 # cloudpickle systematically tracks provenance of class definitions
2386 # and ensure reconciliation in case of round trips:
2387 assert green1 is Color.GREEN
2388 assert ClonedColor is Color
2389
2390 green3 = pickle_depickle(Color.GREEN, protocol=self.protocol)
2391 assert green3 is Color.GREEN
2392
2393 def test_locally_defined_intenum(self):
2394 # Try again with a IntEnum defined with the functional API

Callers

nothing calls this directly

Calls 2

pickle_depickleFunction · 0.85
is_greenMethod · 0.80

Tested by

no test coverage detected