From 5b40324e72ce89fd5f3fe814f45cf71c910ee697 Mon Sep 17 00:00:00 2001 From: Eran Kampf <205185+ekampf@users.noreply.github.com> Date: Sat, 1 Jun 2019 18:43:44 -0700 Subject: [PATCH] Reorganize Tests (#985) We no longer need a dedicated folder for Python3.6+ tests We no longer need to check six.PY3 in tests --- graphene/types/base.py | 6 ++-- graphene/types/scalars.py | 5 ++-- graphene/types/tests/test_enum.py | 5 ---- graphene/types/tests/test_objecttype.py | 14 ++++++++++ graphene/utils/annotate.py | 35 ----------------------- graphene/utils/tests/test_annotate.py | 37 ------------------------- tests_py36/test_objecttype.py | 15 ---------- tox.ini | 2 +- 8 files changed, 19 insertions(+), 100 deletions(-) delete mode 100644 graphene/utils/annotate.py delete mode 100644 graphene/utils/tests/test_annotate.py delete mode 100644 tests_py36/test_objecttype.py diff --git a/graphene/types/base.py b/graphene/types/base.py index f43feb47..bab78a49 100644 --- a/graphene/types/base.py +++ b/graphene/types/base.py @@ -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): diff --git a/graphene/types/scalars.py b/graphene/types/scalars.py index c5f43787..a5596d28 100644 --- a/graphene/types/scalars.py +++ b/graphene/types/scalars.py @@ -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 diff --git a/graphene/types/tests/test_enum.py b/graphene/types/tests/test_enum.py index 6086f54c..e0937992 100644 --- a/graphene/types/tests/test_enum.py +++ b/graphene/types/tests/test_enum.py @@ -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): diff --git a/graphene/types/tests/test_objecttype.py b/graphene/types/tests/test_objecttype.py index 2acb578f..68b8dd8a 100644 --- a/graphene/types/tests/test_objecttype.py +++ b/graphene/types/tests/test_objecttype.py @@ -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 diff --git a/graphene/utils/annotate.py b/graphene/utils/annotate.py deleted file mode 100644 index 43a26ef6..00000000 --- a/graphene/utils/annotate.py +++ /dev/null @@ -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 diff --git a/graphene/utils/tests/test_annotate.py b/graphene/utils/tests/test_annotate.py deleted file mode 100644 index 1b7b4ce1..00000000 --- a/graphene/utils/tests/test_annotate.py +++ /dev/null @@ -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".' - ) diff --git a/tests_py36/test_objecttype.py b/tests_py36/test_objecttype.py deleted file mode 100644 index bce38d94..00000000 --- a/tests_py36/test_objecttype.py +++ /dev/null @@ -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 diff --git a/tox.ini b/tox.ini index 6c672705..6581d340 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,7 @@ deps = setenv = PYTHONPATH = .:{envdir} 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] basepython=python3.6