Squashed 'paste-framework/' content from commit 34e8684

git-subtree-dir: paste-framework
git-subtree-split: 34e8684c4bc3cebbe177509f42ab4ef5b5425a7a
This commit is contained in:
zwf
2026-06-02 19:09:22 +08:00
commit 4729698049
107 changed files with 21484 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
"""
测试字符串工具。
无外部依赖,可离线运行。
"""
import datetime
from paste.util import ustr
class TestUstr:
"""字符串工具测试"""
def test_str_q_count_all_cn(self):
"""全中文统计"""
assert ustr.str_q_count("中国汉字") == 4
def test_str_q_count_mixed(self):
"""中英文混合统计"""
count = ustr.str_q_count("Hello中国")
assert count == 2 # 只有中文字符算
def test_str_q_count_empty(self):
"""空字符串统计"""
assert ustr.str_q_count("") == 0
def test_str_q_count_no_cn(self):
"""纯英文统计"""
assert ustr.str_q_count("HelloWorld") == 0
def test_to_datetime_standard(self):
"""标准格式解析"""
result = ustr.to_datetime("2024-01-15 10:30:00", ["%Y-%m-%d %H:%M:%S"])
assert result is not None
assert isinstance(result, datetime.datetime)
def test_to_datetime_invalid(self):
"""无效格式解析"""
result = ustr.to_datetime("not-a-date", ["%Y-%m-%d"])
assert result is None
def test_to_datetime_empty(self):
"""空字符串解析"""
result = ustr.to_datetime("", ["%Y-%m-%d"])
assert result is None