Skip to content

Commit 1aa975f

Browse files
committed
Merge separate tests directory for Py36 to main one
Since we require Python 3.6+ now, we can have a common test directory.
1 parent 32c76af commit 1aa975f

19 files changed

+66
-87
lines changed

MANIFEST.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ include tox.ini
1212

1313
include scripts/gql-cli
1414

15-
recursive-include tests *.py *.yaml *.graphql
16-
recursive-include tests_py36 *.py *.cnf *.pem
15+
recursive-include tests *.py *.graphql *.cnf *.yaml *.pem
1716

1817
prune gql-checker
1918

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ dev-setup:
44
python pip install -e ".[test]"
55

66
tests:
7-
pytest tests tests_py36 --cov=gql --cov-report=term-missing -vv
7+
pytest tests --cov=gql --cov-report=term-missing -vv
88

99
all_tests:
10-
pytest tests tests_py36 --cov=gql --cov-report=term-missing --run-online -vv
10+
pytest tests --cov=gql --cov-report=term-missing --run-online -vv
1111

1212
clean:
1313
find . -name "*.pyc" -delete

tests_py36/conftest.py renamed to tests/conftest.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ def pytest_addoption(parser):
2020
"--run-online",
2121
action="store_true",
2222
default=False,
23-
help="run tests necessitating online ressources",
23+
help="run tests necessitating online resources",
2424
)
2525

2626

2727
def pytest_configure(config):
2828
config.addinivalue_line(
29-
"markers", "online: mark test as necessitating external online ressources"
29+
"markers", "online: mark test as necessitating external online resources"
3030
)
3131

3232

@@ -164,8 +164,11 @@ async def wait_connection_terminate(ws):
164164

165165

166166
def get_server_handler(request):
167-
""" Get the server handler provided from test or use the default
168-
server handler if the test provides only an array of answers"""
167+
"""Get the server handler.
168+
169+
Either get it from test or use the default server handler
170+
if the test provides only an array of answers.
171+
"""
169172

170173
if isinstance(request.param, types.FunctionType):
171174
server_handler = request.param
@@ -184,8 +187,7 @@ async def default_server_handler(ws, path):
184187
print(f"Server received: {result}")
185188

186189
if isinstance(answer, str) and "{query_id}" in answer:
187-
answer_format_params = {}
188-
answer_format_params["query_id"] = query_id
190+
answer_format_params = {"query_id": query_id}
189191
formatted_answer = answer.format(**answer_format_params)
190192
else:
191193
formatted_answer = answer
@@ -206,7 +208,7 @@ async def default_server_handler(ws, path):
206208

207209
@pytest.fixture
208210
async def ws_ssl_server(request):
209-
"""websockets server fixture using ssl
211+
"""Websockets server fixture using SSL.
210212
211213
It can take as argument either a handler function for the websocket server for complete control
212214
OR an array of answers to be sent by the default server handler
@@ -229,7 +231,7 @@ async def ws_ssl_server(request):
229231

230232
@pytest.fixture
231233
async def server(request):
232-
"""server is a fixture used to start a dummy server to test the client behaviour.
234+
"""Fixture used to start a dummy server to test the client behaviour.
233235
234236
It can take as argument either a handler function for the websocket server for complete control
235237
OR an array of answers to be sent by the default server handler
@@ -252,7 +254,7 @@ async def server(request):
252254

253255
@pytest.fixture
254256
async def client_and_server(server):
255-
"""client_and_server is a helper fixture to start a server and a client connected to its port"""
257+
"""Helper fixture to start a server and a client connected to its port."""
256258

257259
# Generate transport to connect to the server fixture
258260
path = "/graphql"

tests/starwars/schema.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import asyncio
2+
13
from graphql import (
24
GraphQLArgument,
35
GraphQLEnumType,
@@ -12,6 +14,9 @@
1214
GraphQLObjectType,
1315
GraphQLSchema,
1416
GraphQLString,
17+
get_introspection_query,
18+
graphql_sync,
19+
print_schema,
1520
)
1621

1722
from .fixtures import (
@@ -21,6 +26,7 @@
2126
getFriends,
2227
getHero,
2328
getHuman,
29+
reviews,
2430
)
2531

2632
episodeEnum = GraphQLEnumType(
@@ -194,8 +200,42 @@
194200
},
195201
)
196202

203+
204+
async def subscribe_reviews(_root, _info, episode):
205+
for review in reviews[episode]:
206+
yield review
207+
await asyncio.sleep(0.1)
208+
209+
210+
async def resolve_review(review, _info, **_args):
211+
return review
212+
213+
214+
subscriptionType = GraphQLObjectType(
215+
"Subscription",
216+
fields=lambda: {
217+
"reviewAdded": GraphQLField(
218+
reviewType,
219+
args={
220+
"episode": GraphQLArgument(
221+
description="Episode to review", type_=episodeEnum,
222+
)
223+
},
224+
subscribe=subscribe_reviews,
225+
resolve=resolve_review,
226+
)
227+
},
228+
)
229+
230+
197231
StarWarsSchema = GraphQLSchema(
198232
query=queryType,
199233
mutation=mutationType,
234+
subscription=subscriptionType,
200235
types=[humanType, droidType, reviewType, reviewInputType],
201236
)
237+
238+
239+
StarWarsIntrospection = graphql_sync(StarWarsSchema, get_introspection_query()).data
240+
241+
StarWarsTypeDef = print_schema(StarWarsSchema)

tests_py36/test_query.py renamed to tests/starwars/test_subscription.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from graphql import subscribe
33

44
from gql import gql
5-
from tests.starwars.fixtures import reviews
6-
from tests_py36.schema import StarWarsSchema
5+
6+
from .fixtures import reviews
7+
from .schema import StarWarsSchema
78

89

910
@pytest.mark.asyncio

tests/starwars/test_validation.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import pytest
2-
from graphql import get_introspection_query, graphql_sync
32

43
from gql import Client, gql
54

6-
from .schema import StarWarsSchema
7-
8-
introspection = graphql_sync(StarWarsSchema, get_introspection_query()).data
5+
from .schema import StarWarsIntrospection, StarWarsSchema
96

107

118
@pytest.fixture
@@ -60,7 +57,7 @@ def typedef_schema():
6057

6158
@pytest.fixture
6259
def introspection_schema():
63-
return Client(introspection=introspection)
60+
return Client(introspection=StarWarsIntrospection)
6461

6562

6663
@pytest.fixture(params=["local_schema", "typedef_schema", "introspection_schema"])
File renamed without changes.
File renamed without changes.

tests_py36/test_async_client_validation.py renamed to tests/test_async_client_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
from gql import Client, gql
99
from gql.transport.websockets import WebsocketsTransport
10-
from tests_py36.schema import StarWarsIntrospection, StarWarsSchema, StarWarsTypeDef
1110

1211
from .conftest import MS, TestServer
12+
from .starwars.schema import StarWarsIntrospection, StarWarsSchema, StarWarsTypeDef
1313

1414
starwars_expected_one = {
1515
"stars": 3,

tests_py36/test_http_async_sync.py renamed to tests/test_http_async_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async def test_async_client_async_transport(
1919
# Get async transport
2020
sample_transport = AIOHTTPTransport(url=url)
2121

22-
# Instanciate client
22+
# Instantiate client
2323
async with Client(
2424
transport=sample_transport,
2525
fetch_schema_from_transport=fetch_schema_from_transport,

0 commit comments

Comments
 (0)