def test_nbscreenshot(make_test_viewer): """Test taking a screenshot.""" viewer = make_test_viewer() np.random.seed(0) data = np.random.random((10, 15)) viewer.add_image(data) rich_display_object = nbscreenshot(viewer) assert hasattr(rich_display_object, '_repr_png_') # Trigger method that would run in jupyter notebook cell automatically rich_display_object._repr_png_() assert rich_display_object.image is not None
def test_nbscreenshot(make_napari_viewer, alt_text_input, expected_alt_text): """Test taking a screenshot.""" viewer = make_napari_viewer() np.random.seed(0) data = np.random.random((10, 15)) viewer.add_image(data) rich_display_object = nbscreenshot(viewer, alt_text=alt_text_input) assert hasattr(rich_display_object, '_repr_png_') # Trigger method that would run in jupyter notebook cell automatically rich_display_object._repr_png_() assert rich_display_object.image is not None html_output = rich_display_object._repr_html_() if expected_alt_text is None: assert 'alt_text=' not in html_output else: expected_output = 'alt="' + str(expected_alt_text) + '"' assert expected_output in html_output
def test_safe_alt_text(alt_text_input, expected_alt_text): display_obj = nbscreenshot(Mock(), alt_text=alt_text_input) if not expected_alt_text: assert not display_obj.alt_text else: assert html.escape(display_obj.alt_text) == expected_alt_text