From 387b997b1d12de2a6dd01381ff988b3b0bde6004 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sat, 6 Aug 2016 19:42:06 -0700 Subject: [PATCH] Fixed tests and flake errors --- .travis.yml | 4 ++-- graphene/generators/__init__.py | 8 +++++++- graphene/generators/definitions.py | 5 ++++- graphene/generators/utils.py | 1 + graphene/relay/connection.py | 11 ++++++----- graphene/relay/mutation.py | 4 ++-- graphene/relay/node.py | 8 ++++---- graphene/types/__init__.py | 3 +-- graphene/types/argument.py | 2 +- graphene/types/datetime.py | 17 ++++++++++++----- graphene/types/enum.py | 11 +++++------ graphene/types/field.py | 5 +++-- graphene/types/inputobjecttype.py | 4 +--- graphene/types/interface.py | 2 ++ graphene/types/json.py | 1 + graphene/types/mutation.py | 4 ++-- graphene/types/objecttype.py | 4 ++-- graphene/types/scalars.py | 7 +++---- graphene/types/tests/test_scalars.py | 4 ++-- graphene/utils/is_graphene_type.py | 2 -- setup.cfg | 2 +- 21 files changed, 62 insertions(+), 47 deletions(-) diff --git a/.travis.yml b/.travis.yml index 897bb736..d83f3d92 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,10 +23,10 @@ script: - | if [ "$TEST_TYPE" = lint ]; then echo "Checking Python code lint." - flake8 + flake8 graphene exit elif [ "$TEST_TYPE" = build ]; then - py.test --cov=graphene + py.test --cov=graphene graphene examples fi after_success: - | diff --git a/graphene/generators/__init__.py b/graphene/generators/__init__.py index 1f46ebc6..497dddde 100644 --- a/graphene/generators/__init__.py +++ b/graphene/generators/__init__.py @@ -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 diff --git a/graphene/generators/definitions.py b/graphene/generators/definitions.py index 70eba044..68251acb 100644 --- a/graphene/generators/definitions.py +++ b/graphene/generators/definitions.py @@ -1,4 +1,6 @@ -from graphql import GraphQLObjectType, GraphQLInterfaceType, GraphQLScalarType, GraphQLEnumType, GraphQLInputObjectType +from graphql import (GraphQLEnumType, GraphQLInputObjectType, + GraphQLInterfaceType, GraphQLObjectType, + GraphQLScalarType) class GrapheneGraphQLType(object): @@ -6,6 +8,7 @@ class GrapheneGraphQLType(object): A class for extending the base GraphQLType with the related graphene_type ''' + def __init__(self, *args, **kwargs): self.graphene_type = kwargs.pop('graphene_type') super(GrapheneGraphQLType, self).__init__(*args, **kwargs) diff --git a/graphene/generators/utils.py b/graphene/generators/utils.py index 43fc79e5..96eb9016 100644 --- a/graphene/generators/utils.py +++ b/graphene/generators/utils.py @@ -1,4 +1,5 @@ from collections import OrderedDict + from graphql.type import GraphQLEnumValue diff --git a/graphene/relay/connection.py b/graphene/relay/connection.py index 802ee5f0..d29e9b2a 100644 --- a/graphene/relay/connection.py +++ b/graphene/relay/connection.py @@ -1,7 +1,7 @@ -import re import copy +import re +from collections import Iterable from functools import partial -from collections import Iterable, OrderedDict import six @@ -35,8 +35,8 @@ class ConnectionMeta(ObjectTypeMeta): interfaces=[], ) - Edge = attrs.pop('Edge', None) - edge_fields = props(Edge) if Edge else {} + edge_class = attrs.pop('Edge', None) + edge_fields = props(edge_class) if edge_class else {} edge_fields = get_fields(ObjectType, edge_fields, ()) connection_fields = copy_fields(Field, get_fields(ObjectType, attrs, bases)) @@ -108,7 +108,8 @@ class IterableConnectionField(Field): iterable = resolver(root, args, context, info) # if isinstance(resolved, self.type.graphene) 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( iterable, args, diff --git a/graphene/relay/mutation.py b/graphene/relay/mutation.py index 60b84c17..f619a658 100644 --- a/graphene/relay/mutation.py +++ b/graphene/relay/mutation.py @@ -31,11 +31,11 @@ class ClientIDMutationMeta(MutationMeta): description=None, ) - Input = attrs.pop('Input', None) + input_class = attrs.pop('Input', None) 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, ())) output_fields = copy_fields(Field, get_fields(ObjectType, attrs, bases)) diff --git a/graphene/relay/node.py b/graphene/relay/node.py index 99121232..fbccfd4b 100644 --- a/graphene/relay/node.py +++ b/graphene/relay/node.py @@ -6,11 +6,10 @@ from graphql_relay import from_global_id, node_definitions, to_global_id from ..types.field import Field 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 .connection import Connection - from ..utils.copy_fields import copy_fields +from .connection import Connection # 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)) get_node_from_global_id = getattr(cls, 'get_node_from_global_id', 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( get_node_from_global_id, id_resolver=id_resolver, diff --git a/graphene/types/__init__.py b/graphene/types/__init__.py index d226b3e5..e43ad73a 100644 --- a/graphene/types/__init__.py +++ b/graphene/types/__init__.py @@ -1,5 +1,4 @@ -from .objecttype import ObjectType -from .interface import Interface +from .objecttype import ObjectType, Interface from .scalars import Scalar, String, ID, Int, Float, Boolean from .schema import Schema from .structures import List, NonNull diff --git a/graphene/types/argument.py b/graphene/types/argument.py index ad4b20a4..fa816a5f 100644 --- a/graphene/types/argument.py +++ b/graphene/types/argument.py @@ -41,7 +41,7 @@ class Argument(GraphQLArgument, OrderedType): @classmethod def copy_from(cls, argument): - if isinstance (argument, (GraphQLArgumentDefinition, Argument)): + if isinstance(argument, (GraphQLArgumentDefinition, Argument)): name = argument.name else: name = None diff --git a/graphene/types/datetime.py b/graphene/types/datetime.py index d2dd27bf..bdf5870e 100644 --- a/graphene/types/datetime.py +++ b/graphene/types/datetime.py @@ -1,20 +1,27 @@ from __future__ import absolute_import 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 .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): @staticmethod 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() @staticmethod diff --git a/graphene/types/enum.py b/graphene/types/enum.py index c1d382ba..0f8ba122 100644 --- a/graphene/types/enum.py +++ b/graphene/types/enum.py @@ -2,6 +2,7 @@ from collections import OrderedDict import six +from ..generators import generate_enum from ..utils.is_base_type import is_base_type from .options import Options from .unmountedtype import UnmountedType @@ -11,8 +12,6 @@ try: except ImportError: from ..utils.enum import Enum as PyEnum -from ..generators import generate_enum - class EnumTypeMeta(type): @@ -43,10 +42,10 @@ class EnumTypeMeta(type): return cls - def __prepare__(name, bases, **kwargs): + def __prepare__(name, bases, **kwargs): # noqa: N805 return OrderedDict() - def __call__(cls, *args, **kwargs): + def __call__(cls, *args, **kwargs): # noqa: N805 if cls is Enum: description = kwargs.pop('description', None) return cls.from_enum(PyEnum(*args, **kwargs), description=description) @@ -57,5 +56,5 @@ class Enum(six.with_metaclass(EnumTypeMeta, UnmountedType)): @classmethod def from_enum(cls, enum, description=None): - Meta = type('Meta', (object,), {'enum': enum, 'description': description}) - return type(Meta.enum.__name__, (Enum,), {'Meta': Meta}) + meta_class = type('Meta', (object,), {'enum': enum, 'description': description}) + return type(meta_class.enum.__name__, (Enum,), {'Meta': meta_class}) diff --git a/graphene/types/field.py b/graphene/types/field.py index f5316896..2f687381 100644 --- a/graphene/types/field.py +++ b/graphene/types/field.py @@ -1,7 +1,8 @@ -from collections import OrderedDict 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 ..utils.orderedtype import OrderedType diff --git a/graphene/types/inputobjecttype.py b/graphene/types/inputobjecttype.py index 40549994..46a1ffdd 100644 --- a/graphene/types/inputobjecttype.py +++ b/graphene/types/inputobjecttype.py @@ -1,5 +1,6 @@ import six +from ..generators import generate_inputobjecttype from ..utils.copy_fields import copy_fields from ..utils.get_fields import get_fields from ..utils.is_base_type import is_base_type @@ -9,9 +10,6 @@ from .options import Options from .unmountedtype import UnmountedType -from ..generators import generate_inputobjecttype - - class InputObjectTypeMeta(type): def __new__(cls, name, bases, attrs): diff --git a/graphene/types/interface.py b/graphene/types/interface.py index fac33216..56fc0ebb 100644 --- a/graphene/types/interface.py +++ b/graphene/types/interface.py @@ -1 +1,3 @@ from .objecttype import Interface + +__all__ = ['Interface'] diff --git a/graphene/types/json.py b/graphene/types/json.py index 42393957..f4bc632b 100644 --- a/graphene/types/json.py +++ b/graphene/types/json.py @@ -1,6 +1,7 @@ from __future__ import absolute_import import json + from graphql.language import ast from .scalars import Scalar diff --git a/graphene/types/mutation.py b/graphene/types/mutation.py index 6874ae3d..018f8ef9 100644 --- a/graphene/types/mutation.py +++ b/graphene/types/mutation.py @@ -16,10 +16,10 @@ class MutationMeta(ObjectTypeMeta): if not is_base_type(bases, MutationMeta): 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) - field_args = props(Input) if Input else {} + field_args = props(input_class) if input_class else {} resolver = getattr(cls, 'mutate', None) assert resolver, 'All mutations must define a mutate method in it' cls.Field = partial(Field, cls, args=field_args, resolver=resolver) diff --git a/graphene/types/objecttype.py b/graphene/types/objecttype.py index cb073e8e..c2825b70 100644 --- a/graphene/types/objecttype.py +++ b/graphene/types/objecttype.py @@ -46,10 +46,10 @@ class ObjectTypeMeta(type): 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)) - def is_object_type(cls): + def is_object_type(cls): # noqa: N805 return issubclass(cls, ObjectType) @staticmethod diff --git a/graphene/types/scalars.py b/graphene/types/scalars.py index 9d82654a..d6966e19 100644 --- a/graphene/types/scalars.py +++ b/graphene/types/scalars.py @@ -3,12 +3,11 @@ import six from graphql import (GraphQLBoolean, GraphQLFloat, GraphQLID, GraphQLInt, GraphQLString) +from ..generators import generate_scalar from ..utils.is_base_type import is_base_type from .options import Options from .unmountedtype import UnmountedType -from ..generators import generate_scalar - class ScalarTypeMeta(type): @@ -44,8 +43,8 @@ def construct_scalar_class(graphql_type): # class String(Scalar): # class Meta: # graphql_type = graphql_type - Meta = type('Meta', (object,), {'graphql_type': graphql_type}) - return type(graphql_type.name, (Scalar, ), {'Meta': Meta}) + meta_class = type('Meta', (object,), {'graphql_type': graphql_type}) + return type(graphql_type.name, (Scalar, ), {'Meta': meta_class}) String = construct_scalar_class(GraphQLString) diff --git a/graphene/types/tests/test_scalars.py b/graphene/types/tests/test_scalars.py index c79b6910..8a2b7b12 100644 --- a/graphene/types/tests/test_scalars.py +++ b/graphene/types/tests/test_scalars.py @@ -4,9 +4,9 @@ import pytest from graphene.utils.get_graphql_type import get_graphql_type from graphql import graphql -from graphql.type import (GraphQLBoolean, GraphQLFloat, GraphQLInt, - GraphQLScalarType, GraphQLString, GraphQLFieldDefinition) from graphql.language import ast +from graphql.type import (GraphQLBoolean, GraphQLFieldDefinition, GraphQLFloat, + GraphQLInt, GraphQLScalarType, GraphQLString) from ..field import Field from ..objecttype import ObjectType diff --git a/graphene/utils/is_graphene_type.py b/graphene/utils/is_graphene_type.py index 384f1b6c..013d9d2d 100644 --- a/graphene/utils/is_graphene_type.py +++ b/graphene/utils/is_graphene_type.py @@ -8,8 +8,6 @@ def is_graphene_type(_type): from ..types.interface import Interface from ..types.scalars import Scalar 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, ( Interface, diff --git a/setup.cfg b/setup.cfg index 89077559..a6669b9e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [flake8] -exclude = setup.py,docs/*,*/examples/* +exclude = setup.py,docs/*,*/examples/*,graphene/utils/enum.py,tests max-line-length = 120 [coverage:run]