style: apply ruff format across the codebase

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Mathew Sir Guest the best 2026-07-08 23:12:23 -06:00
parent 5ec5ad615a
commit 68978a34e7
10 changed files with 62 additions and 47 deletions

@ -31,9 +31,7 @@ from .pacing import HumanPacing
LOGGER = logging.getLogger("wabot")
# attributes that must never be delegated to the page
_OWN_ATTRS = frozenset(
{"driver", "pacing", "session_name", "good", "page", "_store"}
)
_OWN_ATTRS = frozenset({"driver", "pacing", "session_name", "good", "page", "_store"})
def _refused(*_args, **_kwargs):
@ -69,9 +67,7 @@ class Browser:
if name in _OWN_ATTRS or name.startswith("__"):
raise AttributeError(name)
if self.page is None:
raise AttributeError(
f"{name!r}: no current page — call set_page() first"
)
raise AttributeError(f"{name!r}: no current page — call set_page() first")
if not self.good:
LOGGER.warning("broken state — refusing page action %r (call reset())", name)
return _refused

@ -72,9 +72,7 @@ class Page:
LOGGER.warning("element not in page map: %s", key)
return NullField(name=key)
if not isinstance(locators, (tuple, list)) or len(locators) < 2:
LOGGER.error(
"malformed element %r: expected (type, accessors), got %r", key, locators
)
LOGGER.error("malformed element %r: expected (type, accessors), got %r", key, locators)
return NullField(name=key)
obj_type, accessors = locators[0], locators[1]
# built-in types need a (by, value) accessors pair; a custom field class

@ -26,9 +26,7 @@ def pytest_collection_modifyitems(items):
@pytest.fixture(scope="session")
def site_url():
"""Serve tests/fixtures over HTTP on an ephemeral port."""
handler = functools.partial(
http.server.SimpleHTTPRequestHandler, directory=str(FIXTURES)
)
handler = functools.partial(http.server.SimpleHTTPRequestHandler, directory=str(FIXTURES))
server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), handler)
thread = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()

@ -17,7 +17,8 @@ def external_chromedriver():
pytest.skip("chromedriver not on PATH")
proc = subprocess.Popen(
[binary, "--port=19515"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
url = "http://127.0.0.1:19515"
deadline = time.monotonic() + 15
@ -31,8 +32,12 @@ def external_chromedriver():
def test_persistent_session_on_external_host(external_chromedriver, site_url, store):
bot = wabot.browser(
session="ext", browser="chromium", host=external_chromedriver,
headless=True, pacing=wabot.NoPacing(), store=store,
session="ext",
browser="chromium",
host=external_chromedriver,
headless=True,
pacing=wabot.NoPacing(),
store=store,
)
bot.driver.get(f"{site_url}/welcome.html")
record = store.get("ext")
@ -50,8 +55,11 @@ def test_persistent_session_on_external_host(external_chromedriver, site_url, st
def test_ephemeral_on_external_host(external_chromedriver, site_url, store):
bot = wabot.browser(
host=external_chromedriver, browser="chromium",
headless=True, pacing=wabot.NoPacing(), store=store,
host=external_chromedriver,
browser="chromium",
headless=True,
pacing=wabot.NoPacing(),
store=store,
)
bot.driver.get(f"{site_url}/welcome.html")
assert store.names() == [] # session=None never persists

@ -28,8 +28,11 @@ REATTACH_SCRIPT = textwrap.dedent(
@pytest.mark.parametrize("browser_name", BROWSERS)
def test_second_process_picks_up_saved_browser(browser_name, site_url, store, tmp_path):
bot = wabot.browser(
session="flagship", browser=browser_name, headless=True,
pacing=wabot.NoPacing(), store=store,
session="flagship",
browser=browser_name,
headless=True,
pacing=wabot.NoPacing(),
store=store,
)
try:
bot.driver.get(f"{site_url}/login.html")
@ -41,7 +44,10 @@ def test_second_process_picks_up_saved_browser(browser_name, site_url, store, tm
result = subprocess.run(
[sys.executable, "-c", REATTACH_SCRIPT, str(store.path), "flagship"],
capture_output=True, text=True, timeout=120, check=True,
capture_output=True,
text=True,
timeout=120,
check=True,
)
payload = json.loads(result.stdout.strip().splitlines()[-1])
assert payload["url"] == f"{site_url}/login.html"
@ -54,8 +60,11 @@ def test_destroyed_session_is_really_gone(site_url, store):
from wabot.hosts import service_alive
bot = wabot.browser(
session="doomed", browser="chromium", headless=True,
pacing=wabot.NoPacing(), store=store,
session="doomed",
browser="chromium",
headless=True,
pacing=wabot.NoPacing(),
store=store,
)
bot.driver.get(f"{site_url}/login.html")
record = store.get("doomed")

@ -158,11 +158,17 @@ class TestResourceCleanup:
stopped = []
monkeypatch.setattr(wabot, "stop_service", lambda pid: stopped.append(pid))
store.save(wabot.SessionRecord(
name="s1", executor_url="http://127.0.0.1:7777", session_id="old",
browser="chromium", created_at=datetime.now(timezone.utc).isoformat(),
service_pid=9999, service_port=7777,
))
store.save(
wabot.SessionRecord(
name="s1",
executor_url="http://127.0.0.1:7777",
session_id="old",
browser="chromium",
created_at=datetime.now(timezone.utc).isoformat(),
service_pid=9999,
service_port=7777,
)
)
fake_selenium.service_alive.return_value = True
fake_selenium.attach.return_value = None # session dead on a live server
wabot.browser(session="s1", store=store)
@ -176,8 +182,11 @@ class TestDestroyEdges:
from datetime import datetime, timezone
defaults = dict(
name="s1", executor_url="http://127.0.0.1:7777", session_id="old",
browser="chromium", created_at=datetime.now(timezone.utc).isoformat(),
name="s1",
executor_url="http://127.0.0.1:7777",
session_id="old",
browser="chromium",
created_at=datetime.now(timezone.utc).isoformat(),
)
defaults.update(kw)
store.save(wabot.SessionRecord(**defaults))

@ -73,9 +73,7 @@ class TestGetProxy:
browser = make_browser()
page = BasePage(browser)
result = page["rows"]
browser.driver.find_elements.assert_called_once_with(
by="css selector", value="tr.row"
)
browser.driver.find_elements.assert_called_once_with(by="css selector", value="tr.row")
assert result is browser.driver.find_elements.return_value
def test_unknown_key_returns_falsy_nullfield(self):

@ -16,9 +16,7 @@ class TestReattachingRemote:
assert isinstance(driver.caps, dict)
def test_works_for_firefox_options_too(self):
driver = ReattachingRemote(
"http://127.0.0.1:1", "sid", options=build_options("firefox")
)
driver = ReattachingRemote("http://127.0.0.1:1", "sid", options=build_options("firefox"))
assert driver.session_id == "sid"

@ -62,7 +62,8 @@ class TestChromiumPath:
assert Image.open(out).size == (100, 150)
# scrolled at least twice beyond the initial position
scroll_calls = [
c for c in driver.execute_script.call_args_list
c
for c in driver.execute_script.call_args_list
if c.args and str(c.args[0]).startswith("window.scrollTo")
]
assert len(scroll_calls) >= 2