【发布时间】:2008-10-26 17:31:08
【问题描述】:
我有一些单元测试在夏令时切换后开始失败。
我们正在使用iCalendar python module 来加载和保存 ics 文件。
以下脚本是我们测试的简化版本。截至今天早上,该脚本在“夏天”运行良好,但在“冬天”运行失败。可以通过手动设置时钟来重现故障。这是脚本的输出:
[root@ana icalendar]# date 10250855
Sat Oct 25 08:55:00 CEST 2008
[root@ana icalendar]# python dst.py
DTSTART should represent datetime.datetime(2015, 4, 4, 8, 0, tzinfo=tzfile('/usr/share/zoneinfo/Europe/Brussels')) Brussels time
DTSTART should represent datetime.datetime(2015, 4, 4, 6, 0, tzinfo=<icalendar.prop.UTC object at 0x956b5cc>) UTC
DTSTART represents datetime.datetime(2015, 4, 4, 6, 0, tzinfo=<icalendar.prop.UTC object at 0x956b5cc>) Brussels time
[root@ana icalendar]# date 10260855
Sun Oct 26 08:55:00 CET 2008
[root@ana icalendar]# python dst.py
DTSTART should represent datetime.datetime(2015, 4, 4, 8, 0, tzinfo=tzfile('/usr/share/zoneinfo/Europe/Brussels')) Brussels time
DTSTART should represent datetime.datetime(2015, 4, 4, 6, 0, tzinfo=<icalendar.prop.UTC object at 0x96615cc>) UTC
DTSTART represents datetime.datetime(2015, 4, 4, 7, 0, tzinfo=<icalendar.prop.UTC object at 0x96615cc>) Brussels time
Traceback (most recent call last):
File "dst.py", line 58, in <module>
start.dt, startUTCExpected)
AssertionError: calendar's datetime.datetime(2015, 4, 4, 7, 0, tzinfo=<icalendar.prop.UTC object at 0x96615cc>) != expected datetime.datetime(2015, 4, 4, 6, 0, tzinfo=<icalendar.prop.UTC object at 0x96615cc>)
这里是whole script。
所以,问题: - 为什么我的当前时间(以及我所在的夏令时的哪一部分)会影响时间戳的加载/保存/解析?我希望它不会。 - 如果它是一个错误,你将如何对这种错误进行单元测试?显然,我不希望我的单元测试重置我计算机上的时钟。
【问题讨论】:
-
近 8 年来我已经看到了单元测试和时区 /TZ+DST 的这种麻烦。我真的很好奇这个问题将得到一个更通用的术语的答案(如何为 DST 更改的可靠单元测试做准备)
-
整个脚本的链接失效。
标签: python unit-testing icalendar