This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_time incorrectly defined
Type: behavior Stage:
Components: Tests Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: michael-o, p-ganssle
Priority: normal Keywords:

Created on 2018-08-14 13:36 by michael-o, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg323519 - (view) Author: Michael Osipov (michael-o) * Date: 2018-08-14 13:36
I see a test failure on HP-UX:
> test_negative (test.test_time.TestStrftime4dyear) ... FAIL
> ======================================================================
> FAIL: test_negative (test.test_time.TestStrftime4dyear)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/var/osipovmi/cpython/Lib/test/test_time.py", line 687, in test_negative
>     return super().test_negative()
>   File "/var/osipovmi/cpython/Lib/test/test_time.py", line 713, in test_negative
>     self.assertEqual(self.yearstr(-1), self._format % -1)
> AssertionError: '-0001' != '-001'
> - -0001
> ?  -
> + -001

The bug is in the test class, not cause by HP-UX.
Lib/test/test_time.py:713 says "self.assertEqual(self.yearstr(-1), self._format % -1)" where self._format is set in line 654 to "_format = '%04d'" because
> Python 3.7.0+ (heads/3.7-dirty:ea8835fb30, Aug 14 2018, 14:44:19) [C] on hp-ux11
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import time
> >>> time.strftime('%Y', (1,) + (0,) * 8)
> '0001'

Unfortunately, the zero padding in printf() applies to the entire string length. So
> >>> "%+04d" % -1
> '-001'

on HP-UX, Linux and FreeBSD.

The format string must add an additional zero for negative numbers.
msg323523 - (view) Author: Michael Osipov (michael-o) * Date: 2018-08-14 14:19
The proper format for int < 0 must be "%05d".
History
Date User Action Args
2022-04-11 14:59:04adminsetgithub: 78585
2018-08-21 09:04:00michael-osetversions: + Python 3.6, Python 3.8
2018-08-20 19:46:27p-gansslesetnosy: + p-ganssle
2018-08-14 14:19:31michael-osetmessages: + msg323523
2018-08-14 13:36:49michael-ocreate