Skip to content

Commit c146303

Browse files
committed
Check that every method and property has a docstring
1 parent fb13f6d commit c146303

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/astro_image_display_api/api_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,3 +906,25 @@ def test_all_methods_accept_additional_kwargs(self, data, catalog, tmp_path):
906906
"The following methods failed when called with additional kwargs:\n\t"
907907
f"{'\n\t'.join(failed_methods)}"
908908
)
909+
910+
def test_every_method_attribute_has_docstring(self):
911+
"""
912+
Check that every method and attribute in the protocol has a docstring.
913+
"""
914+
from astro_image_display_api import ImageViewerInterface
915+
916+
all_methods_and_attributes = ImageViewerInterface.__protocol_attrs__
917+
918+
method_attrs_no_docs = []
919+
920+
for method in all_methods_and_attributes:
921+
attr = getattr(self.image, method)
922+
# Make list of methods and attributes that have no docstring
923+
# and assert that list is empty at the end of the test.
924+
if not attr.__doc__:
925+
method_attrs_no_docs.append(method)
926+
927+
assert not method_attrs_no_docs, (
928+
"The following methods and attributes have no docstring:\n\t"
929+
f"{'\n\t'.join(method_attrs_no_docs)}"
930+
)

tests/test_astro_image_display_api.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,26 @@ def test_api_test_class_covers_all_attributes_and_only_those_attributes():
7272
"ImageWidgetAPITest does not access these "
7373
f"attributes/methods:\n{missing_attributes_msg}\n"
7474
)
75+
76+
77+
def test_every_method_attribute_has_docstring():
78+
"""
79+
Check that every method and attribute in the protocol has a docstring.
80+
"""
81+
from astro_image_display_api import ImageViewerInterface
82+
83+
all_methods_and_attributes = ImageViewerInterface.__protocol_attrs__
84+
85+
method_attrs_no_docs = []
86+
87+
for method in all_methods_and_attributes:
88+
attr = getattr(ImageViewerInterface, method)
89+
# Make list of methods and attributes that have no docstring
90+
# and assert that list is empty at the end of the test.
91+
if not attr.__doc__:
92+
method_attrs_no_docs.append(method)
93+
94+
assert not method_attrs_no_docs, (
95+
"The following methods and attributes have no docstring:\n\t"
96+
f"{'\n\t'.join(method_attrs_no_docs)}"
97+
)

0 commit comments

Comments
 (0)