2016-08-15 13:27:13 +00:00
|
|
|
"""
|
|
|
|
Common helper functions for tests.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
|
|
|
|
from attr import Attribute
|
|
|
|
from attr._make import NOTHING, make_class
|
|
|
|
|
|
|
|
|
2018-06-10 17:40:07 +00:00
|
|
|
def simple_class(
|
2018-08-20 04:46:52 +00:00
|
|
|
cmp=False,
|
|
|
|
repr=False,
|
|
|
|
hash=False,
|
|
|
|
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"],
|
|
|
|
cmp=cmp,
|
|
|
|
repr=repr,
|
|
|
|
hash=hash,
|
|
|
|
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,
|
|
|
|
cmp=True,
|
|
|
|
hash=None,
|
|
|
|
init=True,
|
|
|
|
converter=None,
|
2018-08-11 04:40:01 +00:00
|
|
|
kw_only=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,
|
|
|
|
cmp=cmp,
|
|
|
|
hash=hash,
|
|
|
|
init=init,
|
|
|
|
converter=converter,
|
2018-08-11 04:40:01 +00:00
|
|
|
kw_only=False,
|
2016-08-15 13:27:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class TestSimpleClass(object):
|
|
|
|
"""
|
|
|
|
Tests for the testing helper function `make_class`.
|
|
|
|
"""
|
2018-06-10 17:40:07 +00:00
|
|
|
|
2016-08-15 13:27:13 +00:00
|
|
|
def test_returns_class(self):
|
|
|
|
"""
|
|
|
|
Returns a class object.
|
|
|
|
"""
|
|
|
|
assert type is simple_class().__class__
|
|
|
|
|
|
|
|
def returns_distinct_classes(self):
|
|
|
|
"""
|
|
|
|
Each call returns a completely new class.
|
|
|
|
"""
|
|
|
|
assert simple_class() is not simple_class()
|