Skip to content

add setup.py test command #87

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 3 commits into from
Oct 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ before_install:
source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate"
fi
install:
- pip install pytest-cov pytest-mock coveralls flake8 isort==3.9.6 gevent==1.1b5 six>=1.10.0 promise>=0.4.2 pytest-benchmark
- pip install pytest-cov pytest-mock coveralls flake8 gevent==1.1b5 six>=1.10.0 promise>=0.4.2 pytest-benchmark
- pip install pytest==2.9.2
- pip install -e .
script:
Expand All @@ -36,5 +36,4 @@ matrix:
- pip install pytest-asyncio
script:
- flake8
- isort --check-only graphql/ -rc
- py.test --cov=graphql graphql tests tests_py35
166 changes: 115 additions & 51 deletions graphql/execution/tests/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,48 @@
GraphQLSchema, Source, execute, parse)


def test_big_list_of_ints(benchmark):
big_int_list = [x for x in range(5000)]
# set global fixtures
Container = namedtuple('Container', 'x y z o')
big_int_list = [x for x in range(5000)]
big_container_list = [Container(x=x, y=x, z=x, o=x) for x in range(5000)]

ContainerType = GraphQLObjectType('Container',
fields={
'x': GraphQLField(GraphQLInt),
'y': GraphQLField(GraphQLInt),
'z': GraphQLField(GraphQLInt),
'o': GraphQLField(GraphQLInt),
})


def resolve_all_containers(root, args, context, info):
return big_container_list

def resolve_all_ints(root, args, context, info):
return big_int_list

def resolve_all_ints(root, args, context, info):
return big_int_list


def test_big_list_of_ints_to_graphql_schema(benchmark):
@benchmark
def schema():
Query = GraphQLObjectType('Query', fields={
'allInts': GraphQLField(
GraphQLList(GraphQLInt),
resolver=resolve_all_ints
)
})
return GraphQLSchema(Query)


def test_big_list_of_ints_to_graphql_ast(benchmark):
@benchmark
def ast():
source = Source('{ allInts }')
return parse(source)


