Skip to content
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

Fix for #990 (updated) #1035

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mdklatt
Copy link

@mdklatt mdklatt commented Oct 12, 2023

This is an update of #1006 that incorporates upstream fixes to previously-broken tests. It should pass all CI checks now.

This PR:

Need some working tests before attempting to fix python-babel#990.

Refs python-babel#990
In certain OS installations, the target of /etc/localtime contains
double slashes. This is a valid path, but not a valid zoneinfo key.
This fix replaces `os.readlink` with `os.path.realpath`, which is
guaranteed to return a normalized path.

Fixes python-babel#990
Copy link
Member

@akx akx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to formulate the tests without adding the new pyfakefs dependency?

@mdklatt
Copy link
Author

mdklatt commented Nov 28, 2023

Would it be possible to formulate the tests without adding the new pyfakefs dependency?

The Unix tests are the only ones that use pyfakefs, so I can probably replace that with os.chroot.

@akx
Copy link
Member

akx commented Nov 28, 2023

The Unix tests are the only ones that use pyfakefs, so I can probably replace that with os.chroot.

That sounds a bit heavy-handed too... What if you just mock.patch some of the relevant calls?

@mdklatt
Copy link
Author

mdklatt commented Nov 28, 2023

The Unix tests are the only ones that use pyfakefs, so I can probably replace that with os.chroot.

That sounds a bit heavy-handed too... What if you just mock.patch some of the relevant calls?

It turns out that os.chroot will not work anyway because it requires root privileges. However, the _unix._get_localzone() function takes an optional parameter specifically intended for testing, according to its docstring:

The parameter _root makes the function look for files like /etc/localtime
beneath the _root directory. This is primarily used by the tests.
In normal usage you call the function without parameters.

The get_localzone() function is just a wrapper (for now...) around _get_localzone('/'). I have a working commit that calls _get_localzone() with a temporary test directory.

It looks like it would only be necessary to mock os.path.join() in localtime._unix if you still think that's better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash with double-slashes in /etc/localtime on Python 3.9
2 participants