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

fake_scandir.DirEntry isn't Path-like #483

Closed
Aran-Fey opened this issue May 18, 2019 · 4 comments
Closed

fake_scandir.DirEntry isn't Path-like #483

Aran-Fey opened this issue May 18, 2019 · 4 comments
Labels

Comments

@Aran-Fey
Copy link

Aran-Fey commented May 18, 2019

Unlike os.DirEntry, pyfakefs.fake_scandir.DirEntry does not implement the os.PathLike interface.

Sample test case that fails if pyfakefs is used, but passes if the fs fixture is removed:

import pytest
import os

def test_scandir(fs):
    with os.scandir('/') as scanner:
        for direntry in scanner:
            assert isinstance(direntry, os.PathLike)

if __name__ == '__main__':
    pytest.main([__file__])
@mrbean-bremen
Copy link
Member

Good point.

@mrbean-bremen
Copy link
Member

mrbean-bremen commented May 19, 2019

Ok, that is not as straightforward as I thought. Under Windows, scandir.DirEntry seems not to implement os.PathLike (TypeError: expected str, bytes or os.PathLike object, not scandir.DirEntry), and the result of os.fspath() is different for Python 3.6 and Python 3.7 under Linux (but not under MacOS). I have to understand these differences before implementing this...
EDIT: Under Windows it does implement this, there seems to be some test problem.

@Aran-Fey
Copy link
Author

It looks like os.DirEntry has only become path-like starting with version 3.6 (DirEntry was added in 3.5). Do you use 3.5 on Windows?

@mrbean-bremen
Copy link
Member

Yes, path-like objects have been introduced in Python 3.6. I do get os.PathLike behavior under Windows (see my edit above), the reason why the test failed is that it used the scandir package, which seems not to implement this behavior under Windows. Maybe the difference under Linux has also to do with that...
We handle os.scandir and the scandir mostly the same way and test both, so I have to differentiate between them, obviously.

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

No branches or pull requests

2 participants