Files
douyin_guaji-main/tests/test_reservation_modules.py
T
CodexandClaude Opus 4.5 73008a9763 补 douyin/reservation 模块单元测试(+23 用例)
- _compact_text 纯函数测试(空格/中文/边界值)
- match_reservation / validate_back_to_reservation 函数签名验证
- reservation_handler shim 与子模块导出一致性验证
- reservation 子模块存在性测试

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-05-21 22:09:35 +08:00

170 lines
5.5 KiB
Python

"""douyin/reservation 模块单元测试。
覆盖:
- douyin_reservation_verify: _compact_text 纯函数
- douyin_reservation: 文件操作函数签名验证
- reservation shim 与子模块导出一致性
"""
from __future__ import annotations
import pytest
class TestCompactText:
"""_compact_text 纯函数测试。"""
def test_removes_spaces(self):
from douyin.reservation.douyin_reservation_verify import _compact_text
result = _compact_text("hello world")
assert result == "helloworld"
def test_removes_multiple_spaces(self):
from douyin.reservation.douyin_reservation_verify import _compact_text
result = _compact_text("hello world test")
assert result == "helloworldtest"
def test_removes_tabs_and_newlines(self):
from douyin.reservation.douyin_reservation_verify import _compact_text
result = _compact_text("hello\tworld\ntest")
assert result == "helloworldtest"
def test_empty_string(self):
from douyin.reservation.douyin_reservation_verify import _compact_text
result = _compact_text("")
assert result == ""
def test_none_input(self):
from douyin.reservation.douyin_reservation_verify import _compact_text
result = _compact_text(None)
assert result == ""
def test_only_spaces(self):
from douyin.reservation.douyin_reservation_verify import _compact_text
result = _compact_text(" ")
assert result == ""
def test_chinese_text(self):
from douyin.reservation.douyin_reservation_verify import _compact_text
result = _compact_text("福袋 内容 测试")
assert result == "福袋内容测试"
class TestMatchReservation:
"""match_reservation 函数测试。"""
def test_function_exists(self):
from douyin.reservation.douyin_reservation_verify import match_reservation
assert callable(match_reservation)
def test_returns_tuple(self):
from douyin.reservation.douyin_reservation_verify import match_reservation
# 构造一个简单的 item 和 detail
item = {"content": "test", "value": 10.0}
detail = ("test", "5:00", 100, 10, 10.0, (300, 1700000000))
result = match_reservation(item, detail)
assert isinstance(result, tuple)
assert len(result) == 3
class TestValidateBackToReservation:
"""validate_back_to_reservation 函数测试。"""
def test_function_exists(self):
from douyin.reservation.douyin_reservation_verify import validate_back_to_reservation
assert callable(validate_back_to_reservation)
class TestDouyinReservation:
"""douyin_reservation 模块测试。"""
def test_write_reservations_state_exists(self):
from douyin.reservation.douyin_reservation import write_reservations_state
assert callable(write_reservations_state)
def test_load_high_value_rooms_map_exists(self):
from douyin.reservation.douyin_reservation import load_high_value_rooms_map
assert callable(load_high_value_rooms_map)
def test_write_high_value_rooms_state_exists(self):
from douyin.reservation.douyin_reservation import write_high_value_rooms_state
assert callable(write_high_value_rooms_state)
class TestReservationLogicHelpers:
"""reservation_logic 子模块测试。"""
def test_helpers_module_importable(self):
from douyin.reservation.reservation_logic import helpers
assert helpers is not None
def test_calculate_string_similarity_exists(self):
from douyin.reservation.reservation_logic.helpers import _calculate_string_similarity
assert callable(_calculate_string_similarity)
def test_normalize_room_title_exists(self):
from douyin.reservation.reservation_logic.helpers import _normalize_room_title_for_matching
assert callable(_normalize_room_title_for_matching)
class TestReservationHandlerShimConsistency:
"""验证 reservation_handler shim 与子模块导出一致。"""
def test_find_room_pos_by_title_same_object(self):
from douyin.reservation.douyin_reservation_handler import find_room_pos_by_title as f1
from douyin.reservation.douyin_reservation_handler_pkg import find_room_pos_by_title as f2
assert f1 is f2
def test_record_room_title_and_pos_same_object(self):
from douyin.reservation.douyin_reservation_handler import record_room_title_and_pos as f1
from douyin.reservation.douyin_reservation_handler_pkg import record_room_title_and_pos as f2
assert f1 is f2
def test_seek_reservation_room_same_object(self):
from douyin.reservation.douyin_reservation_handler import seek_reservation_room as f1
from douyin.reservation.douyin_reservation_handler_pkg import seek_reservation_room as f2
assert f1 is f2
class TestReservationModules:
"""reservation 子模块存在性测试。"""
def test_douyin_reservation_importable(self):
from douyin.reservation import douyin_reservation
assert douyin_reservation is not None
def test_douyin_reservation_handler_importable(self):
from douyin.reservation import douyin_reservation_handler
assert douyin_reservation_handler is not None
def test_douyin_reservation_logic_importable(self):
from douyin.reservation import douyin_reservation_logic
assert douyin_reservation_logic is not None
def test_douyin_reservation_verify_importable(self):
from douyin.reservation import douyin_reservation_verify
assert douyin_reservation_verify is not None