@@ -1410,22 +1410,36 @@ class Color(Enum):
14101410 def test_interactively_defined_enum (self ):
14111411 code = """if True:
14121412 from enum import Enum
1413- from testutils import subprocess_pickle_echo
1413+ from testutils import subprocess_worker
14141414
1415- class Color(Enum):
1416- RED = 1
1417- GREEN = 2
1415+ with subprocess_worker(protocol={protocol}) as w:
14181416
1419- green1, green2, ClonedColor = subprocess_pickle_echo(
1420- [Color.GREEN, Color.GREEN, Color], protocol={protocol})
1421- assert green1 is green2
1422- assert green1 is ClonedColor.GREEN
1417+ class Color(Enum):
1418+ RED = 1
1419+ GREEN = 2
1420+
1421+ def check_positive(x):
1422+ return Color.GREEN if x >= 0 else Color.RED
1423+
1424+ result = w.run(check_positive, 1)
1425+
1426+ # Check that the returned enum instance is reconciled with the
1427+ # locally defined Color enum type definition:
1428+
1429+ assert result is Color.GREEN
1430+
1431+ # Check that changing the defintion of the Enum class is taken
1432+ # into account on the worker for subsequent calls:
1433+
1434+ class Color(Enum):
1435+ RED = 1
1436+ BLUE = 2
1437+
1438+ def check_positive(x):
1439+ return Color.BLUE if x >= 0 else Color.RED
14231440
1424- # Check that the pickle that was return has been matched back to the
1425- # interactively defined Color living in the __main__ module of the
1426- # original Python process.
1427- assert ClonedColor is Color
1428- assert green1 is Color.GREEN
1441+ result = w.run(check_positive, 1)
1442+ assert result is Color.BLUE
14291443 """ .format (protocol = self .protocol )
14301444 assert_run_python_script (code )
14311445
0 commit comments