mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-25 19:13:57 +03:00
Implement trim_docstring
Thin wrapper around `inspect.clean_doc`
This commit is contained in:
parent
d1d87221d5
commit
0dc8e57c50
21
graphene/utils/tests/test_trim_docstring.py
Normal file
21
graphene/utils/tests/test_trim_docstring.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from ..trim_docstring import trim_docstring
|
||||
|
||||
|
||||
def test_trim_docstring():
|
||||
class WellDocumentedObject(object):
|
||||
"""
|
||||
This object is very well-documented. It has multiple lines in its
|
||||
description.
|
||||
|
||||
Multiple paragraphs too
|
||||
"""
|
||||
pass
|
||||
|
||||
assert (trim_docstring(WellDocumentedObject.__doc__) ==
|
||||
"This object is very well-documented. It has multiple lines in its\n"
|
||||
"description.\n\nMultiple paragraphs too")
|
||||
|
||||
class UndocumentedObject(object):
|
||||
pass
|
||||
|
||||
assert trim_docstring(UndocumentedObject.__doc__) is None
|
9
graphene/utils/trim_docstring.py
Normal file
9
graphene/utils/trim_docstring.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
import inspect
|
||||
|
||||
|
||||
def trim_docstring(docstring):
|
||||
# Cleans up whitespaces from an indented docstring
|
||||
#
|
||||
# See https://www.python.org/dev/peps/pep-0257/
|
||||
# and https://docs.python.org/2/library/inspect.html#inspect.cleandoc
|
||||
return inspect.cleandoc(docstring) if docstring else None
|
Loading…
Reference in New Issue
Block a user