"""Each example requires the same three tests:
- Test that the initial markup loads properly (currently done by testing the
tag's content)
- Testing that pyodide is loading properly
- Testing that the page contains appropriate content after rendering
The single function iterates through the examples, instantiates one playwright browser
session per example, and runs all three of each example's tests in that same browser
session.
"""
import math
import re
import time
from urllib.parse import urljoin
import pytest
MAX_TEST_TIME = 30 # Number of seconds allowed for checking a testing condition
TEST_TIME_INCREMENT = 0.25 # 1/4 second, the length of each iteration
TEST_ITERATIONS = math.ceil(
MAX_TEST_TIME / TEST_TIME_INCREMENT
) # 120 iters of 1/4 second
# Content that is displayed in the page while pyodide loads
LOADING_MESSAGES = [
"Loading runtime...",
"Runtime created...",
"Initializing components...",
"Initializing scripts...",
]
EXAMPLES = [
"altair",
"bokeh",
"bokeh_interactive",
"d3",
"folium",
"hello_world",
"matplotlib",
"numpy_canvas_fractals",
"panel",
"panel_deckgl",
"panel_kmeans",
"panel_stream",
"repl",
"repl2",
"simple_clock",
"todo",
"todo_pylist",
"toga_freedom",
"webgl_raycaster_index",
]
TEST_PARAMS = {
"altair": {
"file": "altair.html",
"pattern": '',
"title": "Altair",
},
"bokeh": {
"file": "bokeh.html",
"pattern": '',
"title": "Bokeh Example",
},
"bokeh_interactive": {
"file": "bokeh_interactive.html",
"pattern": '',
"title": "Bokeh Example",
},
"d3": {
"file": "d3.html",
"pattern": "",
"title": "d3: JavaScript & PyScript visualizations side-by-side",
},
"folium": {"file": "folium.html", "pattern": "