1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
# SPDX-License-Identifier: MIT
"""
Common helper functions for tests.
"""
from attr import Attribute
from attr._make import NOTHING, _default_init_alias_for, make_class
def simple_class(
eq=False,
order=False,
repr=False,
unsafe_hash=False,
str=False,
slots=False,
frozen=False,
cache_hash=False,
):
"""
Return a new simple class.
"""
return make_class(
"C",
["a", "b"],
eq=eq or order,
order=order,
repr=repr,
unsafe_hash=unsafe_hash,
init=True,
slots=slots,
str=str,
frozen=frozen,
cache_hash=cache_hash,
)
def simple_attr(
name,
default=NOTHING,
validator=None,
repr=True,
eq=True,
hash=None,
init=True,
converter=None,
kw_only=False,
inherited=False,
):
"""
Return an attribute with a name and no other bells and whistles.
"""
return Attribute(
name=name,
default=default,
validator=validator,
repr=repr,
cmp=None,
eq=eq,
hash=hash,
init=init,
converter=converter,
kw_only=kw_only,
inherited=inherited,
alias=_default_init_alias_for(name),
)
|