Skip to content

Commit

Permalink
Add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Aug 11, 2024
1 parent 510dbd3 commit 0e6c0a3
Showing 1 changed file with 177 additions and 8 deletions.
185 changes: 177 additions & 8 deletions tests/execution/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ async def get_friend(i):
return {"nonNullName": throw() if i < 0 else friends[i].name}

def get_friends(_info):
return [get_friend(0), get_friend(-1), get_friend(1)]
return [get_friend(i) for i in (0, -1, 1)]

result = await complete(
document,
Expand Down Expand Up @@ -1136,7 +1136,68 @@ def get_friends(_info):
]

@pytest.mark.asyncio()
async def handles_async_error_in_complete_value_for_non_nullable_list():
async def handles_nested_async_error_in_complete_value_after_initial_count():
document = parse(
"""
query {
friendList @stream(initialCount: 1) {
nonNullName
}
}
"""
)

async def get_friend_name(i):
await sleep(0)
if i < 0:
raise RuntimeError("Oops")
return friends[i].name

def get_friends(_info):
return [{"nonNullName": get_friend_name(i)} for i in (0, -1, 1)]

result = await complete(
document,
{
"friendList": get_friends,
},
)
assert result == [
{
"data": {
"friendList": [{"nonNullName": "Luke"}],
},
"hasNext": True,
},
{
"incremental": [
{
"items": [None],
"path": ["friendList", 1],
"errors": [
{
"message": "Oops",
"locations": [{"line": 4, "column": 17}],
"path": ["friendList", 1, "nonNullName"],
},
],
},
],
"hasNext": True,
},
{
"incremental": [
{
"items": [{"nonNullName": "Han"}],
"path": ["friendList", 2],
}
],
"hasNext": False,
},
]

@pytest.mark.asyncio()
async def handles_async_error_in_complete_value_after_initial_count_non_null():
document = parse(
"""
query {
Expand All @@ -1155,7 +1216,7 @@ async def get_friend(i):
return {"nonNullName": throw() if i < 0 else friends[i].name}

def get_friends(_info):
return [get_friend(0), get_friend(-1), get_friend(1)]
return [get_friend(i) for i in (0, -1, 1)]

result = await complete(
document,
Expand All @@ -1173,7 +1234,7 @@ def get_friends(_info):
{
"incremental": [
{
"items": None,
"items": [None],
"path": ["nonNullFriendList", 1],
"errors": [
{
Expand All @@ -1189,7 +1250,59 @@ def get_friends(_info):
]

@pytest.mark.asyncio()
async def handles_async_error_after_initial_count_reached_from_async_iterable():
async def handles_nested_async_error_in_complete_value_after_initial_non_null():
document = parse(
"""
query {
nonNullFriendList @stream(initialCount: 1) {
nonNullName
}
}
"""
)

async def get_friend_name(i):
await sleep(0)
if i < 0:
raise RuntimeError("Oops")
return friends[i].name

def get_friends(_info):
return [{"nonNullName": get_friend_name(i)} for i in (0, -1, 1)]

result = await complete(
document,
{
"nonNullFriendList": get_friends,
},
)
assert result == [
{
"data": {
"nonNullFriendList": [{"nonNullName": "Luke"}],
},
"hasNext": True,
},
{
"incremental": [
{
"items": None,
"path": ["nonNullFriendList", 1],
"errors": [
{
"message": "Oops",
"locations": [{"line": 4, "column": 17}],
"path": ["friendList", 1, "nonNullName"],
},
],
},
],
"hasNext": False,
},
]

@pytest.mark.asyncio()
async def handles_async_error_in_complete_value_after_initial_from_async_iterable():
document = parse(
"""
query {
Expand All @@ -1208,9 +1321,8 @@ async def get_friend(i):
return {"nonNullName": throw() if i < 0 else friends[i].name}

async def get_friends(_info):
yield await get_friend(0)
yield await get_friend(-1)
yield await get_friend(1)
for i in 0, -1, 1:
yield await get_friend(i)

result = await complete(
document,
Expand Down Expand Up @@ -1248,6 +1360,63 @@ async def get_friends(_info):
"path": ["friendList", 2],
},
],
"hasNext": True,
},
{
"hasNext": False,
},
]

@pytest.mark.asyncio()
async def handles_async_error_in_complete_value_from_async_iterable_non_null():
document = parse(
"""
query {
nonNullFriendList @stream(initialCount: 1) {
nonNullName
}
}
"""
)

async def throw():
raise RuntimeError("Oops")

async def get_friend(i):
await sleep(0)
return {"nonNullName": throw() if i < 0 else friends[i].name}

async def get_friends(_info):
for i in 0, -1, 1:
yield await get_friend(i)

result = await complete(
document,
{
"nonNullFriendList": get_friends,
},
)
assert result == [
{
"data": {
"nonNullFriendList": [{"nonNullName": "Luke"}],
},
"hasNext": True,
},
{
"incremental": [
{
"items": [None],
"path": ["nonNullFriendList", 1],
"errors": [
{
"message": "Oops",
"locations": [{"line": 4, "column": 17}],
"path": ["friendList", 1, "nonNullName"],
},
],
},
],
"hasNext": False,
},
]
Expand Down

0 comments on commit 0e6c0a3

Please sign in to comment.