@@ -1410,22 +1410,36 @@ class Color(Enum):
1410
1410
def test_interactively_defined_enum (self ):
1411
1411
code = """if True:
1412
1412
from enum import Enum
1413
- from testutils import subprocess_pickle_echo
1413
+ from testutils import subprocess_worker
1414
1414
1415
- class Color(Enum):
1416
- RED = 1
1417
- GREEN = 2
1415
+ with subprocess_worker(protocol={protocol}) as w:
1418
1416
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
1423
1440
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
1429
1443
""" .format (protocol = self .protocol )
1430
1444
assert_run_python_script (code )
1431
1445
0 commit comments