48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
import unittest
|
|||
|
|
|
||
|
|
from app.collect_skip import (
|
||
|
|
ALIAS_UNMATCHED,
|
||
|
|
LOGIN_REQUIRED,
|
||
|
|
OTHER,
|
||
|
|
classify_skip_reason,
|
||
|
|
format_skip_reason_summary,
|
||
|
|
normalize_skip_reason_counts,
|
||
|
|
skipped_stage_text,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
class CollectSkipReasonTests(unittest.TestCase):
|
||
|
|
def test_classifies_supported_and_unknown_historical_reasons(self):
|
||
|
|
self.assertEqual(ALIAS_UNMATCHED, classify_skip_reason("别名未匹配账号"))
|
||
|
|
self.assertEqual(LOGIN_REQUIRED, classify_skip_reason("采集中途掉登录:LOGIN_PAGE"))
|
||
|
|
self.assertEqual(OTHER, classify_skip_reason("NO_SESSION_COOKIE"))
|
||
|
|
self.assertEqual(OTHER, classify_skip_reason(""))
|
||
|
|
|
||
|
|
def test_unmatched_alias_has_priority_over_reason_text(self):
|
||
|
|
self.assertEqual(
|
||
|
|
ALIAS_UNMATCHED,
|
||
|
|
classify_skip_reason("账号未登录", alias_matched=False),
|
||
|
|
)
|
||
|
|
self.assertEqual(
|
||
|
|
"略过 · 别名未匹配",
|
||
|
|
skipped_stage_text("", alias_matched=False),
|
||
|
|
)
|
||
|
|
|
||
|
|
def test_summary_fills_unclassified_count_as_other(self):
|
||
|
|
counts = normalize_skip_reason_counts(
|
||
|
|
{ALIAS_UNMATCHED: 2, LOGIN_REQUIRED: 1},
|
||
|
|
skipped_total=4,
|
||
|
|
)
|
||
|
|
self.assertEqual(1, counts[OTHER])
|
||
|
|
self.assertEqual(
|
||
|
|
"略过4:别名未匹配2,账号未登录1,其他原因1",
|
||
|
|
format_skip_reason_summary(counts, skipped_total=4),
|
||
|
|
)
|
||
|
|
|
||
|
|
def test_zero_skips_has_no_empty_summary(self):
|
||
|
|
self.assertEqual("", format_skip_reason_summary({}, skipped_total=0))
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
unittest.main()
|