zopefoundation / DateTime

This package provides a DateTime data type, as known from Zope. Unless you need to communicate with Zope APIs, you're probably better off using Python's built-in datetime module.
Other
19 stars 25 forks source link

DateTime 4.5 unit test incompatible with Windows #39

Closed dataflake closed 2 years ago

dataflake commented 2 years ago

In the process of updating the DateTime version pin for Zope and running the CI tests I discovered that a recent change is incompatible with Windows. The tests fail with this traceback:

Error in test test_format (DateTime.tests.test_datetime.DateTimeTests)
Traceback (most recent call last):
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\unittest\case.py", line 59, in testPartExecutor
    yield
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\unittest\case.py", line 605, in run
    testMethod()
  File "d:\a\zope\zope\.tox\py36\eggs\datetime-4.5-py3.6.egg\DateTime\tests\test_datetime.py", line 690, in test_format
    result = dt.strftime(fmt)
  File "d:\a\zope\zope\.tox\py36\eggs\datetime-4.5-py3.6.egg\DateTime\DateTime.py", line 1566, in strftime
    microseconds).strftime(format)
ValueError: Invalid format string

The corresponding code is part of #37.

dataflake commented 2 years ago

I have updated the CI configuration here so it tests for Windows as well: https://github.com/zopefoundation/DateTime/actions/runs/3020975789

d-maurer commented 1 year ago

Jens Vagelpohl wrote at 2022-9-9 01:15 -0700:

In the process of updating the DateTime version pin for Zope and running the CI tests I discovered that a recent change is incompatible with Windows. The tests fail with this traceback:

Error in test test_format (DateTime.tests.test_datetime.DateTimeTests)
Traceback (most recent call last):
 File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\unittest\case.py", line 59, in testPartExecutor
   yield
 File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\unittest\case.py", line 605, in run
   testMethod()
 File "d:\a\zope\zope\.tox\py36\eggs\datetime-4.5-py3.6.egg\DateTime\tests\test_datetime.py", line 690, in test_format
   result = dt.strftime(fmt)
 File "d:\a\zope\zope\.tox\py36\eggs\datetime-4.5-py3.6.egg\DateTime\DateTime.py", line 1566, in strftime
   microseconds).strftime(format)
ValueError: Invalid format string

Almost surely, the test is to blame. The test uses the format %-d.%-m.%Y %H:%M. The - prefixes for the format codes d and m look suspicious -- potentially, they are not supported by all C runtimes (specifically the Windows C library).

d-maurer commented 1 year ago

Dieter Maurer wrote at 2022-9-9 11:12 +0200:

Jens Vagelpohl wrote at 2022-9-9 01:15 -0700:

In the process of updating the DateTime version pin for Zope and running the CI tests I discovered that a recent change is incompatible with Windows. The tests fail with this traceback:

Error in test test_format (DateTime.tests.test_datetime.DateTimeTests)
Traceback (most recent call last):
 File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\unittest\case.py", line 59, in testPartExecutor
   yield
 File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\unittest\case.py", line 605, in run
   testMethod()
 File "d:\a\zope\zope\.tox\py36\eggs\datetime-4.5-py3.6.egg\DateTime\tests\test_datetime.py", line 690, in test_format
   result = dt.strftime(fmt)
 File "d:\a\zope\zope\.tox\py36\eggs\datetime-4.5-py3.6.egg\DateTime\DateTime.py", line 1566, in strftime
   microseconds).strftime(format)
ValueError: Invalid format string

Almost surely, the test is to blame. The test uses the format %-d.%-m.%Y %H:%M. The - prefixes for the format codes d and m look suspicious -- potentially, they are not supported by all C runtimes (specifically the Windows C library).

According to the Linux man page (for strftime), the - prefix belongs to a glibc extension The test should not use it.