Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CharlieZhao95 opened this issue Jul 15, 2024 · 4 comments
Closed
Labels
extension-modules C modules in the Modules dir OS-unsupported type-bug An unexpected behavior, bug, or error

Comments

@CharlieZhao95
Copy link
Contributor

CharlieZhao95 commented Jul 15, 2024

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

@CharlieZhao95 CharlieZhao95 added the type-bug An unexpected behavior, bug, or error label Jul 15, 2024
@encukou encukou added extension-modules C modules in the Modules dir OS-unsupported labels Mar 13, 2025
@encukou
Copy link
Member

encukou commented Mar 13, 2025

Some C libraries

Which ones did you try?
CPython supports glibc on Linux, though we might merge PR for others if they aren't a big maintenance burden.

@encukou encukou added the pending The issue will be closed if no feedback is provided label Jun 5, 2025
@encukou
Copy link
Member

encukou commented Jun 5, 2025

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

@CharlieZhao95
Copy link
Contributor Author

@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;
...

@encukou encukou removed the pending The issue will be closed if no feedback is provided label Jun 5, 2025
@encukou
Copy link
Member

encukou commented Jun 5, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir OS-unsupported type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

2 participants