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:
Eran Kampf 2019-06-01 18:43:44 -07:00 committed by GitHub
parent 923401676c
commit 5b40324e72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 19 additions and 100 deletions

View File

@ -1,9 +1,7 @@
from typing import Type
from ..utils.subclass_with_meta import SubclassWithMeta from ..utils.subclass_with_meta import SubclassWithMeta
from ..utils.trim_docstring import trim_docstring from ..utils.trim_docstring import trim_docstring
import six
if six.PY3:
from typing import Type
class BaseOptions(object): class BaseOptions(object):

View File

@ -1,12 +1,11 @@
import six import six
from typing import Any
from graphql.language.ast import BooleanValue, FloatValue, IntValue, StringValue from graphql.language.ast import BooleanValue, FloatValue, IntValue, StringValue
from .base import BaseOptions, BaseType from .base import BaseOptions, BaseType
from .unmountedtype import UnmountedType from .unmountedtype import UnmountedType
if six.PY3:
from typing import Any
class ScalarOptions(BaseOptions): class ScalarOptions(BaseOptions):
pass pass

View File

@ -1,5 +1,3 @@
import six
from ..argument import Argument from ..argument import Argument
from ..enum import Enum, PyEnum from ..enum import Enum, PyEnum
from ..field import Field 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(): def test_enum_from_python3_enum_uses_enum_doc():
if not six.PY3:
return
from enum import Enum as PyEnum from enum import Enum as PyEnum
class Color(PyEnum): class Color(PyEnum):

View File

@ -265,3 +265,17 @@ def test_abstract_objecttype_can_str():
field = MyScalar() field = MyScalar()
assert str(MyObjectType) == "MyObjectType" 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

View File

@ -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

View File

@ -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".'
)

View File

@ -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

View File

@ -9,7 +9,7 @@ deps =
setenv = setenv =
PYTHONPATH = .:{envdir} PYTHONPATH = .:{envdir}
commands = commands =
py{36,37}: py.test --cov=graphene graphene examples tests_asyncio tests_py36 {posargs} py{36,37}: py.test --cov=graphene graphene examples tests_asyncio {posargs}
[testenv:pre-commit] [testenv:pre-commit]
basepython=python3.6 basepython=python3.6