|
| 1 | +import marimo |
| 2 | + |
| 3 | +__generated_with = "0.23.14" |
| 4 | +app = marimo.App(width="medium") |
| 5 | + |
| 6 | + |
| 7 | +@app.cell |
| 8 | +def _(): |
| 9 | + import marimo as mo |
| 10 | + |
| 11 | + return (mo,) |
| 12 | + |
| 13 | + |
| 14 | +@app.cell |
| 15 | +def _(mo): |
| 16 | + mo.md(r""" |
| 17 | + # Toast error formatting smoke test |
| 18 | +
|
| 19 | + Trigger each case and check: wrapping, scrolling, text selection, and copy. |
| 20 | + """) |
| 21 | + return |
| 22 | + |
| 23 | + |
| 24 | +@app.cell |
| 25 | +def cases(mo): |
| 26 | + from html import escape |
| 27 | + |
| 28 | + LONG_PATH = ( |
| 29 | + "/Users/example/Library/Caches/ms-playwright/" |
| 30 | + "chromium_headless_shell-1200/" |
| 31 | + "chrome-headless-shell-mac-arm64/chrome-headless-shell" |
| 32 | + ) |
| 33 | + PLAYWRIGHT_ERR = f"""\ |
| 34 | +BrowserType.launch: Executable doesn't exist at {LONG_PATH} |
| 35 | +╔════════════════════════════════════════════════════════════╗ |
| 36 | +║ Looks like Playwright was just installed or updated. ║ |
| 37 | +║ Please run the following command to download new browsers: ║ |
| 38 | +║ ║ |
| 39 | +║ playwright install ║ |
| 40 | +║ ║ |
| 41 | +║ <3 Playwright Team ║ |
| 42 | +╚════════════════════════════════════════════════════════════╝""" |
| 43 | + LONG_STACK = """\ |
| 44 | +Traceback (most recent call last): |
| 45 | + File "/Users/example/src/marimo/marimo/_server/export/_pdf_raster.py", line 601, in rasterize |
| 46 | + async with async_playwright() as playwright: |
| 47 | + File "/Users/example/src/marimo/marimo/_server/api/endpoints/export.py", line 142, in export_as_pdf |
| 48 | + pdf_bytes = await export_pdf(request) |
| 49 | + File "/Users/example/.local/share/uv/tools/marimo/lib/python3.12/site-packages/playwright/_impl/_connection.py", line 59, in send |
| 50 | + return await self._inner_send(method, dict(params), False) |
| 51 | +playwright._impl._errors.Error: BrowserType.launch: Executable doesn't exist |
| 52 | +""" |
| 53 | + |
| 54 | + def fire_toast( |
| 55 | + title: str, description: str, *, as_html: bool = False, kind="danger" |
| 56 | + ): |
| 57 | + if as_html: |
| 58 | + description = f'<pre style="margin:0;white-space:pre-wrap;word-break:break-word">{escape(description)}</pre>' |
| 59 | + mo.status.toast(title, description, kind) |
| 60 | + |
| 61 | + cases = mo.ui.dropdown( |
| 62 | + options={ |
| 63 | + "short": "short", |
| 64 | + "long path (single line)": "long_path", |
| 65 | + "playwright ascii box (plain)": "playwright_plain", |
| 66 | + "playwright ascii box (html pre)": "playwright_html", |
| 67 | + "tall traceback (plain)": "tall_plain", |
| 68 | + "tall traceback (html pre)": "tall_html", |
| 69 | + "success (control)": "success", |
| 70 | + }, |
| 71 | + value="playwright ascii box (plain)", |
| 72 | + label="Error shape", |
| 73 | + ) |
| 74 | + |
| 75 | + fire = mo.ui.run_button(label="Show toast") |
| 76 | + mo.hstack([cases, fire], justify="start", gap=1) |
| 77 | + return LONG_PATH, LONG_STACK, PLAYWRIGHT_ERR, cases, fire, fire_toast |
| 78 | + |
| 79 | + |
| 80 | +@app.cell |
| 81 | +def trigger(LONG_PATH, LONG_STACK, PLAYWRIGHT_ERR, cases, fire, fire_toast, mo): |
| 82 | + if fire.value: |
| 83 | + choice = cases.value |
| 84 | + if choice == "short": |
| 85 | + fire_toast("Failed to download", "Something went wrong.") |
| 86 | + elif choice == "long_path": |
| 87 | + fire_toast( |
| 88 | + "Failed to download", |
| 89 | + f"BrowserType.launch: Executable doesn't exist at {LONG_PATH}", |
| 90 | + ) |
| 91 | + elif choice == "playwright_plain": |
| 92 | + fire_toast("Failed to download", PLAYWRIGHT_ERR) |
| 93 | + elif choice == "playwright_html": |
| 94 | + fire_toast("Failed to download", PLAYWRIGHT_ERR, as_html=True) |
| 95 | + elif choice == "tall_plain": |
| 96 | + fire_toast("Failed to download", LONG_STACK) |
| 97 | + elif choice == "tall_html": |
| 98 | + fire_toast("Failed to download", LONG_STACK, as_html=True) |
| 99 | + elif choice == "success": |
| 100 | + mo.status.toast("All good", "This is a short success toast.") |
| 101 | + return |
| 102 | + |
| 103 | + |
| 104 | +if __name__ == "__main__": |
| 105 | + app.run() |
0 commit comments