夏令时变化会影响保存和加载icalendar文件的结果吗?

时间:2008-10-26 08:26:32

标签: python unit-testing icalendar

我有一些单位测试在夏令时转换后开始失败。

我们正在使用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

所以,问题:   - 为什么我当前的时间(以及我所在的DST的哪一部分)会影响时间戳的加载/保存/解析?我希望它不会。   - 如果它是一个bug,你会如何对这种bug进行单元测试?显然,我不希望我的单元测试重置计算机上的时钟。

1 个答案:

答案 0 :(得分:1)

不看你的代码(以及引用的test-run-script我的大脑现在无法理解) 我注意到你试图获得的时间与你所在的时区不同。 (将DST视为另一个TIMEZONE,而不是当前时区的+ 1小时)。 这可能(取决于你如何做)导致小时数的增加或减少。 (就像你的飞行时一样,你从一开始就开始到达你的位置,然后在当地时间开始)

相关问题