staran 1.0.0__py3-none-any.whl → 1.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,177 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ 基础使用示例
6
+ ==========
7
+
8
+ 演示Staran的基本功能和用法。
9
+ """
10
+
11
+ import sys
12
+ import os
13
+
14
+ # 添加项目根目录到路径
15
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..'))
16
+
17
+ from staran.date.core import Date
18
+
19
+
20
+ def basic_usage_demo():
21
+ """基础使用演示"""
22
+ print("🚀 基础使用演示")
23
+ print("=" * 40)
24
+
25
+ # 创建日期对象
26
+ print("1. 创建日期对象:")
27
+ date1 = Date('2025') # 年份格式
28
+ date2 = Date('202504') # 年月格式
29
+ date3 = Date('20250415') # 完整格式
30
+ date4 = Date(2025, 4, 15) # 参数格式
31
+
32
+ print(f" 年份格式: {date1}")
33
+ print(f" 年月格式: {date2}")
34
+ print(f" 完整格式: {date3}")
35
+ print(f" 参数格式: {date4}")
36
+ print()
37
+
38
+ # 智能格式记忆
39
+ print("2. 智能格式记忆:")
40
+ print(f" {date1} + 1年 = {date1.add_years(1)}")
41
+ print(f" {date2} + 2月 = {date2.add_months(2)}")
42
+ print(f" {date3} + 10天 = {date3.add_days(10)}")
43
+ print()
44
+
45
+ # 多种格式输出
46
+ print("3. 多种格式输出:")
47
+ date = Date('20250415')
48
+ print(f" 默认格式: {date}")
49
+ print(f" ISO格式: {date.format_iso()}")
50
+ print(f" 中文格式: {date.format_chinese()}")
51
+ print(f" 斜杠格式: {date.format_slash()}")
52
+ print(f" 点分格式: {date.format_dot()}")
53
+ print()
54
+
55
+
56
+ def api_demo():
57
+ """API命名规范演示"""
58
+ print("🏗️ 统一API命名演示")
59
+ print("=" * 40)
60
+
61
+ date = Date('20250415')
62
+
63
+ # from_* 系列
64
+ print("1. from_* 系列 (创建方法):")
65
+ print(f" from_string: {Date.from_string('20250415')}")
66
+ print(f" today: {Date.today()}")
67
+ print()
68
+
69
+ # to_* 系列
70
+ print("2. to_* 系列 (转换方法):")
71
+ print(f" to_tuple: {date.to_tuple()}")
72
+ print(f" to_dict: {date.to_dict()}")
73
+ print()
74
+
75
+ # get_* 系列
76
+ print("3. get_* 系列 (获取方法):")
77
+ print(f" get_weekday: {date.get_weekday()} (星期二)")
78
+ print(f" get_month_start: {date.get_month_start()}")
79
+ print(f" get_month_end: {date.get_month_end()}")
80
+ print(f" get_days_in_month: {date.get_days_in_month()}")
81
+ print()
82
+
83
+ # is_* 系列
84
+ print("4. is_* 系列 (判断方法):")
85
+ print(f" is_weekend: {date.is_weekend()}")
86
+ print(f" is_weekday: {date.is_weekday()}")
87
+ print(f" is_leap_year: {date.is_leap_year()}")
88
+ print(f" is_month_start: {date.is_month_start()}")
89
+ print()
90
+
91
+ # add_*/subtract_* 系列
92
+ print("5. add_*/subtract_* 系列 (运算方法):")
93
+ print(f" add_days(7): {date.add_days(7)}")
94
+ print(f" add_months(2): {date.add_months(2)}")
95
+ print(f" subtract_years(1): {date.subtract_years(1)}")
96
+ print()
97
+
98
+
99
+ def comparison_demo():
100
+ """日期比较演示"""
101
+ print("⚖️ 日期比较演示")
102
+ print("=" * 40)
103
+
104
+ date1 = Date('20250415')
105
+ date2 = Date('20250416')
106
+ date3 = Date('20250415')
107
+
108
+ print(f"date1 = {date1}")
109
+ print(f"date2 = {date2}")
110
+ print(f"date3 = {date3}")
111
+ print()
112
+
113
+ print("比较结果:")
114
+ print(f" date1 == date3: {date1 == date3}")
115
+ print(f" date1 < date2: {date1 < date2}")
116
+ print(f" date2 > date1: {date2 > date1}")
117
+ print(f" date1 <= date3: {date1 <= date3}")
118
+ print()
119
+
120
+
121
+ def calculation_demo():
122
+ """日期计算演示"""
123
+ print("🧮 日期计算演示")
124
+ print("=" * 40)
125
+
126
+ date1 = Date('20250415')
127
+ date2 = Date('20250515')
128
+
129
+ print(f"date1 = {date1}")
130
+ print(f"date2 = {date2}")
131
+ print()
132
+
133
+ days_diff = date1.calculate_difference_days(date2)
134
+ months_diff = date1.calculate_difference_months(date2)
135
+
136
+ print("计算结果:")
137
+ print(f" 天数差: {days_diff} 天")
138
+ print(f" 月数差: {months_diff} 个月")
139
+ print()
140
+
141
+
142
+ def backward_compatibility_demo():
143
+ """向后兼容性演示"""
144
+ print("🔙 向后兼容性演示")
145
+ print("=" * 40)
146
+
147
+ date = Date('20250415')
148
+
149
+ print("旧API仍然可用:")
150
+ print(f" format('%Y年%m月'): {date.format('%Y年%m月')}")
151
+ print(f" to_date(): {date.to_date()}")
152
+ print(f" weekday(): {date.weekday()}")
153
+
154
+ other_date = Date('20250425')
155
+ print(f" difference(other): {date.difference(other_date)} 天")
156
+ print()
157
+
158
+
159
+ def main():
160
+ """主函数"""
161
+ print("✨ Staran v1.0.2 基础使用示例")
162
+ print("=" * 50)
163
+ print()
164
+
165
+ # 运行各个演示
166
+ basic_usage_demo()
167
+ api_demo()
168
+ comparison_demo()
169
+ calculation_demo()
170
+ backward_compatibility_demo()
171
+
172
+ print("🎉 演示完成!")
173
+ print("更多示例请查看 staran/examples/ 目录")
174
+
175
+
176
+ if __name__ == '__main__':
177
+ main()
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ Staran 测试包
6
+ ============
7
+
8
+ 包含完整的测试套件,用于验证所有功能的正确性。
9
+ """
10
+
11
+ __all__ = []
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ 彩色测试运行器
6
+ ======= print(f"{chr(129514)} Staran v1.0.2 测试套件")====
7
+
8
+ 为Staran项目提供美观的彩色测试输出。
9
+ """
10
+
11
+ import unittest
12
+ import sys
13
+ import os
14
+ import time
15
+
16
+ # 添加项目根目录到路径
17
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..'))
18
+
19
+ from staran.date.tests.test_core import *
20
+
21
+
22
+ class ColoredTestResult(unittest.TextTestResult):
23
+ """彩色测试结果"""
24
+
25
+ def __init__(self, stream, descriptions, verbosity):
26
+ super().__init__(stream, descriptions, verbosity)
27
+ self.verbosity = verbosity
28
+ self.colors = {
29
+ 'green': '\033[92m',
30
+ 'red': '\033[91m',
31
+ 'yellow': '\033[93m',
32
+ 'blue': '\033[94m',
33
+ 'purple': '\033[95m',
34
+ 'cyan': '\033[96m',
35
+ 'end': '\033[0m',
36
+ 'bold': '\033[1m'
37
+ }
38
+
39
+ def addSuccess(self, test):
40
+ super().addSuccess(test)
41
+ if self.verbosity > 1:
42
+ self.stream.write(f"{self.colors['green']}✓{self.colors['end']} ")
43
+ self.stream.writeln(f"{self.colors['green']}{self.getDescription(test)}{self.colors['end']}")
44
+
45
+ def addError(self, test, err):
46
+ super().addError(test, err)
47
+ if self.verbosity > 1:
48
+ self.stream.write(f"{self.colors['red']}✗{self.colors['end']} ")
49
+ self.stream.writeln(f"{self.colors['red']}{self.getDescription(test)}{self.colors['end']}")
50
+
51
+ def addFailure(self, test, err):
52
+ super().addFailure(test, err)
53
+ if self.verbosity > 1:
54
+ self.stream.write(f"{self.colors['red']}✗{self.colors['end']} ")
55
+ self.stream.writeln(f"{self.colors['red']}{self.getDescription(test)}{self.colors['end']}")
56
+
57
+
58
+ class ColoredTestRunner(unittest.TextTestRunner):
59
+ """彩色测试运行器"""
60
+
61
+ def __init__(self, **kwargs):
62
+ kwargs['resultclass'] = ColoredTestResult
63
+ super().__init__(**kwargs)
64
+
65
+
66
+ def main():
67
+ """主函数"""
68
+ print(f"{chr(129514)} Staran v1.0.1 测试套件")
69
+ print("=" * 50)
70
+ print(f"Python版本: {sys.version}")
71
+ print(f"开始时间: {time.strftime('%Y-%m-%d %H:%M:%S')}")
72
+ print()
73
+
74
+ # 创建测试套件
75
+ loader = unittest.TestLoader()
76
+ suite = loader.loadTestsFromModule(sys.modules[__name__])
77
+
78
+ # 运行测试
79
+ runner = ColoredTestRunner(verbosity=2)
80
+ start_time = time.time()
81
+ result = runner.run(suite)
82
+ end_time = time.time()
83
+
84
+ # 生成报告
85
+ print("\n" + "=" * 50)
86
+ print(f"{chr(128202)} 测试报告")
87
+ print("=" * 50)
88
+ print(f"运行时间: {end_time - start_time:.3f}秒")
89
+ print(f"测试总数: {result.testsRun}")
90
+ success_count = result.testsRun - len(result.failures) - len(result.errors)
91
+ print(f"成功: {success_count}")
92
+ print(f"失败: {len(result.failures)}")
93
+ print(f"错误: {len(result.errors)}")
94
+
95
+ if success_count > 0:
96
+ success_rate = (success_count / result.testsRun) * 100
97
+ print(f"成功率: {success_rate:.1f}%")
98
+
99
+ if result.failures or result.errors:
100
+ print(f"\n{chr(10060)} 测试失败! 失败: {len(result.failures)}, 错误: {len(result.errors)}")
101
+ return 1
102
+ else:
103
+ print(f"\n{chr(9989)} 所有测试通过! {chr(127881)}")
104
+ return 0
105
+
106
+
107
+ if __name__ == '__main__':
108
+ exit_code = main()
109
+ sys.exit(exit_code)