Use consistent style of importing from pytest

This commit is contained in:
Christoph Zwerschke 2019-07-01 00:58:43 +02:00 committed by Mel van Londen
parent df0657b816
commit 9594bc616c
13 changed files with 37 additions and 35 deletions

View File

@ -1,4 +1,4 @@
import pytest from pytest import raises
from ...types import Argument, Field, Int, List, NonNull, ObjectType, Schema, String from ...types import Argument, Field, Int, List, NonNull, ObjectType, Schema, String
from ..connection import Connection, ConnectionField, PageInfo from ..connection import Connection, ConnectionField, PageInfo
@ -146,7 +146,7 @@ def test_connectionfield():
def test_connectionfield_node_deprecated(): def test_connectionfield_node_deprecated():
field = ConnectionField(MyObject) field = ConnectionField(MyObject)
with pytest.raises(Exception) as exc_info: with raises(Exception) as exc_info:
field.type field.type
assert "ConnectionFields now need a explicit ConnectionType for Nodes." in str( assert "ConnectionFields now need a explicit ConnectionType for Nodes." in str(

View File

@ -1,6 +1,6 @@
# https://github.com/graphql-python/graphene/issues/356 # https://github.com/graphql-python/graphene/issues/356
import pytest from pytest import raises
import graphene import graphene
from graphene import relay from graphene import relay
@ -23,7 +23,7 @@ def test_issue():
class Query(graphene.ObjectType): class Query(graphene.ObjectType):
things = relay.ConnectionField(MyUnion) things = relay.ConnectionField(MyUnion)
with pytest.raises(Exception) as exc_info: with raises(Exception) as exc_info:
graphene.Schema(query=Query) graphene.Schema(query=Query)
assert str(exc_info.value) == ( assert str(exc_info.value) == (

View File

@ -1,6 +1,6 @@
from functools import partial from functools import partial
import pytest from pytest import raises
from ..argument import Argument, to_arguments from ..argument import Argument, to_arguments
from ..field import Field from ..field import Field
@ -43,7 +43,7 @@ def test_to_arguments():
def test_to_arguments_raises_if_field(): def test_to_arguments_raises_if_field():
args = {"arg_string": Field(String)} args = {"arg_string": Field(String)}
with pytest.raises(ValueError) as exc_info: with raises(ValueError) as exc_info:
to_arguments(args) to_arguments(args)
assert str(exc_info.value) == ( assert str(exc_info.value) == (
@ -55,7 +55,7 @@ def test_to_arguments_raises_if_field():
def test_to_arguments_raises_if_inputfield(): def test_to_arguments_raises_if_inputfield():
args = {"arg_string": InputField(String)} args = {"arg_string": InputField(String)}
with pytest.raises(ValueError) as exc_info: with raises(ValueError) as exc_info:
to_arguments(args) to_arguments(args)
assert str(exc_info.value) == ( assert str(exc_info.value) == (

View File

@ -2,7 +2,8 @@ import datetime
import pytz import pytz
from graphql import GraphQLError from graphql import GraphQLError
import pytest
from pytest import fixture, mark
from ..datetime import Date, DateTime, Time from ..datetime import Date, DateTime, Time
from ..objecttype import ObjectType from ..objecttype import ObjectType
@ -27,13 +28,13 @@ class Query(ObjectType):
schema = Schema(query=Query) schema = Schema(query=Query)
@pytest.fixture @fixture
def sample_datetime(): def sample_datetime():
utc_datetime = datetime.datetime(2019, 5, 25, 5, 30, 15, 10, pytz.utc) utc_datetime = datetime.datetime(2019, 5, 25, 5, 30, 15, 10, pytz.utc)
return utc_datetime return utc_datetime
@pytest.fixture @fixture
def sample_time(sample_datetime): def sample_time(sample_datetime):
time = datetime.time( time = datetime.time(
sample_datetime.hour, sample_datetime.hour,
@ -45,7 +46,7 @@ def sample_time(sample_datetime):
return time return time
@pytest.fixture @fixture
def sample_date(sample_datetime): def sample_date(sample_datetime):
date = sample_datetime.date() date = sample_datetime.date()
return date return date
@ -170,7 +171,7 @@ def test_time_query_variable(sample_time):
assert result.data == {"time": isoformat} assert result.data == {"time": isoformat}
@pytest.mark.xfail( @mark.xfail(
reason="creating the error message fails when un-parsable object is not JSON serializable." reason="creating the error message fails when un-parsable object is not JSON serializable."
) )
def test_bad_variables(sample_date, sample_datetime, sample_time): def test_bad_variables(sample_date, sample_datetime, sample_time):

View File

@ -1,6 +1,6 @@
from functools import partial from functools import partial
import pytest from pytest import raises
from ..argument import Argument from ..argument import Argument
from ..field import Field from ..field import Field
@ -85,7 +85,7 @@ def test_field_with_string_type():
def test_field_not_source_and_resolver(): def test_field_not_source_and_resolver():
MyType = object() MyType = object()
with pytest.raises(Exception) as exc_info: with raises(Exception) as exc_info:
Field(MyType, source="value", resolver=lambda: None) Field(MyType, source="value", resolver=lambda: None)
assert ( assert (
str(exc_info.value) str(exc_info.value)

View File

@ -1,4 +1,4 @@
import pytest from pytest import raises
from ..argument import Argument from ..argument import Argument
from ..dynamic import Dynamic from ..dynamic import Dynamic
@ -39,7 +39,7 @@ def test_generate_mutation_with_meta():
def test_mutation_raises_exception_if_no_mutate(): def test_mutation_raises_exception_if_no_mutate():
with pytest.raises(AssertionError) as excinfo: with raises(AssertionError) as excinfo:
class MyMutation(Mutation): class MyMutation(Mutation):
pass pass

View File

@ -1,4 +1,4 @@
import pytest from pytest import raises
from ..field import Field from ..field import Field
from ..interface import Interface from ..interface import Interface
@ -91,7 +91,7 @@ def test_generate_objecttype_with_private_attributes():
m = MyObjectType(_private_state="custom") m = MyObjectType(_private_state="custom")
assert m._private_state == "custom" assert m._private_state == "custom"
with pytest.raises(TypeError): with raises(TypeError):
MyObjectType(_other_private_state="Wrong") MyObjectType(_other_private_state="Wrong")
@ -177,14 +177,14 @@ def test_objecttype_as_container_all_kwargs():
def test_objecttype_as_container_extra_args(): def test_objecttype_as_container_extra_args():
with pytest.raises(IndexError) as excinfo: with raises(IndexError) as excinfo:
Container("1", "2", "3") Container("1", "2", "3")
assert "Number of args exceeds number of fields" == str(excinfo.value) assert "Number of args exceeds number of fields" == str(excinfo.value)
def test_objecttype_as_container_invalid_kwargs(): def test_objecttype_as_container_invalid_kwargs():
with pytest.raises(TypeError) as excinfo: with raises(TypeError) as excinfo:
Container(unexisting_field="3") Container(unexisting_field="3")
assert "'unexisting_field' is an invalid keyword argument for Container" == str( assert "'unexisting_field' is an invalid keyword argument for Container" == str(
@ -218,7 +218,7 @@ def test_objecttype_with_possible_types():
def test_objecttype_with_possible_types_and_is_type_of_should_raise(): def test_objecttype_with_possible_types_and_is_type_of_should_raise():
with pytest.raises(AssertionError) as excinfo: with raises(AssertionError) as excinfo:
class MyObjectType(ObjectType): class MyObjectType(ObjectType):
class Meta: class Meta:

View File

@ -1,4 +1,4 @@
import pytest from pytest import raises
from graphql.pyutils import dedent from graphql.pyutils import dedent
@ -29,7 +29,7 @@ def test_schema_get_type():
def test_schema_get_type_error(): def test_schema_get_type_error():
schema = Schema(Query) schema = Schema(Query)
with pytest.raises(AttributeError) as exc_info: with raises(AttributeError) as exc_info:
schema.X schema.X
assert str(exc_info.value) == 'Type "X" not found in the Schema' assert str(exc_info.value) == 'Type "X" not found in the Schema'

View File

@ -1,6 +1,6 @@
from functools import partial from functools import partial
import pytest from pytest import raises
from ..scalars import String from ..scalars import String
from ..structures import List, NonNull from ..structures import List, NonNull
@ -14,7 +14,7 @@ def test_list():
def test_list_with_unmounted_type(): def test_list_with_unmounted_type():
with pytest.raises(Exception) as exc_info: with raises(Exception) as exc_info:
List(String()) List(String())
assert ( assert (
@ -82,7 +82,7 @@ def test_nonnull_inherited_works_list():
def test_nonnull_inherited_dont_work_nonnull(): def test_nonnull_inherited_dont_work_nonnull():
with pytest.raises(Exception) as exc_info: with raises(Exception) as exc_info:
NonNull(NonNull(String)) NonNull(NonNull(String))
assert ( assert (
@ -92,7 +92,7 @@ def test_nonnull_inherited_dont_work_nonnull():
def test_nonnull_with_unmounted_type(): def test_nonnull_with_unmounted_type():
with pytest.raises(Exception) as exc_info: with raises(Exception) as exc_info:
NonNull(String()) NonNull(String())
assert ( assert (

View File

@ -1,4 +1,5 @@
import pytest from pytest import raises
from graphql.type import ( from graphql.type import (
GraphQLArgument, GraphQLArgument,
GraphQLEnumType, GraphQLEnumType,
@ -290,7 +291,7 @@ def test_resolve_type_with_missing_type():
return MyOtherObjectType return MyOtherObjectType
type_map = create_type_map([MyObjectType]) type_map = create_type_map([MyObjectType])
with pytest.raises(AssertionError) as excinfo: with raises(AssertionError) as excinfo:
resolve_type(resolve_type_func, type_map, "MyOtherObjectType", {}, {}, None) resolve_type(resolve_type_func, type_map, "MyOtherObjectType", {}, {}, None)
assert "MyOtherObjectTyp" in str(excinfo.value) assert "MyOtherObjectTyp" in str(excinfo.value)

View File

@ -1,4 +1,4 @@
import pytest from pytest import raises
from ..field import Field from ..field import Field
from ..objecttype import ObjectType from ..objecttype import ObjectType
@ -38,7 +38,7 @@ def test_generate_union_with_meta():
def test_generate_union_with_no_types(): def test_generate_union_with_no_types():
with pytest.raises(Exception) as exc_info: with raises(Exception) as exc_info:
class MyUnion(Union): class MyUnion(Union):
pass pass

View File

@ -1,9 +1,9 @@
import pytest from pytest import mark
from ..crunch import crunch from ..crunch import crunch
@pytest.mark.parametrize( @mark.parametrize(
"description,uncrunched,crunched", "description,uncrunched,crunched",
[ [
["number primitive", 0, [0]], ["number primitive", 0, [0]],

View File

@ -1,4 +1,4 @@
import pytest from pytest import raises
from .. import deprecated from .. import deprecated
from ..deprecated import deprecated as deprecated_decorator from ..deprecated import deprecated as deprecated_decorator
@ -71,5 +71,5 @@ def test_deprecated_class_text(mocker):
def test_deprecated_other_object(mocker): def test_deprecated_other_object(mocker):
mocker.patch.object(deprecated, "warn_deprecation") mocker.patch.object(deprecated, "warn_deprecation")
with pytest.raises(TypeError): with raises(TypeError):
deprecated_decorator({}) deprecated_decorator({})