babel icon indicating copy to clipboard operation
babel copied to clipboard

Fix for #990 (updated)

Open mdklatt opened this issue 2 years ago • 3 comments
trafficstars

This is an update of https://github.com/python-babel/babel/pull/1006 that incorporates upstream fixes to previously-broken tests. It should pass all CI checks now.

This PR:

  • Adds some basic tests for the localtime module (developed on macOS, test stub added for Windows)
  • Fixes #990

mdklatt avatar Oct 12 '23 19:10 mdklatt

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.

mdklatt avatar Nov 28 '23 14:11 mdklatt

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?

akx avatar Nov 28 '23 18:11 akx

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.

mdklatt avatar Nov 28 '23 22:11 mdklatt