38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
class _FakeOperation:
|
|
def __init__(self, log_path):
|
|
self._screenshot_log_path = str(log_path)
|
|
self._screenshot_call_cache = []
|
|
|
|
def _get_screenshot_direct(self, _device_id, _path):
|
|
return True
|
|
|
|
|
|
def test_screenshot_trace_is_off_by_default(tmp_path, monkeypatch):
|
|
from douyin.core.underlying_operations_pkg.screenshot_pipeline import get_screenshot
|
|
|
|
monkeypatch.delenv("DOUYIN_SCREENSHOT_TRACE", raising=False)
|
|
op = _FakeOperation(tmp_path / "screenshot_calls.jsonl")
|
|
|
|
assert get_screenshot(op, "device1") is True
|
|
|
|
assert not (tmp_path / "screenshot_calls.jsonl").exists()
|
|
assert op._screenshot_call_cache == []
|
|
assert op._screenshot_trace_disabled_logged is True
|
|
|
|
|
|
def test_screenshot_trace_can_be_enabled_for_diagnostics(tmp_path, monkeypatch):
|
|
from douyin.core.underlying_operations_pkg.screenshot_pipeline import get_screenshot
|
|
|
|
monkeypatch.setenv("DOUYIN_SCREENSHOT_TRACE", "1")
|
|
op = _FakeOperation(tmp_path / "screenshot_calls.jsonl")
|
|
|
|
assert get_screenshot(op, "device1", path="pic") is True
|
|
|
|
lines = (tmp_path / "screenshot_calls.jsonl").read_text(encoding="utf-8").splitlines()
|
|
assert len(lines) == 2
|
|
assert '"phase": "start"' in lines[0]
|
|
assert '"phase": "end"' in lines[1]
|
|
assert len(op._screenshot_call_cache) == 2
|