pytest-dev / py

Python development support library (note: maintenance only)
MIT License
69 stars 105 forks source link

py.path.local.LocalPath.join does not handle unicode #16

Closed pytestbot closed 7 years ago

pytestbot commented 8 years ago

py.path.local.LocalPath.join calls str on its *args. This does not work for unicode filenames.

pytestbot commented 8 years ago

Original comment by @fbauer

I am sorry but I think won't find the time to fix this issue myself. I did investigate the current code and came up with a minimal change to the test suite. This currently lives in the localpath-unicode branch at https://bitbucket.org/fbauer/py

I basically modified the path1 funcarg to return a pathname containing non-ascii characters. I would have liked to create a subclass of TestLocalPath with a path1 funcarg as method, but this does not seem to have the desired effect of overwriting the module-level funcarg.

This change makes TestLocalPath pass under python 3 and fail under python 2. The difference stems from the fact that the py lib runs untranslated on both pythons, e.g. "foo" is a bytestring under py2 and a string under py3, which means the current path code is already unicode-aware under python 3.

I guess the best fix would be to only store unicode path names internally under python 2 as well, mimicking the behavior under python 3.

Btw. I tried to sign up to the mailing list, but can't post there.

pytestbot commented 8 years ago

Original comment by @fbauer

I just forked the py lib and had a first look at the test suite. I see that you are already using the tmpdir funcarg as a convenient path constructor to test other parts of the api. As the tmpdir funcarg was my original use case, I basically have a failing test case lying around. Give me some time to play with the code and I send you a pull request for test case + hopefully a fix. I guess it is not particular hard to fix this anyway, at least for windows + linux.

pytestbot commented 8 years ago

Original comment by @hpk42

could you suggest a few test cases that should work after a fix? I don't have much experience with unicode filenames myself and don't know off hand how python versions support it on the different platforms.

RonnyPfannschmidt commented 7 years ago

@fbauer ping?

fbauer commented 7 years ago

I don't have access to an environment anymore where I could easily reproduce the issue. As far as I can recall I saw it when I tried running tests on Windows 7 (?) both under Python 2.7 and 3.3 at the time. I'd close the issue as likely outdated.

RonnyPfannschmidt commented 7 years ago

thanks, closing as no longer able to obtain the information