Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BokehRenderer tests #193

Merged
merged 1 commit into from Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/installation.rst
Expand Up @@ -102,6 +102,9 @@ against. To include tests that take a long time to run:

$ pytest --runslow

:class:`~contourpy.util.bokeh_renderer.BokehRenderer` tests will be run if ``bokeh`` is installed,
otherwise they will be skipped.


Building the documentation
--------------------------
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Expand Up @@ -41,9 +41,11 @@ docs = [
"sphinx-rtd-theme",
]
bokeh = [
# Optional dependencies to support use of bokeh renderer.
# Also needs chrome/chromium for export to PNG/SVG/buffer.
"bokeh",
"chromedriver",
"selenium",
# Also need geckodriver and firefox, or chromedriver and chrome, for export to PNG/SVG/buffer.
]
test = [
# Standard test dependencies.
Expand Down
Binary file added tests/baseline_images/renderer_filled_bokeh.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/baseline_images/renderer_lines_bokeh.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 26 additions & 8 deletions tests/test_renderer.py
Expand Up @@ -9,13 +9,22 @@
@pytest.mark.text
@pytest.mark.parametrize("show_text", [False, True])
@pytest.mark.parametrize("fill_type", FillType.__members__.values())
def test_renderer_filled(show_text, fill_type):
from contourpy.util.mpl_renderer import MplRenderer
@pytest.mark.parametrize("renderer_type", ["mpl", "bokeh"])
def test_renderer_filled(show_text, fill_type, renderer_type):
if renderer_type == "mpl":
from contourpy.util.mpl_renderer import MplRenderer as Renderer
elif renderer_type == "bokeh":
try:
from contourpy.util.bokeh_renderer import BokehRenderer as Renderer
except ImportError:
pytest.skip("Optional bokeh dependencies not installed")
else:
raise ValueError(f"Unrecognised renderer type {renderer_type}")

from .image_comparison import compare_images

x, y, z = random((3, 4))
renderer = MplRenderer(ncols=2, figsize=(8, 3), show_frame=False)
renderer = Renderer(ncols=2, figsize=(8, 3), show_frame=False)
for ax, quad_as_tri in enumerate((False, True)):
cont_gen = contour_generator(x, y, z, fill_type=fill_type)

Expand All @@ -38,20 +47,29 @@ def test_renderer_filled(show_text, fill_type):

image_buffer = renderer.save_to_buffer()
suffix = "" if show_text else "_no_text"
compare_images(image_buffer, f"renderer_filled_mpl{suffix}.png", f"{fill_type}")
compare_images(image_buffer, f"renderer_filled_{renderer_type}{suffix}.png", f"{fill_type}")


@pytest.mark.image
@pytest.mark.text
@pytest.mark.parametrize("show_text", [False, True])
@pytest.mark.parametrize("line_type", LineType.__members__.values())
def test_renderer_lines(show_text, line_type):
from contourpy.util.mpl_renderer import MplRenderer
@pytest.mark.parametrize("renderer_type", ["mpl", "bokeh"])
def test_renderer_lines(show_text, line_type, renderer_type):
if renderer_type == "mpl":
from contourpy.util.mpl_renderer import MplRenderer as Renderer
elif renderer_type == "bokeh":
try:
from contourpy.util.bokeh_renderer import BokehRenderer as Renderer
except ImportError:
pytest.skip("Optional bokeh dependencies not installed")
else:
raise ValueError(f"Unrecognised renderer type {renderer_type}")

from .image_comparison import compare_images

x, y, z = random((3, 4))
renderer = MplRenderer(ncols=2, figsize=(8, 3), show_frame=show_text)
renderer = Renderer(ncols=2, figsize=(8, 3), show_frame=show_text)
for ax, quad_as_tri in enumerate((False, True)):
cont_gen = contour_generator(x, y, z, line_type=line_type)

Expand All @@ -76,4 +94,4 @@ def test_renderer_lines(show_text, line_type):

image_buffer = renderer.save_to_buffer()
suffix = "" if show_text else "_no_text"
compare_images(image_buffer, f"renderer_lines_mpl{suffix}.png", f"{line_type}")
compare_images(image_buffer, f"renderer_lines_{renderer_type}{suffix}.png", f"{line_type}")