code: def test_altair_mock(mock_name, img_tolerance, delay):
      # Build Jupytext Markdown text containing the mock's code
      mock_path = altair_mocks_dir / mock_name / "mock.py"
      actions = load_actions(mock_name)
  
      mock_code = mock_path.read_text()
      altair_markdown = altair_markdown_template.replace(
          "{code}", mock_code
      )
      vegafusion_mime_markdown = (
          vegafusion_mime_markdown_template.replace("{code}", mock_code)
      )
  
      # Use jupytext to convert markdown to an ipynb file
      altair_notebook = jupytext.read(
          io.StringIO(altair_markdown), fmt="markdown"
      )
      vegafusion_mime_notebook = jupytext.read(
          io.StringIO(vegafusion_mime_markdown), fmt="markdown"
      )
  
      # Create selenium Chrome instance
      chrome_opts = webdriver.ChromeOptions()
  
      if os.environ.get("VEGAFUSION_TEST_HEADLESS"):
          chrome_opts.add_argument("--headless")
  
      if platform.system() == "Linux":
          chrome_opts.add_argument("--disable-dev-shm-usage")
          chrome_opts.add_argument("--no-sandbox")
  
      chrome_opts.set_capability(
          "goog:loggingPrefs", {"browser": "ALL"}
      )
      chrome_driver = webdriver.Chrome(options=chrome_opts)
      chrome_driver.set_window_size(800, 800)
  
      # Launch Voila server
      voila_proc = Popen(
          ["voila", "--no-browser", "--enable_nbextensions=True"],
          cwd=temp_notebooks_dir,
      )
  
      # Sleep to allow Voila itself to start (this does not include loading a particular dashboard).
      time.sleep(1.0)
  
      try:
          name = mock_name.replace("/", "-")
          altair_imgs = export_image_sequence(
              chrome_driver,
              altair_notebook,
              name + "_altair",
              actions,
              delay,
          )
          vegafusion_mime_imgs = export_image_sequence(
              chrome_driver,
              vegafusion_mime_notebook,
              name + "_vegafusion_mime",
              actions,
              delay,
          )
  
          for i in range(len(altair_imgs)):
              altair_img = altair_imgs[i]
              vegafusion_mime_img = vegafusion_mime_imgs[i]
  
              assert (
                  altair_img.shape == vegafusion_mime_img.shape
              ), "Size mismatch with mime renderer"
  
              similarity_mime_value = ssim(
                  altair_img, vegafusion_mime_img, channel_axis=2
              )
              print(
                  f"({i}) similarity_mime_value={similarity_mime_value}"
              )
  
              # Allow slightly more image tolerance for mime renderer as floating point differences may
              # be introduced by pre-transform process
              mime_image_tolerance = img_tolerance * 0.99
              assert (
                  similarity_mime_value >= mime_image_tolerance
              ), f"Similarity failed with mime renderer on image {i}"
  
      finally:
          voila_proc.kill()
          chrome_driver.close()
          time.sleep(0.25)
  
imports: from pathlib import Path
  import jupytext
  import io
  import tempfile
  from subprocess import Popen
  import pytest
  from selenium.webdriver import ActionChains
  from selenium import webdriver
  import time
  from io import BytesIO
  from skimage.io import imread
  from skimage.metrics import structural_similarity
  import shutil
  from tenacity import retry, wait, stop
  import os
  from flaky import flaky
  import json
  import platform
label_desc: Use image node_id 2 for calling a global function with example usage: test_altair_mock(mock_name, img_tolerance, delay) without return types