Skip to content

Commit

Permalink
Make for_code a public property in all strategies
Browse files Browse the repository at this point in the history
This is in order to enable non-test code to use the property.
  • Loading branch information
chris-janidlo committed Dec 10, 2024
1 parent 0467061 commit e152082
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions compute_sdk/globus_compute_sdk/serialize/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions compute_sdk/globus_compute_sdk/serialize/concretes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class DillDataBase64(SerializationStrategy):
identifier = "00\n"
_for_code = False
for_code = False

def __init__(self):
super().__init__()
Expand All @@ -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__()
Expand All @@ -59,7 +59,7 @@ class DillCodeSource(SerializationStrategy):
"""

identifier = "04\n"
_for_code = True
for_code = True

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -89,7 +89,7 @@ class DillCodeTextInspect(SerializationStrategy):
"""

identifier = "03\n"
_for_code = True
for_code = True

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -119,7 +119,7 @@ class PickleCode(SerializationStrategy):
"""

identifier = "02\n"
_for_code = True
for_code = True

def __init__(self):
super().__init__()
Expand All @@ -145,7 +145,7 @@ class DillCode(SerializationStrategy):
"""

identifier = "01\n"
_for_code = True
for_code = True

def __init__(self):
super().__init__()
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions compute_sdk/tests/integration/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -357,10 +357,10 @@ def deserialize(self, payload):


@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",
Expand Down
2 changes: 1 addition & 1 deletion compute_sdk/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit e152082

Please sign in to comment.