added first doc stub (#506)
* added first doc stub * fixed test * review * added newsfragment * improved docs Co-authored-by: Simone Robutti <simone.robutti@teraki.com>
This commit is contained in:
parent
9fcfe3479f
commit
4dea97e633
|
@ -0,0 +1 @@
|
|||
The documentation of generated methods is now created automatically using the method name.
|
|
@ -732,6 +732,13 @@ class _ClassBuilder(object):
|
|||
except AttributeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
method.__doc__ = "Method generated by attrs for class {}.".format(
|
||||
self._cls.__qualname__
|
||||
)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return method
|
||||
|
||||
|
||||
|
|
|
@ -1630,3 +1630,35 @@ class TestDetermineEqOrder(object):
|
|||
"2021-06-01. Please use `eq` and `order` instead."
|
||||
== w.message.args[0]
|
||||
)
|
||||
|
||||
|
||||
class TestDocs:
|
||||
@pytest.mark.parametrize(
|
||||
"meth_name",
|
||||
[
|
||||
"__init__",
|
||||
"__repr__",
|
||||
"__eq__",
|
||||
"__ne__",
|
||||
"__lt__",
|
||||
"__le__",
|
||||
"__gt__",
|
||||
"__ge__",
|
||||
],
|
||||
)
|
||||
def test_docs(self, meth_name):
|
||||
"""
|
||||
Tests the presence and correctness of the documentation
|
||||
for the generated methods
|
||||
"""
|
||||
|
||||
@attr.s
|
||||
class A(object):
|
||||
pass
|
||||
|
||||
if hasattr(A, "__qualname__"):
|
||||
method = getattr(A, meth_name)
|
||||
expected = "Method generated by attrs for class {}.".format(
|
||||
A.__qualname__
|
||||
)
|
||||
assert expected == method.__doc__
|
||||
|
|
Loading…
Reference in New Issue