reverting failing tests

This commit is contained in:
Kacppian 2018-07-17 22:58:06 +05:30
parent b09e4cb6de
commit d4498c3232
18 changed files with 155 additions and 197 deletions

View File

@ -3,7 +3,10 @@ from __future__ import unicode_literals
import datetime import datetime
import os import os
import subprocess import subprocess
<<<<<<< HEAD
from .comparison_helper import raise_assertion_if from .comparison_helper import raise_assertion_if
=======
>>>>>>> parent of 41dcbdc... DRY-ed up
def get_version(version=None): def get_version(version=None):
@ -45,14 +48,11 @@ def get_complete_version(version=None):
if version is None: if version is None:
from graphene import VERSION as version from graphene import VERSION as version
else: else:
raise_assertion_if( if len(version) is not 5:
condition=len(version) is not 5, raise AssertionError("Version needs to be 5")
message="Version needs to be 5" if version[3] not in ("alpha", "beta", "rc", "final"):
) raise AssertionError("Release version is unkown")
raise_assertion_if(
condition=version[3] not in ("alpha", "beta", "rc", "final"),
message="Release version is unkown"
)
return version return version

View File

@ -9,7 +9,6 @@ from ..types import Boolean, Enum, Int, Interface, List, NonNull, Scalar, String
from ..types.field import Field from ..types.field import Field
from ..types.objecttype import ObjectType, ObjectTypeOptions from ..types.objecttype import ObjectType, ObjectTypeOptions
from .node import is_node from .node import is_node
from ..utils.comparison_helper import raise_assertion_if
class PageInfo(ObjectType): class PageInfo(ObjectType):
@ -47,20 +46,16 @@ class Connection(ObjectType):
@classmethod @classmethod
def __init_subclass_with_meta__(cls, node=None, name=None, **options): def __init_subclass_with_meta__(cls, node=None, name=None, **options):
_meta = ConnectionOptions(cls) _meta = ConnectionOptions(cls)
if not node:
error_message = "You have to provide a node in {}.Meta".format(cls.__name__) raise AssertionError(
raise_assertion_if( "You have to provide a node in {}.Meta".format(cls.__name__)
condition=not node,
message=error_message
) )
error_message = 'Received incompatible node "{}" for Connection {}.'.format( if not issubclass(node, (Scalar, Enum, ObjectType, Interface, Union, NonNull)):
node, cls.__name__ raise AssertionError(
) 'Received incompatible node "{}" for Connection {}.'.format(
condition = not issubclass(node, (Scalar, Enum, ObjectType, Interface, Union, NonNull)) node, cls.__name__
raise_assertion_if( )
condition=condition,
message=error_message
) )
base_name = re.sub("Connection$", "", name or cls.__name__) or node._meta.name base_name = re.sub("Connection$", "", name or cls.__name__) or node._meta.name
@ -117,11 +112,11 @@ class IterableConnectionField(Field):
"Read more: https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#node-connections" "Read more: https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#node-connections"
) )
error_message = '{} type have to be a subclass of Connection. Received "{}".' if not issubclass(connection_type, Connection):
.format(self.__class__.__name__, connection_type) raise AssertionError(
raise_assertion_if( '{} type have to be a subclass of Connection. Received "{}".'.format(
condition= not issubclass(connection_type, Connection), self.__class__.__name__, connection_type
message=error_message )
) )
return type return type

View File

@ -5,7 +5,6 @@ from promise import Promise, is_thenable
from ..types import Field, InputObjectType, String from ..types import Field, InputObjectType, String
from ..types.mutation import Mutation from ..types.mutation import Mutation
from ..utils.comparison_helper import raise_assertion_if
class ClientIDMutation(Mutation): class ClientIDMutation(Mutation):
@ -19,7 +18,8 @@ class ClientIDMutation(Mutation):
input_class = getattr(cls, "Input", None) input_class = getattr(cls, "Input", None)
base_name = re.sub("Payload$", "", name or cls.__name__) base_name = re.sub("Payload$", "", name or cls.__name__)
raise_assertion_if(condition=output, message="Can't specify any output") if output:
raise AssertionError("Can't specify any output")
if arguments: if arguments:
raise AssertionError("Can't specify any arguments") raise AssertionError("Can't specify any arguments")

View File

