Skip to content

Commit

Permalink
Use correct version of chromium for Bokeh image tests (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 committed May 17, 2023
1 parent 8803947 commit ff75c94
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
31 changes: 28 additions & 3 deletions .github/workflows/test.yml
Expand Up @@ -65,6 +65,11 @@ jobs:
test:
name: "${{ matrix.name }} ${{ matrix.python-version }} ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
env:
# Required version of chromium used for Bokeh image tests.
CHROME_VER: "110.0.5481.100"
CHROME_REV: "chromium_2333"

strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -122,6 +127,28 @@ jobs:
sudo apt update -yy
sudo apt install -yy lcov
- name: Install chromium for Bokeh tests
if: matrix.test-text
run: |
if [[ "$(chromium --version | cut -d' ' -f2)" = "$CHROME_VER" ]]; then
echo "Using pre-installed version of chromium"
else
URL=https://github.com/bokeh/chromium/raw/main/linux/$CHROME_VER
wget --no-verbose $URL/$CHROME_REV.assert
wget --no-verbose $URL/$CHROME_REV.snap
ls -l $CHROME_REV.*
sudo snap ack $CHROME_REV.assert
sudo snap install $CHROME_REV.snap
snap list chromium
snap info chromium
fi
# Creating symlink here isn't ideal :)
cd /snap/bin && sudo ln -s chromium.chromedriver chromedriver
which chromium
chromium --version
which chromedriver
chromedriver --version
- name: Build and install numpy from sdist
if: matrix.build-numpy
run: |
Expand Down Expand Up @@ -173,9 +200,7 @@ jobs:
elif [[ "${{ matrix.test-text }}" != "" ]]
then
echo "Run normal and text tests with coverage"
chromium --version
#python -m pytest -v --color=yes tests/ --runtext --cov=lib --cov-report=lcov
python -m pytest -v --color=yes tests/ --cov=lib --cov-report=lcov
python -m pytest -v --color=yes -rP tests/test_renderer.py --runtext --cov=lib --cov-report=lcov
elif [[ "${{ matrix.test-no-images }}" != "" ]]
then
echo "Run only tests that do not generate images"
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Expand Up @@ -42,9 +42,8 @@ docs = [
]
bokeh = [
# Optional dependencies to support use of bokeh renderer.
# Also needs chrome/chromium for export to PNG/SVG/buffer.
# Also needs chrome/chromium and chromedriver for export to PNG/SVG/buffer.
"bokeh",
"chromedriver",
"selenium",
]
mypy = [
Expand Down
Binary file modified 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.
Binary file modified 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.
21 changes: 20 additions & 1 deletion tests/test_renderer.py
Expand Up @@ -7,6 +7,22 @@
from contourpy.util.data import random


def test_chrome_version() -> None:
# Print version of chrome used for export to PNG by Bokeh as test images, particularly those
# containing text, are sensitive to chrome version.
try:
import contourpy.util.bokeh_renderer # noqa: F401
except ImportError:
pytest.skip("Optional bokeh dependencies not installed")

from bokeh.io.webdriver import webdriver_control
driver = webdriver_control.get()
capabilities = driver.capabilities
print("chrome version used by Bokeh:", capabilities["browserVersion"])
if "chrome" in capabilities:
print("chromedriver version used by Bokeh:", capabilities["chrome"]["chromedriverVersion"])


@pytest.mark.image
@pytest.mark.text
@pytest.mark.parametrize("show_text", [False, True])
Expand Down Expand Up @@ -99,4 +115,7 @@ def test_renderer_lines(show_text: bool, line_type: LineType, renderer_type: str

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

0 comments on commit ff75c94

Please sign in to comment.