refactor(cleanup): 移除 logging 模块死代码
- unified_logger.py: 删除 5 个从未使用的装饰器/函数 - internal_loggers.py: 删除 3 个未使用方法和工厂函数 - action_logger.py: 删除 3 个未使用方法 - log_formatter.py: 删除 6 个未使用格式化函数(保留 GUI 依赖的 4 个) - 同步更新 __init__.py 和测试文件 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
703da834fb
commit
d19d5bfc56
8 files changed
+12
-482
No files matched your search
@@ -32,21 +32,6 @@ class TestActionLoggerMethods:
|
||||
alog.log_operation("click", details="button_x", x=100, y=200)
|
||||
alog.log_operation("simple_op")
|
||||
|
||||
def test_log_decision(self, alog, caplog):
|
||||
with caplog.at_level(logging.INFO):
|
||||
alog.log_decision("参与", elapsed=0.05)
|
||||
alog.log_decision("跳过")
|
||||
|
||||
def test_log_state_change(self, alog, caplog):
|
||||
with caplog.at_level(logging.INFO):
|
||||
alog.log_state_change("recommend", "live_room", elapsed=0.5)
|
||||
alog.log_state_change("A", "B")
|
||||
|
||||
def test_log_ocr(self, alog, caplog):
|
||||
with caplog.at_level(logging.INFO):
|
||||
alog.log_ocr("countdown_region", "00:30", elapsed=0.1)
|
||||
alog.log_ocr("region", "")
|
||||
|
||||
def test_long_kwargs_does_not_raise(self, alog):
|
||||
# 大量 kwargs 不应导致格式化失败
|
||||
alog.log_operation("complex", **{f"k{i}": i for i in range(50)})
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
"""douyin/logging/log_formatter 的 pytest 单元测试。
|
||||
|
||||
覆盖 9 个格式化纯函数:
|
||||
覆盖格式化纯函数:
|
||||
- format_action_log / format_debug_log / format_error_log
|
||||
- format_parameters / format_variables / format_call_stack
|
||||
- format_exception / add_colors / add_separators
|
||||
- add_colors
|
||||
- beautify_log_output / colorize_log_line(一致性 + 不抛断言)
|
||||
"""
|
||||
from __future__ import annotations
|
||||
@@ -67,64 +66,7 @@ class TestFormatErrorLog:
|
||||
|
||||
|
||||
# ============================================================
|
||||
# format_parameters / format_variables
|
||||
# ============================================================
|
||||
|
||||
class TestFormatParametersVariables:
|
||||
def test_format_parameters_with_data(self):
|
||||
result = f.format_parameters({"a": 1, "b": "x"})
|
||||
assert "a=1" in result
|
||||
assert "b=x" in result
|
||||
|
||||
def test_format_parameters_empty(self):
|
||||
assert f.format_parameters({}) == ""
|
||||
|
||||
def test_format_variables_with_data(self):
|
||||
result = f.format_variables({"k": "v"})
|
||||
assert "k=v" in result
|
||||
|
||||
def test_format_variables_empty(self):
|
||||
assert f.format_variables({}) == ""
|
||||
|
||||
|
||||
# ============================================================
|
||||
# format_call_stack
|
||||
# ============================================================
|
||||
|
||||
class TestFormatCallStack:
|
||||
def test_empty(self):
|
||||
assert f.format_call_stack() == ""
|
||||
|
||||
def test_with_frames(self):
|
||||
result = f.format_call_stack(["frame1", "frame2"])
|
||||
assert "frame1" in result
|
||||
assert "frame2" in result
|
||||
|
||||
|
||||
# ============================================================
|
||||
# format_exception
|
||||
# ============================================================
|
||||
|
||||
class TestFormatException:
|
||||
def test_includes_traceback(self):
|
||||
try:
|
||||
raise RuntimeError("boom")
|
||||
except RuntimeError as e:
|
||||
result = f.format_exception(e)
|
||||
assert "RuntimeError" in result
|
||||
assert "boom" in result
|
||||
|
||||
def test_returns_string(self):
|
||||
try:
|
||||
raise ValueError("bad")
|
||||
except ValueError as e:
|
||||
result = f.format_exception(e)
|
||||
assert isinstance(result, str)
|
||||
assert len(result) > 0
|
||||
|
||||
|
||||
# ============================================================
|
||||
# add_colors / add_separators
|
||||
# add_colors
|
||||
# ============================================================
|
||||
|
||||
class TestAddColors:
|
||||
@@ -146,20 +88,6 @@ class TestAddColors:
|
||||
assert "hi" in result
|
||||
|
||||
|
||||
class TestAddSeparators:
|
||||
def test_with_label(self):
|
||||
result = f.add_separators("content", label="SECTION")
|
||||
assert "content" in result
|
||||
assert "SECTION" in result
|
||||
# 包含分隔线
|
||||
assert "=" * 80 in result
|
||||
|
||||
def test_without_label(self):
|
||||
result = f.add_separators("content")
|
||||
assert "content" in result
|
||||
assert "=" * 80 in result
|
||||
|
||||
|
||||
# ============================================================
|
||||
# beautify_log_output / colorize_log_line(一致性 / 不抛)
|
||||
# ============================================================
|
||||
|
||||
@@ -79,89 +79,6 @@ class TestFormatErrorLog:
|
||||
assert len(result) > 0
|
||||
|
||||
|
||||
class TestFormatCallStack:
|
||||
"""format_call_stack 纯函数测试。"""
|
||||
|
||||
def test_empty_stack(self):
|
||||
from douyin.logging.log_formatter import format_call_stack
|
||||
|
||||
result = format_call_stack(None)
|
||||
assert isinstance(result, str)
|
||||
|
||||
def test_with_stack(self):
|
||||
from douyin.logging.log_formatter import format_call_stack
|
||||
|
||||
stack = ["func1", "func2", "func3"]
|
||||
result = format_call_stack(stack)
|
||||
assert isinstance(result, str)
|
||||
|
||||
|
||||
class TestFormatParameters:
|
||||
"""format_parameters 纯函数测试。"""
|
||||
|
||||
def test_empty_params(self):
|
||||
from douyin.logging.log_formatter import format_parameters
|
||||
|
||||
result = format_parameters({})
|
||||
assert isinstance(result, str)
|
||||
|
||||
def test_with_params(self):
|
||||
from douyin.logging.log_formatter import format_parameters
|
||||
|
||||
result = format_parameters({"x": 1, "y": 2})
|
||||
assert isinstance(result, str)
|
||||
|
||||
|
||||
class TestFormatVariables:
|
||||
"""format_variables 纯函数测试。"""
|
||||
|
||||
def test_empty_vars(self):
|
||||
from douyin.logging.log_formatter import format_variables
|
||||
|
||||
result = format_variables({})
|
||||
assert isinstance(result, str)
|
||||
|
||||
def test_with_vars(self):
|
||||
from douyin.logging.log_formatter import format_variables
|
||||
|
||||
result = format_variables({"a": "hello", "b": 123})
|
||||
assert isinstance(result, str)
|
||||
|
||||
|
||||
class TestFormatException:
|
||||
"""format_exception 纯函数测试。"""
|
||||
|
||||
def test_value_error(self):
|
||||
from douyin.logging.log_formatter import format_exception
|
||||
|
||||
exc = ValueError("test error")
|
||||
result = format_exception(exc)
|
||||
assert "ValueError" in result or "test error" in result
|
||||
|
||||
def test_runtime_error(self):
|
||||
from douyin.logging.log_formatter import format_exception
|
||||
|
||||
exc = RuntimeError("runtime issue")
|
||||
result = format_exception(exc)
|
||||
assert isinstance(result, str)
|
||||
|
||||
|
||||
class TestAddSeparators:
|
||||
"""add_separators 纯函数测试。"""
|
||||
|
||||
def test_basic_text(self):
|
||||
from douyin.logging.log_formatter import add_separators
|
||||
|
||||
result = add_separators("test content")
|
||||
assert "test content" in result
|
||||
|
||||
def test_with_label(self):
|
||||
from douyin.logging.log_formatter import add_separators
|
||||
|
||||
result = add_separators("content", label="Section")
|
||||
assert "content" in result
|
||||
|
||||
|
||||
class TestAddColors:
|
||||
"""add_colors 纯函数测试。"""
|
||||
|
||||
|
||||
Reference in new issue
Block a user