@ -7,9 +7,6 @@ from graphql_relay import from_global_id, to_global_id
from ..types import ID, Field, Interface, ObjectType from ..types import ID, Field, Interface, ObjectType
from ..types.interface import InterfaceOptions from ..types.interface import InterfaceOptions
from ..types.utils import get_type from ..types.utils import get_type
from ..utils.comparison_helper import raise_assertion_if
def is_node(objecttype): def is_node(objecttype):
@ -52,10 +49,8 @@ class GlobalID(Field):
class NodeField(Field): class NodeField(Field):
def __init__(self, node, type=False, deprecation_reason=None, name=None, **kwargs): def __init__(self, node, type=False, deprecation_reason=None, name=None, **kwargs):
raise_assertion_if( if not issubclass(node, Node):
condition= not issubclass(node, Node), raise AssertionError("NodeField can only operate in Nodes")
message="NodeField can only operate in Nodes"
)
self.node_type = node self.node_type = node
self.field_type = type self.field_type = type
@ -103,10 +98,12 @@ class Node(AbstractNode):
except Exception: except Exception:
return None return None
raise_assertion_if( if only_type:
condition=only_type and (graphene_type is not only_type), if graphene_type != only_type:
message="Must receive a {} id.".format(only_type._meta.name) raise AssertionError(
) "Must receive a {} id.".format(only_type._meta.name)
)
# We make sure the ObjectType implements the "Node" interface # We make sure the ObjectType implements the "Node" interface
if cls not in graphene_type._meta.interfaces: if cls not in graphene_type._meta.interfaces:
return None return None

View File