def test_big_list_of_ints_to_graphql_partial(benchmark):
Query = GraphQLObjectType('Query', fields={
'allInts': GraphQLField(
GraphQLList(GraphQLInt),
Expand All @@ -20,43 +56,55 @@ def resolve_all_ints(root, args, context, info):
hello_schema = GraphQLSchema(Query)
source = Source('{ allInts }')
ast = parse(source)
big_list_query = partial(execute, hello_schema, ast)
result = benchmark(big_list_query)
# result = big_list_query()
assert not result.errors
assert result.data == {'allInts': big_int_list}

@benchmark
def b():
return partial(execute, hello_schema, ast)

def test_big_list_of_ints_to_graphql_total(benchmark):
@benchmark
def total():
Query = GraphQLObjectType('Query', fields={
'allInts': GraphQLField(
GraphQLList(GraphQLInt),
resolver=resolve_all_ints
)
})
hello_schema = GraphQLSchema(Query)
source = Source('{ allInts }')
ast = parse(source)
return partial(execute, hello_schema, ast)


def test_big_list_of_ints_base(benchmark):
big_int_list = [x for x in range(5000)]
def test_big_list_of_ints_base_serialize(benchmark):
from ..executor import complete_leaf_value
# def convert_item(i):
# return i

def convert_list():
r = []
@benchmark
def serialize():
for i in big_int_list:
r.append(GraphQLInt.serialize(i))
return r
benchmark(convert_list)
GraphQLInt.serialize(i)


def test_big_list_of_containers_with_one_field(benchmark):
Container = namedtuple('Container', 'x y z o')
def test_total_big_list_of_containers_with_one_field_schema(benchmark):
@benchmark
def schema():
Query = GraphQLObjectType('Query', fields={
'allContainers': GraphQLField(
GraphQLList(ContainerType),
resolver=resolve_all_containers
)
})
return GraphQLSchema(Query)

ContainerType = GraphQLObjectType('Container', fields={
'x': GraphQLField(GraphQLInt),
'y': GraphQLField(GraphQLInt),
'z': GraphQLField(GraphQLInt),
'o': GraphQLField(GraphQLInt),
})

big_container_list = [Container(x=x, y=x, z=x, o=x) for x in range(5000)]
def test_total_big_list_of_containers_with_one_field_parse(benchmark):
@benchmark
def ast():
source = Source('{ allContainers { x } }')
ast = parse(source)

def resolve_all_containers(root, args, context, info):
return big_container_list

def test_total_big_list_of_containers_with_one_field_partial(benchmark):
Query = GraphQLObjectType('Query', fields={
'allContainers': GraphQLField(
GraphQLList(ContainerType),
Expand All @@ -66,39 +114,55 @@ def resolve_all_containers(root, args, context, info):
hello_schema = GraphQLSchema(Query)
source = Source('{ allContainers { x } }')
ast = parse(source)
big_list_query = partial(execute, hello_schema, ast)
result = benchmark(big_list_query)
# result = big_list_query()
assert not result.errors
assert result.data == {'allContainers': [{'x': c.x} for c in big_container_list]}

@benchmark
def b():
return partial(execute, hello_schema, ast)

def test_big_list_of_containers_with_multiple_fields(benchmark):
Container = namedtuple('Container', 'x y z o')

ContainerType = GraphQLObjectType('Container', fields={
'x': GraphQLField(GraphQLInt),
'y': GraphQLField(GraphQLInt),
'z': GraphQLField(GraphQLInt),
'o': GraphQLField(GraphQLInt),
})
def test_total_big_list_of_containers_with_one_field_total(benchmark):
@benchmark
def total():
Query = GraphQLObjectType('Query', fields={
'allContainers': GraphQLField(
GraphQLList(ContainerType),
resolver=resolve_all_containers
)
})
hello_schema = GraphQLSchema(Query)
source = Source('{ allContainers { x } }')
ast = parse(source)
result = partial(execute, hello_schema, ast)

big_container_list = [Container(x=x, y=x, z=x, o=x) for x in range(5000)]

def resolve_all_containers(root, args, context, info):
return big_container_list

def test_total_big_list_of_containers_with_multiple_fields_partial(benchmark):
Query = GraphQLObjectType('Query', fields={
'allContainers': GraphQLField(
GraphQLList(ContainerType),
resolver=resolve_all_containers
)
})

hello_schema = GraphQLSchema(Query)
source = Source('{ allContainers { x, y, z } }')
ast = parse(source)
big_list_query = partial(execute, hello_schema, ast)
result = benchmark(big_list_query)
# result = big_list_query()
assert not result.errors
assert result.data == {'allContainers': [{'x': c.x, 'y': c.y, 'z': c.z} for c in big_container_list]}

@benchmark
def b():
return partial(execute, hello_schema, ast)


def test_total_big_list_of_containers_with_multiple_fields(benchmark):
@benchmark
def total():
Query = GraphQLObjectType('Query', fields={
'allContainers': GraphQLField(
GraphQLList(ContainerType),
resolver=resolve_all_containers
)
})

hello_schema = GraphQLSchema(Query)
source = Source('{ allContainers { x, y, z } }')
ast = parse(source)
result = partial(execute, hello_schema, ast)
47 changes: 34 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand
import sys

if sys.version_info[0] < 3:
Expand All @@ -12,10 +13,39 @@
# the numpy distutils extensions that are used by scikit-learn to recursively
# build the compiled extensions in sub-packages is based on the Python import
# machinery.
builtins.__GRAPHQL_SETUP__ = True
if 'test' not in sys.argv:
builtins.__GRAPHQL_SETUP__ = True

version = __import__('graphql').get_version()

install_requires = [
'six>=1.10.0',
'promise>=0.4.2'
]

tests_requires = [
'pytest==3.0.2',
'pytest-django==2.9.1',
'pytest-cov==2.3.1',
'gevent==1.1rc1',
'six>=1.10.0',
'pytest-benchmark==3.0.0',
'pytest-mock==1.2',
]

class PyTest(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = ['graphql', '-vrsx']
self.test_suite = True

def run_tests(self):
#import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.test_args)
sys.exit(errno)


setup(
name='graphql-core',
version=version,
Expand Down Expand Up @@ -43,18 +73,9 @@

keywords='api graphql protocol rest',
packages=find_packages(exclude=['tests', 'tests_py35']),
install_requires=[
'six>=1.10.0',
'promise>=0.4.2'
],
tests_require=[
'pytest==2.9.2',
'pytest-benchmark',
'pytest-cov',
'gevent==1.1rc1',
'six>=1.10.0',
'pytest-mock'
],
install_requires=install_requires,
tests_require=tests_requires,
cmdclass = {'test': PyTest},
extras_require={
'gevent': [
'gevent==1.1rc1'
Expand Down