diff --git a/README.md b/README.md index b4347e1..5a28613 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,6 @@ client = Browserbase( session = client.sessions.create( project_id=BROWSERBASE_PROJECT_ID, ) -``` - def run(playwright: Playwright) -> None: # Connect to the remote session @@ -228,6 +226,8 @@ By default requests time out after 1 minute. You can configure this with a `time which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object: ```python +import httpx + from browserbase import Browserbase # Configure the default for all requests: diff --git a/tests/test_readme.py b/tests/test_readme.py new file mode 100644 index 0000000..61fad34 --- /dev/null +++ b/tests/test_readme.py @@ -0,0 +1,25 @@ +from __future__ import annotations + +import re +from pathlib import Path + +README = Path(__file__).parent.parent / "README.md" + + +def python_blocks() -> list[str]: + return re.findall(r"```(?:py|python)\n(.*?)```", README.read_text(encoding="utf-8"), flags=re.DOTALL) + + +def test_quickstart_is_a_complete_python_block() -> None: + quickstart = next(block for block in python_blocks() if "sync_playwright" in block) + + assert "def run(playwright: Playwright) -> None:" in quickstart + assert 'if __name__ == "__main__":' in quickstart + compile(quickstart, str(README), "exec") + + +def test_timeout_example_imports_httpx() -> None: + timeout_example = next(block for block in python_blocks() if "httpx.Timeout" in block) + + assert "import httpx" in timeout_example + compile(timeout_example, str(README), "exec")