@ -5,7 +5,6 @@ from .dynamic import Dynamic
from .mountedtype import MountedType from .mountedtype import MountedType
from .structures import NonNull from .structures import NonNull
from .utils import get_type from .utils import get_type
from ..utils.comparison_helper import raise_assertion_if
class Argument(MountedType): class Argument(MountedType):
def __init__( def __init__(
@ -73,10 +72,10 @@ def to_arguments(args, extra_args=None):
raise ValueError('Unknown argument "{}".'.format(default_name)) raise ValueError('Unknown argument "{}".'.format(default_name))
arg_name = default_name or arg.name arg_name = default_name or arg.name
raise_assertion_if( if arg_name in arguments:
condition=arg_name in arguments, raise AssertionError(
message='More than one Argument have same name "{}".'.format(arg_name) 'More than one Argument have same name "{}".'.format(arg_name)
) )
arguments[arg_name] = arg arguments[arg_name] = arg
return arguments return arguments

View File

@ -1,6 +1,5 @@
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
from ..utils.comparison_helper import raise_assertion_if
class BaseOptions(object): class BaseOptions(object):
name = None # type: str name = None # type: str
@ -31,10 +30,8 @@ class BaseType(SubclassWithMeta):
@classmethod @classmethod
def __init_subclass_with_meta__(cls, name=None, description=None, _meta=None): def __init_subclass_with_meta__(cls, name=None, description=None, _meta=None):
raise_assertion_if( if "_meta" in cls.__dict__:
condition="_meta" in cls.__dict__, raise AssertionError("Can't assign meta directly")
message="Can't assign meta directly"
)
if not _meta: if not _meta:
return return
_meta.name = name or cls.__name__ _meta.name = name or cls.__name__

View File

@ -6,7 +6,6 @@ from aniso8601 import parse_date, parse_datetime, parse_time
from graphql.language import ast from graphql.language import ast
from .scalars import Scalar from .scalars import Scalar
from ..utils.comparison_helper import raise_assertion_if
class Date(Scalar): class Date(Scalar):
""" """
@ -19,10 +18,8 @@ class Date(Scalar):
def serialize(date): def serialize(date):
if isinstance(date, datetime.datetime): if isinstance(date, datetime.datetime):
date = date.date() date = date.date()
raise_assertion_if( if not isinstance(date, datetime.date):
condition=not isinstance(date, datetime.date), raise AssertionError('Received not compatible date "{}"'.format(repr(date)))
message='Received not compatible date "{}"'.format(repr(date))
)
return date.isoformat() return date.isoformat()
@classmethod @classmethod
@ -47,11 +44,10 @@ class DateTime(Scalar):
@staticmethod @staticmethod
def serialize(dt): def serialize(dt):
if not isinstance(dt, (datetime.datetime, datetime.date)):
raise_assertion_if( raise AssertionError(
condition=not isinstance(dt, (datetime.datetime, datetime.date)), 'Received not compatible datetime "{}"'.format(repr(dt))
message='Received not compatible datetime "{}"'.format(repr(dt)) )
)
return dt.isoformat() return dt.isoformat()
@classmethod @classmethod
@ -76,10 +72,8 @@ class Time(Scalar):
@staticmethod @staticmethod
def serialize(time): def serialize(time):
raise_assertion_if( if not isinstance(time, datetime.time):
condition= not isinstance(time, datetime.time), raise AssertionError('Received not compatible time "{}"'.format(repr(time)))
message='Received not compatible time "{}"'.format(repr(time))
)
return time.isoformat() return time.isoformat()
@classmethod @classmethod

View File

@ -3,8 +3,6 @@ from functools import partial
from .mountedtype import MountedType from .mountedtype import MountedType
from ..utils.comparison_helper import raise_assertion_if
class Dynamic(MountedType): class Dynamic(MountedType):
""" """
@ -14,10 +12,10 @@ class Dynamic(MountedType):
def __init__(self, type, with_schema=False, _creation_counter=None): def __init__(self, type, with_schema=False, _creation_counter=None):
super(Dynamic, self).__init__(_creation_counter=_creation_counter) super(Dynamic, self).__init__(_creation_counter=_creation_counter)
raise_assertion_if( if not (inspect.isfunction(type) or isinstance(type, partial)):
condition=not (inspect.isfunction(type) or isinstance(type, partial)), raise AssertionError(
message="type is expected to be a function or an instance of partial" "type is expected to be a function or an instance of partial"
) )
self.type = type self.type = type
self.with_schema = with_schema self.with_schema = with_schema

View File

@ -7,7 +7,6 @@ from .mountedtype import MountedType
from .structures import NonNull from .structures import NonNull
from .unmountedtype import UnmountedType from .unmountedtype import UnmountedType
from .utils import get_type from .utils import get_type
from ..utils.comparison_helper import raise_assertion_if
base_type = type base_type = type
@ -36,20 +35,20 @@ class Field(MountedType):
): ):
super(Field, self).__init__(_creation_counter=_creation_counter) super(Field, self).__init__(_creation_counter=_creation_counter)
raise_assertion_if( if args and not isinstance(args, Mapping):
condition=args and not isinstance(args, Mapping), raise AssertionError(
message='Arguments in a field have to be a mapping, received "{}".'.format(args) 'Arguments in a field have to be a mapping, received "{}".'.format(args)
) )
if source and resolver:
raise_assertion_if( raise AssertionError(
condition=source and resolver, "A Field cannot have a source and a resolver in at the same time."
message="A Field cannot have a source and a resolver in at the same time." )
) if callable(default_value):
raise AssertionError(
raise_assertion_if( 'The default value can not be a function but received "{}".'.format(
condition=callable(default_value), base_type(default_value)
message='The default value can not be a function but received "{}".'.format(base_type(default_value) )
) )
if required: if required:
type = NonNull(type) type = NonNull(type)

View File

@ -1,7 +1,6 @@
from ..utils.orderedtype import OrderedType from ..utils.orderedtype import OrderedType
from .unmountedtype import UnmountedType from .unmountedtype import UnmountedType
from ..utils.comparison_helper import raise_assertion_if
class MountedType(OrderedType): class MountedType(OrderedType):
@classmethod @classmethod
@ -9,10 +8,10 @@ class MountedType(OrderedType):
""" """
Mount the UnmountedType instance Mount the UnmountedType instance
""" """
raise_assertion_if( if not isinstance(unmounted, UnmountedType):
condition=not isinstance(unmounted, UnmountedType), raise AssertionError(
message="{} can't mount {}".format(cls.__name__, repr(unmounted) "{} can't mount {}".format(cls.__name__, repr(unmounted))
) )
return cls( return cls(
unmounted.get_type(), unmounted.get_type(),

View File

@ -5,8 +5,6 @@ from .field import Field
from .interface import Interface from .interface import Interface
from .utils import yank_fields_from_attrs from .utils import yank_fields_from_attrs
from ..utils.comparison_helper import raise_assertion_if
# For static type checking with Mypy # For static type checking with Mypy
MYPY = False MYPY = False
if MYPY: if MYPY:
@ -49,15 +47,15 @@ class ObjectType(BaseType):
for base in reversed(cls.__mro__): for base in reversed(cls.__mro__):
fields.update(yank_fields_from_attrs(base.__dict__, _as=Field)) fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))
error_message = """ if possible_types and cls.is_type_of:
{name}.Meta.possible_types will cause type collision with {name}.is_type_of. raise AssertionError(
Please use one or other. """
""".format(name=cls.__name__) {name}.Meta.possible_types will cause type collision with {name}.is_type_of.
Please use one or other.
raise_assertion_if( """.format(
condition=possible_types and cls.is_type_of, name=cls.__name__
message=error_message )
) )
if _meta.fields: if _meta.fields:
_meta.fields.update(fields) _meta.fields.update(fields)

