2021-12-27 08:29:09 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2016-08-15 13:27:13 +00:00
|
|
|
"""
|
|
|
|
Common helper functions for tests.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
from attr import Attribute
|
2022-11-30 14:39:57 +00:00
|
|
|
from attr._make import NOTHING, _default_init_alias_for, make_class
|
2016-08-15 13:27:13 +00:00
|
|
|
|
|
|
|
|
2018-06-10 17:40:07 +00:00
|
|
|
def simple_class(
|
2019-09-22 13:07:19 +00:00
|
|
|
eq=False,
|
|
|
|
order=False,
|
2018-08-20 04:46:52 +00:00
|
|
|
repr=False,
|
2024-08-03 13:19:21 +00:00
|
|
|
unsafe_hash=False,
|
2018-08-20 04:46:52 +00:00
|
|
|
str=False,
|
|
|
|
slots=False,
|
|
|
|
frozen=False,
|
|
|
|
cache_hash=False,
|
2018-06-10 17:40:07 +00:00
|
|
|
):
|
2016-08-15 13:27:13 +00:00
|
|
|
"""
|
|
|
|
Return a new simple class.
|
|
|
|
"""
|
|
|
|
return make_class(
|
2018-06-10 17:40:07 +00:00
|
|
|
"C",
|
|
|
|
["a", "b"],
|
2019-09-22 13:07:19 +00:00
|
|
|
eq=eq or order,
|
|
|
|
order=order,
|
2018-06-10 17:40:07 +00:00
|
|
|
repr=repr,
|
2024-08-03 13:19:21 +00:00
|
|
|
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,
|
2018-08-20 04:46:52 +00:00
|
|
|
cache_hash=cache_hash,
|
2016-08-15 13:27:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-06-10 17:40:07 +00:00
|
|
|
def simple_attr(
|
|
|
|
name,
|
|
|
|
default=NOTHING,
|
|
|
|
validator=None,
|
|
|
|
repr=True,
|
2019-09-22 13:07:19 +00:00
|
|
|
eq=True,
|
2018-06-10 17:40:07 +00:00
|
|
|
hash=None,
|
|
|
|
init=True,
|
|
|
|
converter=None,
|
2018-08-11 04:40:01 +00:00
|
|
|
kw_only=False,
|
2020-04-06 09:41:52 +00:00
|
|
|
inherited=False,
|
2018-06-10 17:40:07 +00:00
|
|
|
):
|
2016-08-15 13:27:13 +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,
|
2019-09-22 13:07:19 +00:00
|
|
|
cmp=None,
|
|
|
|
eq=eq,
|
2018-06-10 17:40:07 +00:00
|
|
|
hash=hash,
|
|
|
|
init=init,
|
|
|
|
converter=converter,
|
2020-04-06 09:41:52 +00:00
|
|
|
kw_only=kw_only,
|
|
|
|
inherited=inherited,
|
2022-11-30 14:39:57 +00:00
|
|
|
alias=_default_init_alias_for(name),
|
2016-08-15 13:27:13 +00:00
|
|
|
)
|