parent
eb54ff0256
commit
8a07ae4101
@ -0,0 +1,29 @@
|
||||
# test_helper_functions.py
|
||||
import os
|
||||
from helper_functions import Utils
|
||||
|
||||
# 创建一个测试文件
|
||||
test_content = "这是一个测试文件,用于验证工具函数。\nThis is a test file to verify utility functions."
|
||||
test_file_path = "test_file.txt"
|
||||
|
||||
# 写入测试文件
|
||||
with open(test_file_path, "w", encoding="utf-8") as f:
|
||||
f.write(test_content)
|
||||
|
||||
# 测试文件大小格式化
|
||||
file_size = os.path.getsize(test_file_path)
|
||||
formatted_size = Utils.format_file_size(file_size)
|
||||
print(f"文件大小: {file_size} 字节")
|
||||
print(f"格式化大小: {formatted_size}")
|
||||
|
||||
# 测试文件编码检测
|
||||
detected_encoding = Utils.detect_encoding(test_file_path)
|
||||
print(f"检测到的编码: {detected_encoding}")
|
||||
|
||||
# 测试文件哈希计算
|
||||
file_hash = Utils.calculate_file_hash(test_file_path)
|
||||
print(f"文件哈希值: {file_hash}")
|
||||
|
||||
# 清理测试文件
|
||||
os.remove(test_file_path)
|
||||
print("测试完成,临时文件已清理。")
|
||||
Loading…
Reference in new issue