Skip to content

Commit

Permalink
Fixed Python3 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Aug 14, 2016
1 parent 3516948 commit 9f1c5fa
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 31 deletions.
1 change: 0 additions & 1 deletion graphene-django/graphene_django/debug/middleware.py
Expand Up @@ -49,7 +49,6 @@ def resolve(self, next, root, args, context, info):
raise Exception('DjangoDebug need the context to be writable, context received: {}.'.format(
context.__class__.__name__
))
print info.schema.get_type('DjangoDebug'), info.return_type
if info.schema.get_type('DjangoDebug') == info.return_type:
return context.django_debug.get_debug_promise()
promise = next(root, args, context, info)
Expand Down
Expand Up @@ -4,7 +4,6 @@
import graphene
from ..form_converter import convert_form_field
from graphene import ID, List, NonNull
from graphene.utils.get_graphql_type import get_graphql_type

from .models import Reporter

Expand Down
4 changes: 2 additions & 2 deletions graphene-sqlalchemy/graphene_sqlalchemy/tests/test_schema.py
Expand Up @@ -28,7 +28,7 @@ class Meta:
model = Reporter
registry = Registry()

assert ReporterType2._meta.fields.keys() == ['id', 'first_name', 'last_name', 'email', 'pets', 'articles']
assert list(ReporterType2._meta.fields.keys()) == ['id', 'first_name', 'last_name', 'email', 'pets', 'articles']


def test_should_map_only_few_fields():
Expand All @@ -37,4 +37,4 @@ class Reporter2(SQLAlchemyObjectType):
class Meta:
model = Reporter
only_fields = ('id', 'email')
assert Reporter2._meta.fields.keys() == ['id', 'email']
assert list(Reporter2._meta.fields.keys()) == ['id', 'email']
4 changes: 2 additions & 2 deletions graphene-sqlalchemy/graphene_sqlalchemy/tests/test_types.py
Expand Up @@ -49,7 +49,7 @@ def test_sqlalchemy_interface():
def test_objecttype_registered():
assert issubclass(Character, ObjectType)
assert Character._meta.model == Reporter
assert Character._meta.fields.keys() == ['id', 'first_name', 'last_name', 'email', 'pets', 'articles']
assert list(Character._meta.fields.keys()) == ['id', 'first_name', 'last_name', 'email', 'pets', 'articles']


# def test_sqlalchemynode_idfield():
Expand All @@ -70,5 +70,5 @@ def test_node_replacedfield():

