Skip to content

test_strptime fails when time.strftime does not support %Z format string #121782

Not planned
@CharlieZhao95

Description

@CharlieZhao95

Bug report

Bug description:

As time.strftime doc says:

%Z: Time zone name (no characters if no time zone exists). Deprecated.

Some C libraries may replace %Z with a null character, which may cause test_strptime.CalculationTests to fail. For example:

ERROR: test_day_of_week_calculation (test.test_strptime.CalculationTests.test_day_of_week_calculation)
--
Traceback (most recent call last):
  File "/data/ci/python3.12/lib/python3.12/test/test_strptime.py", line 563, in test_day_of_week_calculation
    result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
             ^^
  File "/data/ci/python3.12/lib/python3.12/_strptime.py", line 548, in _strptime_time
    tt = _strptime(data_string, format)[0]
         ^^
  File "/data/ci/python3.12/lib/python3.12/_strptime.py", line 333, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '2024 07 11 02 08 193 ' does not match format '%Y %m %d %H %S %j %Z'

In my opinion, removing the deprecated %Z from format_string variable will not affect those tests.

Similar tests that may fail:
test_strptime.CalculationTests.test_day_of_week_calculation
test_strptime.CalculationTests.test_gregorian_calculation
test_strptime.CalculationTests.test_julian_calculation
test_time.TimeTestCase.test_strptime

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Activity

encukou

encukou commented on Mar 13, 2025

@encukou
Member
No description provided.
added
pendingThe issue will be closed if no feedback is provided
on Jun 5, 2025
encukou

encukou commented on Jun 5, 2025

@encukou
Member

@CharlieZhao95, do you remember which C library this was?
We can't easily fix this without a reproducer.

CharlieZhao95

CharlieZhao95 commented on Jun 5, 2025

@CharlieZhao95
ContributorAuthor

@CharlieZhao95, do you remember which C library this was? We can't easily fix this without a reproducer.

Thanks for the reminder, I missed the last message :)

I was working on a new unix-like embedded OS that uses musllibc. Now I think this case is more related to OS, maybe DST information is missing on the OS caused this error. And this is stated in the doc, I'm not sure if we should fix it.

See also:

musllibc strftime %Z
    case 'Z':
        if (tm->tm_isdst < 0) {
            *l = 0;
            return "";
        }
        fmt = __tm_to_tzname(tm);
        goto string;
...
removed
pendingThe issue will be closed if no feedback is provided
on Jun 5, 2025
encukou

encukou commented on Jun 5, 2025

@encukou
Member

A new OS! Exciting ❤️

But, on a new OS, you will generally need to skip a few tests, or patch things here and there.
If you really want to, send a PR and we could merge it. It shouldn't break supported platforms, shouldn't make the test ineffective, and should be very simple. Ideally it would help other OSes as well.

I'll close the issue—remove it from CPython's TODO list. We can reopen if you send a PR.

1 remaining item

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Done

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      `test_strptime` fails when `time.strftime` does not support `%Z` format string · Issue #121782 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant