Fixed tests and flake errors

This commit is contained in:
Syrus Akbary 2016-08-06 19:42:06 -07:00
parent 05144487ce
commit 387b997b1d
21 changed files with 62 additions and 47 deletions

View File

@ -23,10 +23,10 @@ script:
- | - |
if [ "$TEST_TYPE" = lint ]; then if [ "$TEST_TYPE" = lint ]; then
echo "Checking Python code lint." echo "Checking Python code lint."
flake8 flake8 graphene
exit exit
elif [ "$TEST_TYPE" = build ]; then elif [ "$TEST_TYPE" = build ]; then
py.test --cov=graphene py.test --cov=graphene graphene examples
fi fi
after_success: after_success:
- | - |

View File

@ -1,4 +1,10 @@
from .definitions import GrapheneInterfaceType, GrapheneObjectType, GrapheneScalarType, GrapheneEnumType, GrapheneInputObjectType from .definitions import (
GrapheneInterfaceType,
GrapheneObjectType,
GrapheneScalarType,
GrapheneEnumType,
GrapheneInputObjectType
)
from .utils import values_from_enum from .utils import values_from_enum

View File

@ -1,4 +1,6 @@
from graphql import GraphQLObjectType, GraphQLInterfaceType, GraphQLScalarType, GraphQLEnumType, GraphQLInputObjectType from graphql import (GraphQLEnumType, GraphQLInputObjectType,
GraphQLInterfaceType, GraphQLObjectType,
GraphQLScalarType)
class GrapheneGraphQLType(object): class GrapheneGraphQLType(object):
@ -6,6 +8,7 @@ class GrapheneGraphQLType(object):
A class for extending the base GraphQLType with the related A class for extending the base GraphQLType with the related
graphene_type graphene_type
''' '''
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.graphene_type = kwargs.pop('graphene_type') self.graphene_type = kwargs.pop('graphene_type')
super(GrapheneGraphQLType, self).__init__(*args, **kwargs) super(GrapheneGraphQLType, self).__init__(*args, **kwargs)

View File

@ -1,4 +1,5 @@
from collections import OrderedDict from collections import OrderedDict
from graphql.type import GraphQLEnumValue from graphql.type import GraphQLEnumValue

View File

@ -1,7 +1,7 @@
import re
import copy import copy
import re
from collections import Iterable
from functools import partial from functools import partial
from collections import Iterable, OrderedDict
import six import six
@ -35,8 +35,8 @@ class ConnectionMeta(ObjectTypeMeta):
interfaces=[], interfaces=[],
) )
Edge = attrs.pop('Edge', None) edge_class = attrs.pop('Edge', None)
edge_fields = props(Edge) if Edge else {} edge_fields = props(edge_class) if edge_class else {}
edge_fields = get_fields(ObjectType, edge_fields, ()) edge_fields = get_fields(ObjectType, edge_fields, ())
connection_fields = copy_fields(Field, get_fields(ObjectType, attrs, bases)) connection_fields = copy_fields(Field, get_fields(ObjectType, attrs, bases))
@ -108,7 +108,8 @@ class IterableConnectionField(Field):
iterable = resolver(root, args, context, info) iterable = resolver(root, args, context, info)
# if isinstance(resolved, self.type.graphene) # if isinstance(resolved, self.type.graphene)
assert isinstance( assert isinstance(
iterable, Iterable), 'Resolved value from the connection field have to be iterable. Received "{}"'.format(iterable) iterable, Iterable), 'Resolved value from the connection field have to be iterable. Received "{}"'.format(
iterable)
connection = connection_from_list( connection = connection_from_list(
iterable, iterable,
args, args,

View File

@ -31,11 +31,11 @@ class ClientIDMutationMeta(MutationMeta):
description=None, description=None,
) )
Input = attrs.pop('Input', None) input_class = attrs.pop('Input', None)
cls = super_new(cls, name, bases, dict(attrs, _meta=options)) cls = super_new(cls, name, bases, dict(attrs, _meta=options))
input_fields = props(Input) if Input else {} input_fields = props(input_class) if input_class else {}
input_local_fields = copy_fields(InputField, get_fields(InputObjectType, input_fields, ())) input_local_fields = copy_fields(InputField, get_fields(InputObjectType, input_fields, ()))
output_fields = copy_fields(Field, get_fields(ObjectType, attrs, bases)) output_fields = copy_fields(Field, get_fields(ObjectType, attrs, bases))

View File

@ -6,11 +6,10 @@ from graphql_relay import from_global_id, node_definitions, to_global_id
from ..types.field import Field from ..types.field import Field
from ..types.interface import Interface from ..types.interface import Interface
from ..types.objecttype import ObjectType, ObjectTypeMeta, is_objecttype from ..types.objecttype import ObjectType, ObjectTypeMeta
from ..types.options import Options from ..types.options import Options
from .connection import Connection
from ..utils.copy_fields import copy_fields from ..utils.copy_fields import copy_fields
from .connection import Connection
# We inherit from ObjectTypeMeta as we want to allow # We inherit from ObjectTypeMeta as we want to allow
@ -40,7 +39,8 @@ class NodeMeta(ObjectTypeMeta):
cls = type.__new__(cls, name, bases, dict(attrs, _meta=options)) cls = type.__new__(cls, name, bases, dict(attrs, _meta=options))
get_node_from_global_id = getattr(cls, 'get_node_from_global_id', None) get_node_from_global_id = getattr(cls, 'get_node_from_global_id', None)
id_resolver = getattr(cls, 'id_resolver', None) id_resolver = getattr(cls, 'id_resolver', None)
assert get_node_from_global_id, '{}.get_node_from_global_id method is required by the Node interface.'.format(cls.__name__) assert get_node_from_global_id, '{}.get_node_from_global_id method is required by the Node interface.'.format(
cls.__name__)
node_interface, node_field = node_definitions( node_interface, node_field = node_definitions(
get_node_from_global_id, get_node_from_global_id,
id_resolver=id_resolver, id_resolver=id_resolver,

View File

@ -1,5 +1,4 @@
from .objecttype import ObjectType from .objecttype import ObjectType, Interface
from .interface import Interface
from .scalars import Scalar, String, ID, Int, Float, Boolean from .scalars import Scalar, String, ID, Int, Float, Boolean
from .schema import Schema from .schema import Schema
from .structures import List, NonNull from .structures import List, NonNull

View File

@ -41,7 +41,7 @@ class Argument(GraphQLArgument, OrderedType):
@classmethod @classmethod
def copy_from(cls, argument): def copy_from(cls, argument):
if isinstance (argument, (GraphQLArgumentDefinition, Argument)): if isinstance(argument, (GraphQLArgumentDefinition, Argument)):
name = argument.name name = argument.name
else: else:
name = None name = None

View File

@ -1,20 +1,27 @@
from __future__ import absolute_import from __future__ import absolute_import
import datetime import datetime
try:
import iso8601
except:
raise ImportError("iso8601 package is required for DateTime Scalar.\nYou can install it using: pip install iso8601.")
from graphql.language import ast from graphql.language import ast
from .scalars import Scalar from .scalars import Scalar
try:
import iso8601
except:
raise ImportError(
"iso8601 package is required for DateTime Scalar.\n"
"You can install it using: pip install iso8601."
)
class DateTime(Scalar): class DateTime(Scalar):
@staticmethod @staticmethod
def serialize(dt): def serialize(dt):
assert isinstance(dt, (datetime.datetime, datetime.date)), 'Received not compatible datetime "{}"'.format(repr(dt)) assert isinstance(dt, (datetime.datetime, datetime.date)), (
'Received not compatible datetime "{}"'.format(repr(dt))
)
return dt.isoformat() return dt.isoformat()
@staticmethod @staticmethod

View File

@ -2,6 +2,7 @@ from collections import OrderedDict
import six import six
from ..generators import generate_enum
from ..utils.is_base_type import is_base_type from ..utils.is_base_type import is_base_type
from .options import Options from .options import Options
from .unmountedtype import UnmountedType from .unmountedtype import UnmountedType
@ -11,8 +12,6 @@ try:
except ImportError: except ImportError:
from ..utils.enum import Enum as PyEnum from ..utils.enum import Enum as PyEnum
from ..generators import generate_enum
class EnumTypeMeta(type): class EnumTypeMeta(type):
@ -43,10 +42,10 @@ class EnumTypeMeta(type):
return cls return cls
def __prepare__(name, bases, **kwargs): def __prepare__(name, bases, **kwargs): # noqa: N805
return OrderedDict() return OrderedDict()
def __call__(cls, *args, **kwargs): def __call__(cls, *args, **kwargs): # noqa: N805
if cls is Enum: if cls is Enum:
description = kwargs.pop('description', None) description = kwargs.pop('description', None)
return cls.from_enum(PyEnum(*args, **kwargs), description=description) return cls.from_enum(PyEnum(*args, **kwargs), description=description)
@ -57,5 +56,5 @@ class Enum(six.with_metaclass(EnumTypeMeta, UnmountedType)):
@classmethod @classmethod
def from_enum(cls, enum, description=None): def from_enum(cls, enum, description=None):
Meta = type('Meta', (object,), {'enum': enum, 'description': description}) meta_class = type('Meta', (object,), {'enum': enum, 'description': description})
return type(Meta.enum.__name__, (Enum,), {'Meta': Meta}) return type(meta_class.enum.__name__, (Enum,), {'Meta': meta_class})

View File

@ -1,7 +1,8 @@
from collections import OrderedDict
import inspect import inspect
from collections import OrderedDict
from graphql.type import GraphQLField, GraphQLInputObjectField, GraphQLFieldDefinition from graphql.type import (GraphQLField, GraphQLFieldDefinition,
GraphQLInputObjectField)
from graphql.utils.assert_valid_name import assert_valid_name from graphql.utils.assert_valid_name import assert_valid_name
from ..utils.orderedtype import OrderedType from ..utils.orderedtype import OrderedType

View File

@ -1,5 +1,6 @@
import six import six
from ..generators import generate_inputobjecttype
from ..utils.copy_fields import copy_fields from ..utils.copy_fields import copy_fields
from ..utils.get_fields import get_fields from ..utils.get_fields import get_fields
from ..utils.is_base_type import is_base_type from ..utils.is_base_type import is_base_type
@ -9,9 +10,6 @@ from .options import Options
from .unmountedtype import UnmountedType from .unmountedtype import UnmountedType
from ..generators import generate_inputobjecttype
class InputObjectTypeMeta(type): class InputObjectTypeMeta(type):
def __new__(cls, name, bases, attrs): def __new__(cls, name, bases, attrs):

View File

@ -1 +1,3 @@
from .objecttype import Interface from .objecttype import Interface
__all__ = ['Interface']

View File

@ -1,6 +1,7 @@
from __future__ import absolute_import from __future__ import absolute_import
import json import json
from graphql.language import ast from graphql.language import ast
from .scalars import Scalar from .scalars import Scalar

View File

@ -16,10 +16,10 @@ class MutationMeta(ObjectTypeMeta):
if not is_base_type(bases, MutationMeta): if not is_base_type(bases, MutationMeta):
return type.__new__(cls, name, bases, attrs) return type.__new__(cls, name, bases, attrs)
Input = attrs.pop('Input', None) input_class = attrs.pop('Input', None)
cls = cls._create_objecttype(cls, name, bases, attrs) cls = cls._create_objecttype(cls, name, bases, attrs)
field_args = props(Input) if Input else {} field_args = props(input_class) if input_class else {}
resolver = getattr(cls, 'mutate', None) resolver = getattr(cls, 'mutate', None)
assert resolver, 'All mutations must define a mutate method in it' assert resolver, 'All mutations must define a mutate method in it'
cls.Field = partial(Field, cls, args=field_args, resolver=resolver) cls.Field = partial(Field, cls, args=field_args, resolver=resolver)

View File

@ -46,10 +46,10 @@ class ObjectTypeMeta(type):
return cls._create_objecttype(cls, name, bases, attrs) return cls._create_objecttype(cls, name, bases, attrs)
def get_interfaces(cls, bases): def get_interfaces(cls, bases): # noqa: N805
return (b for b in bases if issubclass(b, Interface)) return (b for b in bases if issubclass(b, Interface))
def is_object_type(cls): def is_object_type(cls): # noqa: N805
return issubclass(cls, ObjectType) return issubclass(cls, ObjectType)
@staticmethod @staticmethod

View File

@ -3,12 +3,11 @@ import six
from graphql import (GraphQLBoolean, GraphQLFloat, GraphQLID, GraphQLInt, from graphql import (GraphQLBoolean, GraphQLFloat, GraphQLID, GraphQLInt,
GraphQLString) GraphQLString)
from ..generators import generate_scalar
from ..utils.is_base_type import is_base_type from ..utils.is_base_type import is_base_type
from .options import Options from .options import Options
from .unmountedtype import UnmountedType from .unmountedtype import UnmountedType
from ..generators import generate_scalar
class ScalarTypeMeta(type): class ScalarTypeMeta(type):
@ -44,8 +43,8 @@ def construct_scalar_class(graphql_type):
# class String(Scalar): # class String(Scalar):
# class Meta: # class Meta:
# graphql_type = graphql_type # graphql_type = graphql_type
Meta = type('Meta', (object,), {'graphql_type': graphql_type}) meta_class = type('Meta', (object,), {'graphql_type': graphql_type})
return type(graphql_type.name, (Scalar, ), {'Meta': Meta}) return type(graphql_type.name, (Scalar, ), {'Meta': meta_class})
String = construct_scalar_class(GraphQLString) String = construct_scalar_class(GraphQLString)

View File

@ -4,9 +4,9 @@ import pytest
from graphene.utils.get_graphql_type import get_graphql_type from graphene.utils.get_graphql_type import get_graphql_type
from graphql import graphql from graphql import graphql
from graphql.type import (GraphQLBoolean, GraphQLFloat, GraphQLInt,
GraphQLScalarType, GraphQLString, GraphQLFieldDefinition)
from graphql.language import ast from graphql.language import ast
from graphql.type import (GraphQLBoolean, GraphQLFieldDefinition, GraphQLFloat,
GraphQLInt, GraphQLScalarType, GraphQLString)
from ..field import Field from ..field import Field
from ..objecttype import ObjectType from ..objecttype import ObjectType

View File

@ -8,8 +8,6 @@ def is_graphene_type(_type):
from ..types.interface import Interface from ..types.interface import Interface
from ..types.scalars import Scalar from ..types.scalars import Scalar
from ..types.enum import Enum from ..types.enum import Enum
from ..relay.mutation import ClientIDMutation
from ..relay.connection import Connection
return inspect.isclass(_type) and hasattr(_type, '_meta') and issubclass(_type, ( return inspect.isclass(_type) and hasattr(_type, '_meta') and issubclass(_type, (
Interface, Interface,

View File

@ -1,5 +1,5 @@
[flake8] [flake8]
exclude = setup.py,docs/*,*/examples/* exclude = setup.py,docs/*,*/examples/*,graphene/utils/enum.py,tests
max-line-length = 120 max-line-length = 120
[coverage:run] [coverage:run]