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

Implement __eq__ for File objects #303

Closed
mdelapenya opened this issue Apr 9, 2018 · 2 comments
Closed

Implement __eq__ for File objects #303

mdelapenya opened this issue Apr 9, 2018 · 2 comments
Labels
enhancement This issue/PR relates to a feature request. good first issue

Comments

@mdelapenya
Copy link

mdelapenya commented Apr 9, 2018

Hello, I'm getting this error while checking the linked_to of a valid symlink.

        def test_paths_are_symliks(host):
            myPath = host.file("/mnt/jenkins/workspace")
            myLink = host.file("/home/ubuntu/workspace")
            assert myPath.exists
            assert myLink.exists
            assert myLink.is_symlink
            assert myLink.linked_to == myPath

    E           AssertionError: assert '/mnt/jenkins/workspace' == <file /mnt/jenkins/workspace>
    E            +  where '/mnt/jenkins/workspace' = <file /home/ubuntu/workspace>.linked_to

Is the last assertion returning a file object instead of the string representation of its path?

Thanks!

PS: close this issue if you consider is not a bug

@philpep
Copy link
Contributor

philpep commented Apr 10, 2018

HI, that's because myPath is an object.

You should either assert myLink.linked_to == "/mnt/jenkins/workspace" or assert myLink.linked_to == myPath.path.

I think we could have a __eq__() method on file objects for such case, so let's keep this ticket open.

@philpep philpep added the enhancement This issue/PR relates to a feature request. label Apr 10, 2018
@mdelapenya
Copy link
Author

mdelapenya commented Apr 10, 2018

I totally see it now... I don't know why I did not see it before: I was just putting the eyes on the wrong side of the equation, when the problem was at the other 😄

It works now, thanks!

@philpep philpep changed the title Error reading linked_to in MacOS Implement __eq__ for File objects Apr 10, 2018
@philpep philpep added the easy label Apr 10, 2018
barnabasJ added a commit to barnabasJ/testinfra that referenced this issue May 29, 2018
Implements __eq__ and __ne__ methods on teh File object.
If both objects are files, the paths are getting compared,
if the other object is a string it's compared with the path directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue/PR relates to a feature request. good first issue
Projects
None yet
Development

No branches or pull requests

2 participants