Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion trendradar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
from trendradar.context import AppContext

__version__ = "6.7.0"
__all__ = ["AppContext", "__version__"]
__all__ = ["AppContext", "__version__"]
45 changes: 45 additions & 0 deletions trendradar/utils/code_review_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# coding=utf-8
# 代码审查测试模块

def validate_data(data):
"""验证数据有效性"""
if data is None:
return False
if not isinstance(data, dict):
return False
return True

def process_records(records, min_score=60):
"""处理记录列表,筛选合格项"""
if records is None:
return []
result = []
for record in records:
score = record.get("score", 0)
if score >= min_score:
result.append(record)
return result

class DataAnalyzer:
"""数据分析器"""

def __init__(self, config=None):
self.config = config or {}
self.data = []

def load_from_file(self, filepath):
"""从文件加载数据"""
try:
with open(filepath, "r", encoding="utf-8") as f:
content = f.read()
self.data = content.split("\n")
except FileNotFoundError:
self.data = []
except Exception as e:
self.data = []

def analyze(self):
"""分析数据"""
if not self.data:
return []
return [line.strip() for line in self.data if line.strip()]
37 changes: 37 additions & 0 deletions trendradar/utils/review_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# coding=utf-8
"""
代码审查测试模块
用于验证 AI 代码审查功能
"""

class DataAnalyzer:
"""数据分析器"""

def __init__(self, config):
self.config = config
self.data = []

def analyze(self, items):
"""分析数据"""
results = []
for item in items:
# 计算统计信息
result = {
'id': item.get('id'),
'value': item.get('value', 0),
'category': item.get('category', 'unknown')
}
results.append(result)
return results

def get_summary(self):
"""获取摘要"""
if not self.data:
return "暂无数据"
return f"共 {len(self.data)} 条数据"


def process_items(items, threshold=0.5):
"""处理数据项"""
filtered = [i for i in items if i.get('score', 0) >= threshold]
return filtered
42 changes: 42 additions & 0 deletions trendradar/utils/test_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# coding=utf-8
"""
测试辅助工具 - 用于代码审查测试
"""

def process_data(data, config):
"""处理数据"""
# 故意添加一些问题用于测试代码审查
result = {}

# 问题1: 潜在的空指针
if data['items']:
for item in data['items']:
result[item['id']] = item['value']

# 问题2: 不安全的字符串拼接
query = "SELECT * FROM users WHERE id = " + str(data.get('user_id'))

# 问题3: 硬编码的配置
timeout = 30
retry_count = 3

return result

def validate_input(input_str):
"""验证输入"""
# 问题: 没有处理 None 的情况
return input_str.strip() if input_str else None

class DataProcessor:
def __init__(self):
self.data = None

def load(self, path):
# 问题: 没有异常处理
with open(path, 'r') as f:
self.data = f.read()

def process(self):
# 问题: 可能的 None 访问
lines = self.data.split('\n')
return [line.strip() for line in lines]