From 0d9579d56d3fcaffbb892531ce560e88e0f136a8 Mon Sep 17 00:00:00 2001 From: Nanaloveyuki Date: Sun, 27 Jul 2025 21:53:12 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20`fmt`=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=B5=8B=E8=AF=95=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/t-fmt.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/t-fmt.py diff --git a/tests/t-fmt.py b/tests/t-fmt.py new file mode 100644 index 0000000..d810d48 --- /dev/null +++ b/tests/t-fmt.py @@ -0,0 +1,50 @@ +import sys +from pathlib import Path + +project_root = Path(__file__).parent.parent +sys.path.append(str(project_root)) + +from src.utils.fmt import fmt_level, fmt_level_number, fmt_console, fmt_message, fmt_placeholder + +print("日志级别测试") +print(fmt_level("DEBUG")) +print(fmt_level("INFO")) +print(fmt_level("WARN")) +print(fmt_level("ERRO")) +print(fmt_level("CRIT")) +print(fmt_level("UNKN")) + +print("日志级别数字测试") +print(fmt_level_number(10)) +print(fmt_level_number(20)) +print(fmt_level_number(30)) +print(fmt_level_number(40)) +print(fmt_level_number(50)) +print(fmt_level_number(-1)) +print(fmt_level_number(100)) + +print("消息格式化测试") +print(fmt_message("测试消息: {time},\n {asctime}, \n{unknown}")) + +print("控制台格式化测试") +print(fmt_console(10, "测试消息")) +print("前缀测试") +print(fmt_console(35, "测试消息", "可爱猫猫")) + +print("未知日志级别测试") +print(fmt_console(-1, "测试消息")) + + +print("颜色插值测试") +print("分段颜色插值") +formatted_msg = fmt_message("测试消息<#ff0000>red") +processed_msg = fmt_placeholder(formatted_msg) +print(fmt_console(15, processed_msg)) + +print("单段颜色插值") +print(fmt_console(15, fmt_placeholder("测试消息<#00ff00>green{asctime}", use_date_color=False))) + +print("不完整颜色插值") +print(fmt_console(15, fmt_placeholder("测试消息<#00ff00>green{asctime}", use_date_color=False))) +print(fmt_console(15, fmt_placeholder("测试消息green{asctime}", use_date_color=False))) +print(fmt_console(15, fmt_placeholder("测试消息<#00ff000>green{asctime}", use_date_color=False))) \ No newline at end of file