(verbose: bool = True)
| 376 | |
| 377 | |
| 378 | def run_tests(verbose: bool = True) -> None: |
| 379 | failed = [] |
| 380 | |
| 381 | for name, text, expected in TEST_CASES: |
| 382 | actual = normalize_tts_text(text) |
| 383 | if actual != expected: |
| 384 | failed.append((name, text, expected, actual)) |
| 385 | continue |
| 386 | |
| 387 | # 幂等性:第二次归一化不应继续改动结果 |
| 388 | second = normalize_tts_text(actual) |
| 389 | if second != actual: |
| 390 | failed.append((name + "_idempotence", actual, actual, second)) |
| 391 | |
| 392 | if failed: |
| 393 | lines = ["\nTEST FAILED:\n"] |
| 394 | for name, text, expected, actual in failed: |
| 395 | lines.append(f"[{name}]") |
| 396 | lines.append(f"input : {text}") |
| 397 | lines.append(f"expected: {expected}") |
| 398 | lines.append(f"actual : {actual}") |
| 399 | lines.append("") |
| 400 | raise AssertionError("\n".join(lines)) |
| 401 | |
| 402 | if verbose: |
| 403 | print(f"All {len(TEST_CASES)} tests passed.") |
| 404 | |
| 405 | |
| 406 | if __name__ == "__main__": |
no test coverage detected