54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
from pathlib import Path
|
|
|
|
from core.huya import browser_harvest
|
|
|
|
|
|
class _FakeStderr:
|
|
def readline(self):
|
|
return "DevTools listening on ws://127.0.0.1/devtools/browser/test\n"
|
|
|
|
|
|
class _FakeProcess:
|
|
stderr = _FakeStderr()
|
|
|
|
def kill(self):
|
|
pass
|
|
|
|
|
|
def test_launch_defaults_to_headless(monkeypatch):
|
|
calls = []
|
|
|
|
def fake_popen(args, **kwargs):
|
|
calls.append((args, kwargs))
|
|
return _FakeProcess()
|
|
|
|
def no_http(*args, **kwargs):
|
|
raise OSError("test: no CDP endpoint")
|
|
|
|
monkeypatch.setattr(browser_harvest.subprocess, "Popen", fake_popen)
|
|
monkeypatch.setattr(browser_harvest.urllib.request, "urlopen", no_http)
|
|
|
|
browser_harvest.launch(Path("/tmp/test-huya-profile"), 9555)
|
|
|
|
args, kwargs = calls[0]
|
|
assert "--headless=new" in args
|
|
assert kwargs["stdout"] is browser_harvest.subprocess.DEVNULL
|
|
|
|
|
|
def test_launch_can_show_window_when_requested(monkeypatch):
|
|
calls = []
|
|
|
|
def fake_popen(args, **kwargs):
|
|
calls.append(args)
|
|
return _FakeProcess()
|
|
|
|
def no_http(*args, **kwargs):
|
|
raise OSError("test: no CDP endpoint")
|
|
|
|
monkeypatch.setattr(browser_harvest.subprocess, "Popen", fake_popen)
|
|
monkeypatch.setattr(browser_harvest.urllib.request, "urlopen", no_http)
|
|
|
|
browser_harvest.launch(Path("/tmp/test-huya-profile"), 9556, headless=False)
|
|
|
|
assert "--headless=new" not in calls[0]
|