View File

@ -1,5 +1,3 @@
from ..utils.comparison_helper import raise_assertion_if
def attr_resolver(attname, default_value, root, info, **args): def attr_resolver(attname, default_value, root, info, **args):
return getattr(root, attname, default_value) return getattr(root, attname, default_value)
@ -13,11 +11,8 @@ default_resolver = attr_resolver
def set_default_resolver(resolver): def set_default_resolver(resolver):
global default_resolver global default_resolver
if not callable(resolver):
raise_assertion_if( raise AssertionError("Received non-callable resolver.")
condition=not callable(resolver),
message="Received non-callable resolver."
)
default_resolver = resolver default_resolver = resolver

View File

@ -13,17 +13,14 @@ from graphql.utils.schema_printer import print_schema
from .definitions import GrapheneGraphQLType from .definitions import GrapheneGraphQLType
from .objecttype import ObjectType from .objecttype import ObjectType
from .typemap import TypeMap, is_graphene_type from .typemap import TypeMap, is_graphene_type
from ..utils.comparison_helper import raise_assertion_if
def assert_valid_root_type(_type): def assert_valid_root_type(_type):
if _type is None: if _type is None:
return return
is_graphene_objecttype = inspect.isclass(_type) and issubclass(_type, ObjectType) is_graphene_objecttype = inspect.isclass(_type) and issubclass(_type, ObjectType)
is_graphql_objecttype = isinstance(_type, GraphQLObjectType) is_graphql_objecttype = isinstance(_type, GraphQLObjectType)
raise_assertion_if( if not (is_graphene_objecttype or is_graphql_objecttype):
condition=not (is_graphene_objecttype or is_graphql_objecttype), raise AssertionError("Type {} is not a valid ObjectType.".format(_type))
message="Type {} is not a valid ObjectType.".format(_type)
)
class Schema(GraphQLSchema): class Schema(GraphQLSchema):
@ -54,10 +51,12 @@ class Schema(GraphQLSchema):
if directives is None: if directives is None:
directives = [GraphQLIncludeDirective, GraphQLSkipDirective] directives = [GraphQLIncludeDirective, GraphQLSkipDirective]
raise_assertion_if( if not all(isinstance(d, GraphQLDirective) for d in directives):
condition=not all(isinstance(d, GraphQLDirective) for d in directives), raise AssertionError(
message="Schema directives must be List[GraphQLDirective] if provided but got: {}.".format(directives) "Schema directives must be List[GraphQLDirective] if provided but got: {}.".format(
) directives
)
)
self._directives = directives self._directives = directives
self.build_typemap() self.build_typemap()
@ -91,19 +90,16 @@ class Schema(GraphQLSchema):
return _type return _type
if is_graphene_type(_type): if is_graphene_type(_type):
graphql_type = self.get_type(_type._meta.name) graphql_type = self.get_type(_type._meta.name)
if not graphql_type:
raise_assertion_if( raise AssertionError(
condition=not graphql_type, "Type {} not found in this schema.".format(_type._meta.name)
message="Type {} not found in this schema.".format(_type._meta.name) )
) if graphql_type.graphene_type != _type:
raise AssertionError(
error_message = "The type {} does not match with the associated graphene type {}." "The type {} does not match with the associated graphene type {}.".format(
.format(_type, graphql_type.graphene_type) _type, graphql_type.graphene_type
raise_assertion_if( )
condition=graphql_type.graphene_type is not _type, )
message=error_message
)
return graphql_type return graphql_type
raise Exception("{} is not a valid GraphQL type.".format(_type)) raise Exception("{} is not a valid GraphQL type.".format(_type))

View File

