Files
grok-register/tests/test_pending_recovery.py
Aaron LiangandGitHub 4b030214d9 docs: clarify Python module responsibilities
Rewrite the module-level descriptions for all 28 Python files and remove the obsolete integration note from grok_register_ttk.py. Verified on Python 3.9 and Python 3.12.
2026-07-15 12:26:57 +08:00

38 lines
1.5 KiB
Python

"""验证 pending 账号恢复的去重、锁、原子更新和异常处理。"""
import json
import os
import tempfile
import unittest
from account_outputs import retry_pending_file
class PendingRecoveryTests(unittest.TestCase):
def test_retry_is_idempotent_after_target_was_already_written(self):
with tempfile.TemporaryDirectory() as directory:
pending = os.path.join(directory, "accounts.txt.pending.jsonl")
target = os.path.join(directory, "accounts.txt")
record = {"email": "a@example.com", "password": "pw", "sso": "token"}
with open(pending, "w", encoding="utf-8") as handle:
handle.write(json.dumps(record) + "\n")
with open(target, "w", encoding="utf-8") as handle:
handle.write("a@example.com----pw----token\n")
summary = retry_pending_file(pending)
self.assertEqual(summary["restored"], 1)
with open(target, "r", encoding="utf-8") as handle:
self.assertEqual(handle.readlines(), ["a@example.com----pw----token\n"])
self.assertFalse(os.path.exists(pending))
def test_rejects_same_input_and_output_path(self):
with tempfile.TemporaryDirectory() as directory:
pending = os.path.join(directory, "pending.jsonl")
with open(pending, "w", encoding="utf-8") as handle:
handle.write("{}\n")
with self.assertRaises(ValueError):
retry_pending_file(pending, output_path=pending)
if __name__ == "__main__":
unittest.main()