Skip to content

Add pytest-benchmark and port the benchmarks from GraphQL.js #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Port building Schema from introspection benchmark
From src/utilities/__tests__/buildClientSchema-benchmark.js
  • Loading branch information
ktosiek committed Sep 8, 2019
commit ea71ad5f7fe10cc5f562d535a08a6e95a6fcf083
15 changes: 15 additions & 0 deletions tests/benchmarks/test_build_client_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from graphql import build_client_schema, GraphQLSchema

# noinspection PyUnresolvedReferences
from ..fixtures import big_schema_introspection_result # noqa: F401


def test_build_schema_from_introspection(
benchmark, big_schema_introspection_result # noqa: F811
):
schema: GraphQLSchema = benchmark(
lambda: build_client_schema(
big_schema_introspection_result["data"], assume_valid=True
)
)
assert schema.query_type is not None
19 changes: 17 additions & 2 deletions tests/fixtures/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
"""Fixtures for graphql tests"""

import json
from os.path import dirname, join

from pytest import fixture # type: ignore

__all__ = ["kitchen_sink_query", "kitchen_sink_sdl", "big_schema_sdl"]
__all__ = [
"kitchen_sink_query",
"kitchen_sink_sdl",
"big_schema_sdl",
"big_schema_introspection_result",
]


def read_graphql(name):
path = join(dirname(__file__), name + ".graphql")
return open(path, encoding="utf-8").read()


def read_json(name):
path = join(dirname(__file__), name + ".json")
return json.load(open(path, encoding="utf-8"))


@fixture(scope="module")
def kitchen_sink_query():
return read_graphql("kitchen_sink")
Expand All @@ -25,3 +35,8 @@ def kitchen_sink_sdl():
@fixture(scope="module")
def big_schema_sdl():
return read_graphql("github_schema")


@fixture(scope="module")
def big_schema_introspection_result():
return read_json("github_schema")
Loading