@ -40,7 +40,6 @@ from .scalars import ID, Boolean, Float, Int, Scalar, String
from .structures import List, NonNull from .structures import List, NonNull
from .union import Union from .union import Union
from .utils import get_field_as from .utils import get_field_as
from ..utils.comparison_helper import raise_assertion_if
def is_graphene_type(_type): def is_graphene_type(_type):
@ -61,18 +60,16 @@ def resolve_type(resolve_type_func, map, type_name, root, info):
if inspect.isclass(_type) and issubclass(_type, ObjectType): if inspect.isclass(_type) and issubclass(_type, ObjectType):
graphql_type = map.get(_type._meta.name) graphql_type = map.get(_type._meta.name)
raise_assertion_if( if not graphql_type:
condition=not graphql_type, raise AssertionError(
message="Can't find type {} in schema".format(_type._meta.name) "Can't find type {} in schema".format(_type._meta.name)
) )
if graphql_type.graphene_type != _type:
error_message = "The type {} does not match with the associated graphene type {}." raise AssertionError(
.format( _type, graphql_type.graphene_type) "The type {} does not match with the associated graphene type {}.".format(
raise_assertion_if( _type, graphql_type.graphene_type
condition=graphql_type.graphene_type is not _type, )
message=error_message )
)
return graphql_type return graphql_type
return _type return _type
@ -103,12 +100,12 @@ class TypeMap(GraphQLTypeMap):
if type._meta.name in map: if type._meta.name in map:
_type = map[type._meta.name] _type = map[type._meta.name]
if isinstance(_type, GrapheneGraphQLType): if isinstance(_type, GrapheneGraphQLType):
error_message = "Found different types with the same name in the schema: {}, {}." if _type.graphene_type is not type:
.format(_type.graphene_type, type) raise AssertionError(
raise_assertion_if( "Found different types with the same name in the schema: {}, {}.".format(
condition=_type.graphene_type is not type, _type.graphene_type, type
message=error_message )
) )
return map return map
if issubclass(type, ObjectType): if issubclass(type, ObjectType):
@ -185,12 +182,12 @@ class TypeMap(GraphQLTypeMap):
if type._meta.name in map: if type._meta.name in map:
_type = map[type._meta.name] _type = map[type._meta.name]
if isinstance(_type, GrapheneGraphQLType): if isinstance(_type, GrapheneGraphQLType):
error_message = "Found different types with the same name in the schema: {}, {}." if _type.graphene_type != type:
.format(_type.graphene_type, type) raise AssertionError(
raise_assertion_if( "Found different types with the same name in the schema: {}, {}.".format(
condition=_type.graphene_type is not type, _type.graphene_type, type
message=error_message )
) )
return _type return _type
def interfaces(): def interfaces():
@ -198,12 +195,12 @@ class TypeMap(GraphQLTypeMap):
for interface in type._meta.interfaces: for interface in type._meta.interfaces:
self.graphene_reducer(map, interface) self.graphene_reducer(map, interface)
internal_type = map[interface._meta.name] internal_type = map[interface._meta.name]
error_message = "Found different types with the same name in the schema: {}, {}." if internal_type.graphene_type != interface:
.format(internal_type.graphene_type, interface) raise AssertionError(
raise_assertion_if( "Found different types with the same name in the schema: {}, {}.".format(
condition=internal_type.graphene_type is not interface, internal_type.graphene_type, interface
message=error_message )
) )
interfaces.append(internal_type) interfaces.append(internal_type)
return interfaces return interfaces
@ -227,12 +224,12 @@ class TypeMap(GraphQLTypeMap):
if type._meta.name in map: if type._meta.name in map:
_type = map[type._meta.name] _type = map[type._meta.name]
if isinstance(_type, GrapheneInterfaceType): if isinstance(_type, GrapheneInterfaceType):
error_message = "Found different types with the same name in the schema: {}, {}." if _type.graphene_type != type:
.format(_type.graphene_type, type) raise AssertionError(
raise_assertion_if( "Found different types with the same name in the schema: {}, {}.".format(
condition= _type.graphene_type is not type, _type.graphene_type, type
message=error_message )
) )
return _type return _type
_resolve_type = None _resolve_type = None
@ -271,12 +268,12 @@ class TypeMap(GraphQLTypeMap):
for objecttype in type._meta.types: for objecttype in type._meta.types:
self.graphene_reducer(map, objecttype) self.graphene_reducer(map, objecttype)
internal_type = map[objecttype._meta.name] internal_type = map[objecttype._meta.name]
error_message = "Found different types with the same name in the schema: {}, {}." if internal_type.graphene_type != objecttype:
.format(internal_type.graphene_type, objecttype) raise AssertionError(
raise_assertion_if( "Found different types with the same name in the schema: {}, {}.".format(
condition=internal_type.graphene_type is not objecttype, internal_type.graphene_type, objecttype
message=error_message )
) )
union_types.append(internal_type) union_types.append(internal_type)
return union_types return union_types

