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

Incorrect behavior for pathlib.Path.resolve() when path does not exist #401

Closed
apt-itude opened this issue May 16, 2018 · 3 comments · Fixed by #402
Closed

Incorrect behavior for pathlib.Path.resolve() when path does not exist #401

apt-itude opened this issue May 16, 2018 · 3 comments · Fixed by #402
Labels

Comments

@apt-itude
Copy link

In the following test suite, the test that does not use the fs fixture succeeds while the test that does use the fs fixture fails:

import pathlib

import pytest


def test_pathlib_resolve_without_fs():
    path = pathlib.Path('/var/foo/bar/baz')

    assert path.resolve() == path


@pytest.mark.usefixtures('fs')
def test_pathlib_resolve_with_fs():
    path = pathlib.Path('/var/foo/bar/baz')

    assert path.resolve() == path

Here is a snippet of the results:

===================================================== FAILURES =====================================================
___________________________________________ test_pathlib_resolve_with_fs ___________________________________________

>   ???
E   AssertionError: assert PosixPath('/var') == PosixPath('/var/foo/bar/baz')
E    +  where PosixPath('/var') = <bound method FakePath.resolve of PosixPath('/var/foo/bar/baz')>()
E    +    where <bound method FakePath.resolve of PosixPath('/var/foo/bar/baz')> = PosixPath('/var/foo/bar/baz').resolve

From the documentation (https://docs.python.org/3/library/pathlib.html#pathlib.Path.resolve):

If strict is False, the path is resolved as far as possible and any remainder is appended without checking whether it exists.

A similar bug existed in Python itself, but was fixed in version 3.6.2.

Environment

OS: CentOS Linux release 7.3.1611 (Core)
Python: 3.6.5
pyfakefs: 3.4.1

@mrbean-bremen
Copy link
Member

Thanks for the report - I will have a look!

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue May 17, 2018
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue May 17, 2018
@mrbean-bremen
Copy link
Member

Interestingly enough, there had been a test in place for this, but it had an error - instead of the intended assertEqual it used assertTrue to check for the resolved name. Urgh... Together with the fact that the implementation of resolve was directly taken from Python (which was buggy for Python at the time) this caused the problem.

@apt-itude
Copy link
Author

Thanks for being so responsive!

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

Successfully merging a pull request may close this issue.

2 participants