Repository navigation
test(browser): mount the upstream E2E app's sibling files #2145
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,15 +9,13 @@ | |
| PYTHONPATH=../packages/browser/upstream-e2e .venv/bin/python -m pytest \ | ||
| -p stlite_upstream_e2e e2e_playwright/st_button_test.py \ | ||
| --browser chromium -n 4 --dist loadscope | ||
|
|
||
| Only the test's own script is mounted, so modules whose app reads | ||
| sibling files (multipage `pages/`, `static/` assets) don't work yet. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import mimetypes | ||
| import re | ||
| import sys | ||
| from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer | ||
| from pathlib import Path | ||
|
|
@@ -97,6 +95,29 @@ def page(self, context: Any, request: pytest.FixtureRequest) -> Any: | |
| } | ||
|
|
||
|
|
||
| def _app_files(script: Path) -> dict[str, dict[str, str]]: | ||
| app_dir = script.parent | ||
| skipped_dirs = {"__snapshots__", "__pycache__", "test-results"} | ||
| # `static/` is most of the directory's size, so only apps naming it get it. | ||
| # `./app/static/` URLs don't count, since Stlite doesn't serve them (#2143). | ||
| if not re.search(r"(?<!app/)static", script.read_text()): | ||
| skipped_dirs.add("static") | ||
|
Comment on lines
+103
to
+104
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Check mounted files before excluding If a helper or a script in 🤖 Prompt for AI Agents |
||
| files = {} | ||
| for path in app_dir.rglob("*"): | ||
| relative = path.relative_to(app_dir) | ||
| if ( | ||
| not path.is_file() | ||
| or path.name.endswith("_test.py") | ||
| or not skipped_dirs.isdisjoint(relative.parts) | ||
| or any( | ||
| part.startswith(".") and part != ".streamlit" for part in relative.parts | ||
| ) | ||
| ): | ||
| continue | ||
| files[relative.as_posix()] = {"url": f"/_app/{relative.as_posix()}"} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Encode file paths used as URLs. If a sibling filename contains 🤖 Prompt for AI Agents |
||
| return files | ||
|
|
||
|
|
||
| def pytest_collection_modifyitems(items: list[pytest.Item]) -> None: | ||
| for item in items: | ||
| test_id = f"{item.path.name}::{item.name.split('[')[0]}" | ||
|
|
@@ -171,7 +192,7 @@ def start_app_server( | |
| } | ||
| options = { | ||
| "entrypoint": script.name, | ||
| "files": {script.name: {"url": f"/_app/{script.name}"}}, | ||
| "files": _app_files(script), | ||
| "streamlitConfig": config, | ||
| "env": extra_env or {}, | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Read the script as UTF-8.
If the system default encoding cannot decode a UTF-8 script,
script.read_text()raises before the app server starts. Passencoding="utf-8"so file discovery does not depend on the host locale. Based on learnings, Python file reads should specify UTF-8 becausePYTHONIOENCODINGdoes not control file I/O.🤖 Prompt for AI Agents
Source: Learnings