Fix fudai countdown and room mapping guards
This commit is contained in:
1 parent
d6312d8813
commit
ec51772cf0
9 files changed
+153
-18
No files matched your search
@@ -104,10 +104,23 @@ class TestCutDetailRegions:
|
||||
|
||||
mm_call = a.cut_pic.call_args_list[1]
|
||||
ss_call = a.cut_pic.call_args_list[2]
|
||||
assert mm_call.args[1] == 1340
|
||||
assert mm_call.args[3] == 1371
|
||||
assert ss_call.args[1] == 1340
|
||||
assert ss_call.args[3] == 1371
|
||||
assert mm_call.args[1] == 1351
|
||||
assert mm_call.args[3] == 1392
|
||||
assert ss_call.args[1] == 1351
|
||||
assert ss_call.args[3] == 1392
|
||||
|
||||
def test_v2_two_task_tall_profile_uses_lower_digit_band(self):
|
||||
a = _mk_analyser()
|
||||
profile = {"countdown_full": (760, 1265, 1040, 1398)}
|
||||
|
||||
cut_detail_regions(a, renwu=2, profile=profile)
|
||||
|
||||
mm_call = a.cut_pic.call_args_list[1]
|
||||
ss_call = a.cut_pic.call_args_list[2]
|
||||
assert mm_call.args[1] >= 1310
|
||||
assert mm_call.args[3] >= 1385
|
||||
assert ss_call.args[1] == mm_call.args[1]
|
||||
assert ss_call.args[3] == mm_call.args[3]
|
||||
|
||||
def test_save_debug_images_disabled_default(self):
|
||||
a = _mk_analyser()
|
||||
|
||||
@@ -30,7 +30,7 @@ def test_v2_profile_keeps_legacy_and_adds_expected_regions(monkeypatch):
|
||||
assert DETAIL_UI_LEGACY["content"] == (389, 1273, 1000, 1534)
|
||||
assert DETAIL_UI_V2_0["content"] == (365, 1368, 1040, 1465)
|
||||
assert DETAIL_UI_V2_0["value"] == (300, 1518, 820, 1695)
|
||||
assert DETAIL_UI_V2_0["countdown_full"] == (760, 1265, 1040, 1345)
|
||||
assert DETAIL_UI_V2_0["countdown_full"] == (760, 1265, 1040, 1398)
|
||||
assert DETAIL_UI_V2_0["task_list"] == (60, 1840, 1030, 2005)
|
||||
assert DETAIL_UI_V2_0["task_count"] == (860, 1770, 1035, 1875)
|
||||
assert DETAIL_UI_V2_0["participants"] == (520, 1325, 760, 1415)
|
||||
@@ -175,6 +175,33 @@ def test_v2_two_task_value_region_covers_reference_value_line():
|
||||
assert crop_has_reference_line_text(sample) > 0.03
|
||||
|
||||
|
||||
def test_v2_two_task_countdown_region_covers_lower_countdown_line():
|
||||
from pathlib import Path
|
||||
from douyin.fudai.core.coords import DETAIL_UI_V2_0
|
||||
|
||||
samples = [
|
||||
Path("tests/fixtures/fudai_detail_v2_two_task_redmi_2999_regions.png"),
|
||||
Path("tests/fixtures/fudai_detail_v2_two_task_guohao_1199_regions.png"),
|
||||
]
|
||||
missing = [sample for sample in samples if not sample.exists()]
|
||||
if missing:
|
||||
pytest.skip("v2 two-task countdown samples are unavailable")
|
||||
|
||||
countdown_box = DETAIL_UI_V2_0["countdown_full"]
|
||||
assert countdown_box[1] <= 1328
|
||||
assert countdown_box[3] >= 1398
|
||||
|
||||
def crop_has_countdown_text(sample: Path) -> float:
|
||||
img = Image.open(sample).convert("RGB")
|
||||
crop = img.crop((760, 1328, min(countdown_box[2], 1040), min(countdown_box[3], 1398)))
|
||||
pixels = list(crop.getdata())
|
||||
bright = sum(1 for r, g, b in pixels if r > 185 and g > 185 and b > 185)
|
||||
return bright / max(1, len(pixels))
|
||||
|
||||
for sample in samples:
|
||||
assert crop_has_countdown_text(sample) > 0.02
|
||||
|
||||
|
||||
def test_ocr_switch_defaults_and_legacy_disable_compat():
|
||||
from douyin.fudai.douyin_fudai_core_pkg.ocr_switches import (
|
||||
FudaiDetailOcrSwitches,
|
||||
|
||||
@@ -173,3 +173,67 @@ def test_no_fudai_room_mapping_does_not_inherit_previous_fudai_content():
|
||||
assert info["has_fudai"] is False
|
||||
assert info["fudai_content"] == ""
|
||||
assert info["fudai_detail"] is None
|
||||
|
||||
|
||||
def test_validation_failed_detail_is_not_recorded_as_valid_fudai_mapping():
|
||||
from douyin.reservation.douyin_reservation_handler_pkg import record_title as mod
|
||||
|
||||
a = _mk_analyser()
|
||||
a.room_pos = 6
|
||||
a.current_room_title = "作业帮学万"
|
||||
a.current_room_title_raw = "作业帮学万"
|
||||
a._room_title_identified_positions = {6}
|
||||
a._current_fudai_content = "免费试用"
|
||||
a._last_fudai_detail_tuple = (
|
||||
"免费试用",
|
||||
"00:15",
|
||||
0,
|
||||
0,
|
||||
0.0,
|
||||
(100.0, 115.0),
|
||||
)
|
||||
a._last_fudai_detail_status = "validation_failed"
|
||||
|
||||
with patch.object(mod, "_dump_room_pos_map_to_state", return_value=None):
|
||||
consumed = mod.record_room_title_and_pos(a)
|
||||
|
||||
assert consumed is False
|
||||
info = a._room_pos_to_title_map[6]
|
||||
assert info["title"] == "作业帮学万"
|
||||
assert info["has_fudai"] is False
|
||||
assert info["fudai_content"] == ""
|
||||
assert info["fudai_detail"] is None
|
||||
|
||||
|
||||
def test_reservation_handler_propagates_record_consumed_swipe():
|
||||
from douyin.reservation.douyin_reservation_handler_pkg.handler import (
|
||||
ReservationHandler,
|
||||
)
|
||||
|
||||
a = _mk_analyser()
|
||||
|
||||
with patch(
|
||||
"douyin.reservation.douyin_reservation_handler_pkg.handler._record_room_title_and_pos",
|
||||
return_value=True,
|
||||
):
|
||||
assert ReservationHandler.record_room_title_and_pos(a) is True
|
||||
|
||||
|
||||
def test_room_utils_record_wrapper_propagates_consumed_swipe(monkeypatch):
|
||||
from douyin.core.fudai_modules.fudai_room_utils import RoomUtilsMixin
|
||||
|
||||
class _A(RoomUtilsMixin):
|
||||
pass
|
||||
|
||||
def fake_record(_analyser):
|
||||
return True
|
||||
|
||||
from douyin.reservation import douyin_reservation_handler
|
||||
|
||||
monkeypatch.setattr(
|
||||
douyin_reservation_handler.ReservationHandler,
|
||||
"record_room_title_and_pos",
|
||||
staticmethod(fake_record),
|
||||
)
|
||||
|
||||
assert _A()._record_room_title_and_pos() is True
|
||||
Reference in new issue
Block a user