diff --git a/compute_sdk/globus_compute_sdk/serialize/base.py b/compute_sdk/globus_compute_sdk/serialize/base.py index 82d63150c..888a3c672 100644 --- a/compute_sdk/globus_compute_sdk/serialize/base.py +++ b/compute_sdk/globus_compute_sdk/serialize/base.py @@ -21,6 +21,11 @@ def __init_subclass__(cls): def identifier(self): pass + @property + @abstractmethod + def for_code(self): + pass + def chomp(self, payload: str) -> str: """If the payload starts with the identifier, return the remaining block diff --git a/compute_sdk/globus_compute_sdk/serialize/concretes.py b/compute_sdk/globus_compute_sdk/serialize/concretes.py index 34fac9446..8f9490282 100644 --- a/compute_sdk/globus_compute_sdk/serialize/concretes.py +++ b/compute_sdk/globus_compute_sdk/serialize/concretes.py @@ -17,7 +17,7 @@ class DillDataBase64(SerializationStrategy): identifier = "00\n" - _for_code = False + for_code = False def __init__(self): super().__init__() @@ -34,7 +34,7 @@ def deserialize(self, payload: str): class JSONData(SerializationStrategy): identifier = "11\n" - _for_code = False + for_code = False def __init__(self): super().__init__() @@ -59,7 +59,7 @@ class DillCodeSource(SerializationStrategy): """ identifier = "04\n" - _for_code = True + for_code = True def __init__(self): super().__init__() @@ -89,7 +89,7 @@ class DillCodeTextInspect(SerializationStrategy): """ identifier = "03\n" - _for_code = True + for_code = True def __init__(self): super().__init__() @@ -119,7 +119,7 @@ class PickleCode(SerializationStrategy): """ identifier = "02\n" - _for_code = True + for_code = True def __init__(self): super().__init__() @@ -145,7 +145,7 @@ class DillCode(SerializationStrategy): """ identifier = "01\n" - _for_code = True + for_code = True def __init__(self): super().__init__() @@ -171,7 +171,7 @@ class CombinedCode(SerializationStrategy): """ identifier = "10\n" - _for_code = True + for_code = True # Functions are serialized using the following strategies and the resulting encoded # versions are stored as chunks. Allows redundancy if one of the strategies fails diff --git a/compute_sdk/tests/integration/test_serialization.py b/compute_sdk/tests/integration/test_serialization.py index 592fa9702..44f988af5 100644 --- a/compute_sdk/tests/integration/test_serialization.py +++ b/compute_sdk/tests/integration/test_serialization.py @@ -327,7 +327,7 @@ def test_compute_serializer_defaults(): @pytest.mark.parametrize("strategy", concretes.SELECTABLE_STRATEGIES) def test_selectable_serialization(strategy): - if strategy._for_code: + if strategy.for_code: serializer = ComputeSerializer(strategy_code=strategy()) data = foo else: @@ -340,6 +340,7 @@ def test_selectable_serialization(strategy): def test_serializer_errors_on_unknown_strategy(): class NewStrategy(SerializationStrategy): identifier = "aa\n" + for_code = True def serialize(self, data): pass @@ -352,15 +353,17 @@ def deserialize(self, payload): with pytest.raises(SerializationError): ComputeSerializer(strategy_code=strategy) + NewStrategy.for_code = False + with pytest.raises(SerializationError): ComputeSerializer(strategy_data=strategy) @pytest.mark.parametrize( - "strategy_code", (s for s in concretes.SELECTABLE_STRATEGIES if s._for_code) + "strategy_code", (s for s in concretes.SELECTABLE_STRATEGIES if s.for_code) ) @pytest.mark.parametrize( - "strategy_data", (s for s in concretes.SELECTABLE_STRATEGIES if not s._for_code) + "strategy_data", (s for s in concretes.SELECTABLE_STRATEGIES if not s.for_code) ) @pytest.mark.parametrize( "function, args, kwargs", diff --git a/compute_sdk/tests/unit/test_client.py b/compute_sdk/tests/unit/test_client.py index 10d759036..e99706ffe 100644 --- a/compute_sdk/tests/unit/test_client.py +++ b/compute_sdk/tests/unit/test_client.py @@ -211,7 +211,7 @@ def test_batch_created_websocket_queue(gcc, create_result_queue): @pytest.mark.parametrize( - "strategy", [s for s in SELECTABLE_STRATEGIES if not s._for_code] + "strategy", [s for s in SELECTABLE_STRATEGIES if not s.for_code] ) def test_batch_respects_serialization_strategy(gcc, strategy): gcc.fx_serializer = ComputeSerializer(strategy_data=strategy())