Skip to content

Commit cdb3f6f

Browse files
committed
Improved dataloader tests
1 parent c496eed commit cdb3f6f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

graphql/execution/tests/test_dataloader.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
import pytest
12
from promise import Promise
23
from promise.dataloader import DataLoader
34

45
from graphql import GraphQLObjectType, GraphQLField, GraphQLID, GraphQLArgument, GraphQLNonNull, GraphQLSchema, parse, execute
6+
from graphql.execution.executors.sync import SyncExecutor
7+
from graphql.execution.executors.thread import ThreadExecutor
58

69

7-
def test_batches_correctly():
10+
@pytest.mark.parametrize("executor", [
11+
SyncExecutor(),
12+
ThreadExecutor(),
13+
])
14+
def test_batches_correctly(executor):
815

916
Business = GraphQLObjectType('Business', lambda: {
1017
'id': GraphQLField(GraphQLID, resolver=lambda root, args, context, info: root),
@@ -46,7 +53,7 @@ class Context(object):
4653
business_data_loader = BusinessDataLoader()
4754

4855

49-
result = execute(schema, doc_ast, None, context_value=Context())
56+
result = execute(schema, doc_ast, None, context_value=Context(), executor=executor)
5057
assert not result.errors
5158
assert result.data == {
5259
'business1': {
@@ -59,7 +66,11 @@ class Context(object):
5966
assert load_calls == [['1','2']]
6067

6168

62-
def test_batches_multiple_together():
69+
@pytest.mark.parametrize("executor", [
70+
SyncExecutor(),
71+
ThreadExecutor(),
72+
])
73+
def test_batches_multiple_together(executor):
6374

6475
Location = GraphQLObjectType('Location', lambda: {
6576
'id': GraphQLField(GraphQLID, resolver=lambda root, args, context, info: root),
@@ -122,7 +133,7 @@ class Context(object):
122133
location_data_loader = LocationDataLoader()
123134

124135

125-
result = execute(schema, doc_ast, None, context_value=Context())
136+
result = execute(schema, doc_ast, None, context_value=Context(), executor=executor)
126137
assert not result.errors
127138
assert result.data == {
128139
'business1': {

0 commit comments

Comments
 (0)