attrs/tests/utils.py

69 lines
1.2 KiB
Python
Raw Normal View History

2021-12-27 08:29:09 +00:00
# SPDX-License-Identifier: MIT
"""
Common helper functions for tests.
"""
from attr import Attribute
from attr._make import NOTHING, _default_init_alias_for, make_class
2018-06-10 17:40:07 +00:00
def simple_class(
eq=False,
order=False,
repr=False,
unsafe_hash=False,
str=False,
slots=False,
frozen=False,
cache_hash=False,
2018-06-10 17:40:07 +00:00
):
"""
Return a new simple class.
"""
return make_class(
2018-06-10 17:40:07 +00:00
"C",
["a", "b"],
eq=eq or order,
order=order,
2018-06-10 17:40:07 +00:00
repr=repr,
unsafe_hash=unsafe_hash,
2018-06-10 17:40:07 +00:00
init=True,
slots=slots,
str=str,
2017-02-19 08:51:43 +00:00
frozen=frozen,
cache_hash=cache_hash,
)
2018-06-10 17:40:07 +00:00
def simple_attr(
name,
default=NOTHING,
validator=None,
repr=True,
eq=True,
2018-06-10 17:40:07 +00:00
hash=None,
init=True,
converter=None,
kw_only=False,
inherited=False,
2018-06-10 17:40:07 +00:00
):
"""
Return an attribute with a name and no other bells and whistles.
"""
return Attribute(
2018-06-10 17:40:07 +00:00
name=name,
default=default,
validator=validator,
repr=repr,
cmp=None,
eq=eq,
2018-06-10 17:40:07 +00:00
hash=hash,
init=init,
converter=converter,
kw_only=kw_only,
inherited=inherited,
alias=_default_init_alias_for(name),
)