Skip to content

Commit

Permalink
Merge pull request #64 from nipreps/fix/strawberry-enum
Browse files Browse the repository at this point in the history
FIX: Strawberry enum name/value discrepancy
  • Loading branch information
mgxd authored Dec 16, 2022
2 parents f9adcf4 + a7a486e commit b4e3b16
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
13 changes: 13 additions & 0 deletions migas_server/tests/test_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

from migas_server import types

@pytest.mark.parametrize('names,val', [
(['running', 'R'], 'R'),
(['completed', 'C'], 'C'),
(['failed', 'F'], 'F'),
(['suspended', 'S'], 'S'),
])
def test_status(names, val):
for name in names:
assert getattr(types.Status, name).value == val
39 changes: 20 additions & 19 deletions migas_server/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,33 @@

@strawberry.enum
class Container(Enum):
unknown = 0
docker = 1
apptainer = 2
unknown = 'unknown'
docker = 'docker'
apptainer = 'apptainer'


@strawberry.enum
class User(Enum):
general = 0
dev = 1
ci = 2
general = 'general'
dev = 'dev'
ci = 'ci'


@strawberry.enum
class Status(Enum):
R = 'running'
running = strawberry.enum_value('running')
C = 'completed'
completed = strawberry.enum_value('completed')
F = 'failed'
failed = strawberry.enum_value('failed')
S = 'suspended'
suspended = strawberry.enum_value('suspended')
R = 'R'
running = strawberry.enum_value('R')
C = 'C'
completed = strawberry.enum_value('C')
F = 'F'
failed = strawberry.enum_value('F')
S = 'S'
suspended = strawberry.enum_value('S')

pending = strawberry.enum_value('running', deprecation_reason="Changed to `running`")
success = strawberry.enum_value('completed', deprecation_reason="Changed to `completed`")
error = strawberry.enum_value('error', deprecation_reason="Changed to `failed`")
# Deprecations, to be removed in 0.4.0
pending = strawberry.enum_value('R', deprecation_reason="Pending is now running")
success = strawberry.enum_value('C', deprecation_reason="Success is now completed")
error = strawberry.enum_value('F', deprecation_reason="Error is now failed")


# @strawberry.type
Expand All @@ -92,7 +93,7 @@ class Status(Enum):

@strawberry.type
class Process:
status: Status = Status.pending
status: Status = Status.running
status_desc: str | None = None
error_type: str | None = None
error_desc: str | None = None
Expand Down Expand Up @@ -163,7 +164,7 @@ async def serialize(data: dict) -> dict:
if isinstance(v, _BaseVersion):
data[k] = str(v)
elif isinstance(v, Enum):
data[k] = v.name
data[k] = v.value
# datetime ok?
elif isinstance(v, (Context, Process)):
data[k] = await serialize(v.__dict__)
Expand Down
8 changes: 8 additions & 0 deletions stable-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
aiohttp==3.8.3
asyncpg==0.27.0
fastapi==0.88.0
redis==4.4.0
sqlalchemy==1.4.45
starlette==0.22.0
strawberry-graphql==0.151.0
.

0 comments on commit b4e3b16

Please sign in to comment.