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

Using tilde (~) #137

Open
adriano-di-giovanni opened this issue Oct 14, 2016 · 5 comments
Open

Using tilde (~) #137

adriano-di-giovanni opened this issue Oct 14, 2016 · 5 comments
Labels
bug This issue/PR relates to a bug.

Comments

@adriano-di-giovanni
Copy link

The following test fails

def test_gitignore_global_file(File):
    gitignore_global = File('~/.gitignore_global')
    assert gitignore_global.exists

This one succeeds

def test_gitignore_global_file(File):
    gitignore_global = File('/Users/me/.gitignore_global')
    assert gitignore_global.exists

In order to make the test succeed I have to use /Users/me instead of tilde.

Is it correct?

@adriano-di-giovanni
Copy link
Author

In the meanwhile, I found this workaround

from os.path import expanduser

def test_gitignore_global_file(File):
    path = expanduser('~/.gitignore_global')
    gitignore_global = File(path)
    assert gitignore_global.exists

@philpep
Copy link
Contributor

philpep commented Oct 14, 2016

Hi, thanks for reporting.

I think there is a bug here and the behavior could be different given the undelying backend or options (like sudo).

@philpep philpep added the bug This issue/PR relates to a bug. label Oct 14, 2016
@mr-ice
Copy link
Contributor

mr-ice commented Dec 16, 2016

Python does not expand ~ by default. For that matter, only shells do.

likewise by default Python will not expand '$HOME/.gitignore_global' which is valid to the shell and in many cases equivalent to the example given.

Should the File() module call both expanduser and expandvars from os.path?

@philpep
Copy link
Contributor

philpep commented Dec 16, 2016

Using expanduser cannot work on remote connections (ssh, docker etc). This must be done by the shell.

@gbirke
Copy link
Contributor

gbirke commented Jan 12, 2017

I had the same problem. My current workaround that works on remote connections looks like this:

import os

def test_gitignore_global_file(File, User):
    gitignore_global = File(os.path.join(User().home, '.gitignore_global'))
    assert gitignore_global.exists

But I think it makes the tests unneccesarily verbose. It would be nice if there was a shortcut for home-local paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

4 participants