def test_object_type():
assert issubclass(Human, ObjectType)
assert Human._meta.fields.keys() == ['id', 'pub_date', 'headline', 'reporter_id', 'reporter']
assert list(Human._meta.fields.keys()) == ['id', 'pub_date', 'headline', 'reporter_id', 'reporter']
assert is_node(Human)
1 change: 1 addition & 0 deletions graphene-sqlalchemy/setup.py
Expand Up @@ -34,6 +34,7 @@
install_requires=[
'six>=1.10.0',
'graphene>=1.0',
'SQLAlchemy',
'singledispatch>=3.4.0.3',
],
tests_require=[
Expand Down
6 changes: 3 additions & 3 deletions graphene/relay/tests/test_connection.py
Expand Up @@ -34,7 +34,7 @@ class RootQuery(ObjectType):
def test_connection():
assert MyObjectConnection._meta.name == 'MyObjectConnection'
fields = MyObjectConnection._meta.fields
assert fields.keys() == ['page_info', 'edges', 'extra']
assert list(fields.keys()) == ['page_info', 'edges', 'extra']
edge_field = fields['edges']
pageinfo_field = fields['page_info']

Expand All @@ -51,7 +51,7 @@ def test_edge():
Edge = MyObjectConnection.Edge
assert Edge._meta.name == 'MyObjectEdge'
edge_fields = Edge._meta.fields
assert edge_fields.keys() == ['node', 'cursor', 'other']
assert list(edge_fields.keys()) == ['node', 'cursor', 'other']

assert isinstance(edge_fields['node'], Field)
assert edge_fields['node'].type == MyObject
Expand All @@ -63,4 +63,4 @@ def test_edge():
def test_pageinfo():
assert PageInfo._meta.name == 'PageInfo'
fields = PageInfo._meta.fields
assert fields.keys() == ['has_next_page', 'has_previous_page', 'start_cursor', 'end_cursor']
assert list(fields.keys()) == ['has_next_page', 'has_previous_page', 'start_cursor', 'end_cursor']
6 changes: 3 additions & 3 deletions graphene/relay/tests/test_mutation.py
Expand Up @@ -38,11 +38,11 @@ class MyMutation(ClientIDMutation):

def test_mutation():
fields = SaySomething._meta.fields
assert fields.keys() == ['phrase']
assert list(fields.keys()) == ['phrase']
assert isinstance(fields['phrase'], Field)
field = SaySomething.Field()
assert field.type == SaySomething
assert field.args.keys() == ['input']
assert list(field.args.keys()) == ['input']
assert isinstance(field.args['input'], Argument)
assert field.args['input'].type == SaySomething.Input

Expand All @@ -51,7 +51,7 @@ def test_mutation_input():
Input = SaySomething.Input
assert issubclass(Input, InputObjectType)
fields = Input._meta.fields
assert fields.keys() == ['what', 'client_mutation_id']
assert list(fields.keys()) == ['what', 'client_mutation_id']
assert isinstance(fields['what'], InputField)
assert fields['what'].type == String
assert isinstance(fields['client_mutation_id'], InputField)
Expand Down
2 changes: 1 addition & 1 deletion graphene/types/argument.py
Expand Up @@ -22,7 +22,7 @@ def __init__(self, type, default_value=None, description=None, name=None, requir
def to_arguments(args, extra_args):
from .unmountedtype import UnmountedType
extra_args = sorted(extra_args.items(), key=lambda f: f[1])
iter_arguments = chain(args.items() + extra_args)
iter_arguments = chain(args.items(), extra_args)
arguments = OrderedDict()
for default_name, arg in iter_arguments:
if isinstance(arg, UnmountedType):
Expand Down
2 changes: 1 addition & 1 deletion graphene/types/tests/test_abstracttype.py
Expand Up @@ -37,6 +37,6 @@ class MyAbstractType1(AbstractType):
class MyAbstractType2(MyAbstractType1):
field2 = UnmountedType(MyType)

assert MyAbstractType2._meta.fields.keys() == ['field1', 'field2']
assert list(MyAbstractType2._meta.fields.keys()) == ['field1', 'field2']
assert not hasattr(MyAbstractType1, 'field1')
assert not hasattr(MyAbstractType2, 'field2')
1 change: 0 additions & 1 deletion graphene/types/tests/test_definition.py
Expand Up @@ -137,7 +137,6 @@ class SomeSubscription(Mutation):
subscription=SomeSubscription
)

print schema.get_type_map()
assert schema.get_type_map()['NestedInputObject'].graphene_type is NestedInputObject


Expand Down
2 changes: 1 addition & 1 deletion graphene/types/tests/test_field.py
Expand Up @@ -66,7 +66,7 @@ def test_field_source_func():
def test_field_source_argument_as_kw():
MyType = object()
field = Field(MyType, b=NonNull(True), c=Argument(None), a=NonNull(False))
assert field.args.keys() == ['b', 'c', 'a']
assert list(field.args.keys()) == ['b', 'c', 'a']
assert isinstance(field.args['b'], Argument)
assert isinstance(field.args['b'].type, NonNull)
assert field.args['b'].type.of_type is True
Expand Down
4 changes: 2 additions & 2 deletions graphene/types/tests/test_inputobjecttype.py
Expand Up @@ -68,7 +68,7 @@ class MyAbstractType(AbstractType):
class MyInputObjectType(InputObjectType, MyAbstractType):
field2 = MyScalar(MyType)

assert MyInputObjectType._meta.fields.keys() == ['field1', 'field2']
assert list(MyInputObjectType._meta.fields.keys()) == ['field1', 'field2']
assert [type(x) for x in MyInputObjectType._meta.fields.values()] == [InputField, InputField]


Expand All @@ -79,5 +79,5 @@ class MyAbstractType(AbstractType):
class MyInputObjectType(MyAbstractType, InputObjectType):
field2 = MyScalar(MyType)

assert MyInputObjectType._meta.fields.keys() == ['field1', 'field2']
assert list(MyInputObjectType._meta.fields.keys()) == ['field1', 'field2']
assert [type(x) for x in MyInputObjectType._meta.fields.values()] == [InputField, InputField]
6 changes: 3 additions & 3 deletions graphene/types/tests/test_interface.py
Expand Up @@ -67,7 +67,7 @@ class MyAbstractType(AbstractType):
class MyInterface(Interface, MyAbstractType):
field2 = MyScalar()

assert MyInterface._meta.fields.keys() == ['field1', 'field2']
assert list(MyInterface._meta.fields.keys()) == ['field1', 'field2']
assert [type(x) for x in MyInterface._meta.fields.values()] == [Field, Field]


Expand All @@ -79,7 +79,7 @@ class MyInterface(MyBaseInterface):
field2 = MyScalar()

assert MyInterface._meta.name == 'MyInterface'
assert MyInterface._meta.fields.keys() == ['field1', 'field2']
assert list(MyInterface._meta.fields.keys()) == ['field1', 'field2']
assert [type(x) for x in MyInterface._meta.fields.values()] == [Field, Field]


Expand All @@ -90,5 +90,5 @@ class MyAbstractType(AbstractType):
class MyInterface(MyAbstractType, Interface):
field2 = MyScalar()

assert MyInterface._meta.fields.keys() == ['field1', 'field2']
assert list(MyInterface._meta.fields.keys()) == ['field1', 'field2']
assert [type(x) for x in MyInterface._meta.fields.values()] == [Field, Field]
8 changes: 4 additions & 4 deletions graphene/types/tests/test_objecttype.py
Expand Up @@ -79,8 +79,8 @@ class MyAbstractType(AbstractType):
class MyObjectType(ObjectType, MyAbstractType):
field2 = MyScalar()

assert MyObjectType._meta.fields.keys() == ['field1', 'field2']
assert [type(x) for x in MyObjectType._meta.fields.values()] == [Field, Field]
assert list(MyObjectType._meta.fields.keys()) == ['field1', 'field2']
assert list(map(type, MyObjectType._meta.fields.values())) == [Field, Field]


def test_generate_objecttype_inherit_abstracttype_reversed():
Expand All @@ -90,8 +90,8 @@ class MyAbstractType(AbstractType):
class MyObjectType(MyAbstractType, ObjectType):
field2 = MyScalar()

assert MyObjectType._meta.fields.keys() == ['field1', 'field2']
assert [type(x) for x in MyObjectType._meta.fields.values()] == [Field, Field]
assert list(MyObjectType._meta.fields.keys()) == ['field1', 'field2']
assert list(map(type, MyObjectType._meta.fields.values())) == [Field, Field]


def test_generate_objecttype_unmountedtype():
Expand Down
9 changes: 5 additions & 4 deletions graphene/types/tests/test_typemap.py
Expand Up @@ -57,11 +57,12 @@ def resolve_foo(self, args, info):
assert graphql_type.description == 'Description'

fields = graphql_type.get_fields()
assert fields.keys() == ['foo', 'gizmo']
assert list(fields.keys()) == ['foo', 'gizmo']
foo_field = fields['foo']
assert isinstance(foo_field, GraphQLField)
assert foo_field.description == 'Field description'
assert foo_field.resolver == MyObjectType.resolve_foo.__func__
f = MyObjectType.resolve_foo
assert foo_field.resolver == getattr(f, '__func__', f)
assert foo_field.args == {
'bar': GraphQLArgument(GraphQLString, description='Argument description', default_value='x')
}
Expand All @@ -74,9 +75,9 @@ class MyObjectType(ObjectType):

typemap = TypeMap([MyObjectType])
assert 'MyObjectType' in typemap
assert MyObjectType._meta.fields.keys() == ['bar']
assert list(MyObjectType._meta.fields.keys()) == ['bar']
graphql_type = typemap['MyObjectType']

fields = graphql_type.get_fields()
assert fields.keys() == ['bar']
assert list(fields.keys()) == ['bar']
assert fields['bar'].type == GraphQLString
7 changes: 5 additions & 2 deletions graphene/types/typemap.py
Expand Up @@ -244,8 +244,11 @@ def get_resolver_for_type(cls, type, name):
break
resolver = interface_resolver
# Only if is not decorated with classmethod
if resolver and not getattr(resolver, '__self__', True):
return resolver.__func__
if resolver:
if not getattr(resolver, '__self__', True):
return resolver.__func__
return resolver

return partial(cls.default_resolver, name)

@classmethod
Expand Down

0 comments on commit 9f1c5fa

Please sign in to comment.