View File

@ -1,8 +1,6 @@
from .base import BaseOptions, BaseType from .base import BaseOptions, BaseType
from .unmountedtype import UnmountedType from .unmountedtype import UnmountedType
from ..utils.comparison_helper import raise_assertion_if
# For static type checking with Mypy # For static type checking with Mypy
MYPY = False MYPY = False
if MYPY: if MYPY:
@ -25,11 +23,10 @@ class Union(UnmountedType, BaseType):
@classmethod @classmethod
def __init_subclass_with_meta__(cls, types=None, **options): def __init_subclass_with_meta__(cls, types=None, **options):
if not (isinstance(types, (list, tuple)) and len(types) > 0):
raise_assertion_if( raise AssertionError(
condition=not (isinstance(types, (list, tuple)) and len(types) > 0, "Must provide types for Union {name}.".format(name=cls.__name__)
message="Must provide types for Union {name}.".format(name=cls.__name__) )
)
_meta = UnionOptions(cls) _meta = UnionOptions(cls)
_meta.types = types _meta.types = types
super(Union, cls).__init_subclass_with_meta__(_meta=_meta, **options) super(Union, cls).__init_subclass_with_meta__(_meta=_meta, **options)

View File

@ -5,7 +5,6 @@ from uuid import UUID as _UUID
from graphql.language import ast from graphql.language import ast
from .scalars import Scalar from .scalars import Scalar
from ..utils.comparison_helper import raise_assertion_if
class UUID(Scalar): class UUID(Scalar):
"""UUID""" """UUID"""
@ -14,10 +13,8 @@ class UUID(Scalar):
def serialize(uuid): def serialize(uuid):
if isinstance(uuid, str): if isinstance(uuid, str):
uuid = _UUID(uuid) uuid = _UUID(uuid)
raise_assertion_if( if not isinstance(uuid, _UUID):
condition=not isinstance(uuid, _UUID), raise AssertionError("Expected UUID instance, received {}".format(uuid))
message="Expected UUID instance, received {}".format(uuid)
)
return str(uuid) return str(uuid)
@staticmethod @staticmethod

View File

@ -2,7 +2,6 @@ import six
from ..pyutils.compat import func_name, signature from ..pyutils.compat import func_name, signature
from .deprecated import warn_deprecation from .deprecated import warn_deprecation
from .comparison_helper import raise_assertion_if
def annotate(_func=None, _trigger_warning=True, **annotations): def annotate(_func=None, _trigger_warning=True, **annotations):
@ -23,13 +22,11 @@ def annotate(_func=None, _trigger_warning=True, **annotations):
# We make sure the annotations are valid # We make sure the annotations are valid
for key, value in annotations.items(): for key, value in annotations.items():
func_param = func_signature.parameters.get(key, None) if func_signature.parameters.get(key, None) is None:
assertion_message = 'The key {key} is not a function parameter in the function "{func_name}".' raise AssertionError(
.format(key=key, func_name=func_name(_func) 'The key {key} is not a function parameter in the function "{func_name}".'.format(
key=key, func_name=func_name(_func)
raise_assertion_if( )
condition=func_param is None,
message=assertion_message
) )
func_annotations = getattr(_func, "__annotations__", None) func_annotations = getattr(_func, "__annotations__", None)

View File

@ -41,13 +41,16 @@ class SubclassWithMeta(six.with_metaclass(SubclassWithMeta_Meta)):
options = dict(meta_options, **_meta_props) options = dict(meta_options, **_meta_props)
abstract = options.pop("abstract", False) abstract = options.pop("abstract", False)
error_message = """ if abstract:
if options:
raise AssertionError(
"""
Abstract types can only contain the abstract attribute. Abstract types can only contain the abstract attribute.
Received: abstract, {option_keys} Received: abstract, {option_keys}
""".format(option_keys=", ".join(options.keys()) """.format(
option_keys=", ".join(options.keys())
raise_assertion_if(condition=options and abstract, message=error_message) )
)
else: else:
super_class = super(cls, cls) super_class = super(cls, cls)
if hasattr(super_class, "__init_subclass_with_meta__"): if hasattr(super_class, "__init_subclass_with_meta__"):