Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ async def fake_shutdown_chrome():
monkeypatch.setattr(moon_extract, "close_browser", fake_close_browser)
monkeypatch.setattr(moon_extract, "shutdown_chrome", fake_shutdown_chrome)

# Both front-ends import their own copy of each of these names, so both
# must be patched here -- patching only one leaves the other holding the
# real implementation, invisibly, until something exercises it.
for host in (moon_engine, moon_cli):
monkeypatch.setattr(host, "extract_fuckingfast", fake_ff)
monkeypatch.setattr(host, "extract_datanodes", fake_dn)
monkeypatch.setattr(host, "close_ff_session", lambda: asyncio.sleep(0))
monkeypatch.setattr(moon_cli, "download_file", fake_download)
monkeypatch.setattr(host, "download_file", fake_download)

return calls
22 changes: 18 additions & 4 deletions tests/test_no_chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
)


def run_engine(engine, urls, retries=1) -> dict:
def run_engine(engine, urls, retries=1, mode="links") -> dict:
res = engine.start(
{
"links": urls,
"mode": "links",
"mode": mode,
"out_folder": str(ROOT / "_tmp_out"),
"workers": 4,
"dl_streams": 4,
Expand All @@ -45,7 +45,7 @@ def run_engine(engine, urls, retries=1) -> dict:
time.sleep(0.15)

metrics = engine.snapshot(0)["metrics"]
return {"ok": metrics["ok"], "fail": metrics["fail"]}
return {"ok": metrics["ok"], "fail": metrics["fail"], "dl_done": metrics["dl_done"]}


def run_cli(urls, retries=1) -> None:
Expand Down Expand Up @@ -95,6 +95,20 @@ def test_engine_mixed_batch_launches_one_shared_browser(browser_calls):
cleanup()


def test_engine_download_mode_uses_stubbed_download_file(browser_calls):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The download mode test here is a good addition — I forgot to add this test in my #162 (sorry).

# moon_engine imports download_file straight from moon_download, a
# separate name from moon_cli's. If the fixture only patches moon_cli's
# copy, this hits the real downloader against a fake URL instead of the
# stub -- see #160.
engine = moon_engine.Engine()
try:
result = run_engine(engine, FF, mode="download")
assert result == {"ok": len(FF), "fail": 0, "dl_done": len(FF)}
assert_browser_counts(browser_calls, want_browsers=0)
finally:
cleanup()


def test_engine_unsupported_host_fails_once_without_browser(browser_calls):
engine = moon_engine.Engine()

Expand All @@ -104,7 +118,7 @@ def test_engine_unsupported_host_fails_once_without_browser(browser_calls):
messages = [message for message, _tag in snapshot["log"]]
record = engine._tracked[UNSUPPORTED[0]]

assert result == {"ok": 0, "fail": 1}
assert result == {"ok": 0, "fail": 1, "dl_done": 0}
assert browser_calls["open_browser"] == 0
assert browser_calls["playwright"] == 0
assert record.status == "fail"
Expand Down