Skip to content

Commit 1264f61

Browse files
committed
Add test that checks whether API test is complete
1 parent ecf476a commit 1264f61

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from astropy.utils.data import get_pkg_data_contents
2+
3+
from astro_image_display_api.interface_definition import ImageViewerInterface
4+
from astro_image_display_api.dummy_viewer import ImageViewer
5+
from astro_image_display_api.widget_api_test import ImageWidgetAPITest
6+
7+
def test_api_test_class_completeness():
8+
"""
9+
Test that the ImageWidgetAPITest class is complete and has tests
10+
for all of the required methods and attributes.
11+
"""
12+
# Get the attributes on the protocol
13+
required_attributes = ImageViewerInterface.__protocol_attrs__
14+
15+
# Get the text of the api tests
16+
widget_api_test_content = get_pkg_data_contents("widget_api_test.py", package="astro_image_display_api")
17+
# Loop over the attributes and check that the test class has a method
18+
# for each one whose name starts with test_ and ends with the attribute
19+
# name.
20+
attr_present = []
21+
image_viewer_name = "self.image"
22+
for attr in required_attributes:
23+
attr_present.append(f"{image_viewer_name}.{attr}" in widget_api_test_content)
24+
25+
26+
27+
assert all(attr_present), (
28+
"ImageWidgetAPITest is does not access these attributes/methods:\n "
29+
f"{"\n".join(attr for attr, present in zip(required_attributes, attr_present) if not present)}. "
30+
)

0 commit comments

Comments
 (0)