mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
Reorganize Tests (#985)
We no longer need a dedicated folder for Python3.6+ tests We no longer need to check six.PY3 in tests
This commit is contained in:
parent
923401676c
commit
5b40324e72
|
@ -1,9 +1,7 @@
|
|||
from typing import Type
|
||||
|
||||
from ..utils.subclass_with_meta import SubclassWithMeta
|
||||
from ..utils.trim_docstring import trim_docstring
|
||||
import six
|
||||
|
||||
if six.PY3:
|
||||
from typing import Type
|
||||
|
||||
|
||||
class BaseOptions(object):
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import six
|
||||
from typing import Any
|
||||
|
||||
from graphql.language.ast import BooleanValue, FloatValue, IntValue, StringValue
|
||||
|
||||
from .base import BaseOptions, BaseType
|
||||
from .unmountedtype import UnmountedType
|
||||
|
||||
if six.PY3:
|
||||
from typing import Any
|
||||
|
||||
|
||||
class ScalarOptions(BaseOptions):
|
||||
pass
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import six
|
||||
|
||||
from ..argument import Argument
|
||||
from ..enum import Enum, PyEnum
|
||||
from ..field import Field
|
||||
|
@ -115,9 +113,6 @@ def test_enum_from_builtin_enum_accepts_lambda_description():
|
|||
|
||||
|
||||
def test_enum_from_python3_enum_uses_enum_doc():
|
||||
if not six.PY3:
|
||||
return
|
||||
|
||||
from enum import Enum as PyEnum
|
||||
|
||||
class Color(PyEnum):
|
||||
|
|
|
@ -265,3 +265,17 @@ def test_abstract_objecttype_can_str():
|
|||
field = MyScalar()
|
||||
|
||||
assert str(MyObjectType) == "MyObjectType"
|
||||
|
||||
|
||||
def test_objecttype_meta_with_annotations():
|
||||
class Query(ObjectType):
|
||||
class Meta:
|
||||
name: str = "oops"
|
||||
|
||||
hello = String()
|
||||
|
||||
def resolve_hello(self, info):
|
||||
return "Hello"
|
||||
|
||||
schema = Schema(query=Query)
|
||||
assert schema is not None
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
import six
|
||||
|
||||
from ..pyutils.compat import func_name, signature
|
||||
from .deprecated import warn_deprecation
|
||||
|
||||
|
||||
def annotate(_func=None, _trigger_warning=True, **annotations):
|
||||
if not six.PY2 and _trigger_warning:
|
||||
warn_deprecation(
|
||||
"annotate is intended for use in Python 2 only, as you can use type annotations Python 3.\n"
|
||||
"Read more in https://docs.python.org/3/library/typing.html"
|
||||
)
|
||||
|
||||
if not _func:
|
||||
|
||||
def _func(f):
|
||||
return annotate(f, **annotations)
|
||||
|
||||
return _func
|
||||
|
||||
func_signature = signature(_func)
|
||||
|
||||
# We make sure the annotations are valid
|
||||
for key, value in annotations.items():
|
||||
assert key in func_signature.parameters, (
|
||||
'The key {key} is not a function parameter in the function "{func_name}".'
|
||||
).format(key=key, func_name=func_name(_func))
|
||||
|
||||
func_annotations = getattr(_func, "__annotations__", None)
|
||||
if func_annotations is None:
|
||||
_func.__annotations__ = annotations
|
||||
else:
|
||||
_func.__annotations__.update(annotations)
|
||||
|
||||
return _func
|
|
@ -1,37 +0,0 @@
|
|||
import pytest
|
||||
|
||||
from ..annotate import annotate
|
||||
|
||||
|
||||
def func(a, b, *c, **d):
|
||||
pass
|
||||
|
||||
|
||||
annotations = {"a": int, "b": str, "c": list, "d": dict}
|
||||
|
||||
|
||||
def func_with_annotations(a, b, *c, **d):
|
||||
pass
|
||||
|
||||
|
||||
func_with_annotations.__annotations__ = annotations
|
||||
|
||||
|
||||
def test_annotate_with_no_params():
|
||||
annotated_func = annotate(func, _trigger_warning=False)
|
||||
assert annotated_func.__annotations__ == {}
|
||||
|
||||
|
||||
def test_annotate_with_params():
|
||||
annotated_func = annotate(_trigger_warning=False, **annotations)(func)
|
||||
assert annotated_func.__annotations__ == annotations
|
||||
|
||||
|
||||
def test_annotate_with_wront_params():
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
annotate(p=int, _trigger_warning=False)(func)
|
||||
|
||||
assert (
|
||||
str(exc_info.value)
|
||||
== 'The key p is not a function parameter in the function "func".'
|
||||
)
|
|
@ -1,15 +0,0 @@
|
|||
from graphene import Schema, ObjectType, String
|
||||
|
||||
|
||||
def test_objecttype_meta_with_annotations():
|
||||
class Query(ObjectType):
|
||||
class Meta:
|
||||
name: str = "oops"
|
||||
|
||||
hello = String()
|
||||
|
||||
def resolve_hello(self, info):
|
||||
return "Hello"
|
||||
|
||||
schema = Schema(query=Query)
|
||||
assert schema is not None
|
Loading…
Reference in New Issue
Block a user