diff --git a/jupyter_core/paths.py b/jupyter_core/paths.py index 4bee4ff3..8d6869e2 100644 --- a/jupyter_core/paths.py +++ b/jupyter_core/paths.py @@ -14,6 +14,7 @@ import errno import tempfile import warnings +from pathlib import Path from contextlib import contextmanager @@ -37,7 +38,7 @@ def get_home_dir(): homedir = os.path.expanduser('~') # Next line will make things work even when /home/ is a symlink to # /usr/home as it is on FreeBSD, for example - homedir = os.path.realpath(homedir) + homedir = str(Path(homedir).resolve()) return homedir _dtemps = {} @@ -90,7 +91,7 @@ def jupyter_data_dir(): elif os.name == 'nt': appdata = os.environ.get('APPDATA', None) if appdata: - return pjoin(appdata, 'jupyter') + return str(Path(appdata, 'jupyter').resolve()) else: return pjoin(jupyter_config_dir(), 'data') else: diff --git a/jupyter_core/tests/mocking.py b/jupyter_core/tests/mocking.py index 094c5f09..e1f62a12 100644 --- a/jupyter_core/tests/mocking.py +++ b/jupyter_core/tests/mocking.py @@ -29,8 +29,3 @@ def __exit__(self, *args): patch.object(os, 'name', 'posix'), patch.object(sys, 'platform', 'linux2'), ) - -windows = MultiPatch( - patch.object(os, 'name', 'nt'), - patch.object(sys, 'platform', 'win32'), -) diff --git a/jupyter_core/tests/test_paths.py b/jupyter_core/tests/test_paths.py index 6d37d22c..5b4ae657 100644 --- a/jupyter_core/tests/test_paths.py +++ b/jupyter_core/tests/test_paths.py @@ -19,7 +19,7 @@ secure_write, is_hidden, is_file_hidden ) -from .mocking import darwin, windows, linux +from .mocking import darwin, linux pjoin = os.path.join @@ -36,8 +36,6 @@ 'XDG_RUNTIME_DIR': '', }) -appdata = patch.dict('os.environ', {'APPDATA': 'appdata'}) - no_config_env = patch.dict('os.environ', { 'JUPYTER_CONFIG_DIR': '', 'JUPYTER_DATA_DIR': '', @@ -50,7 +48,7 @@ def realpath(path): - return os.path.realpath(os.path.expanduser(path)) + return os.path.abspath(os.path.realpath(os.path.expanduser(path))) home_jupyter = realpath('~/.jupyter') @@ -65,6 +63,7 @@ def test_envset(): assert not paths.envset(f"FOO_{v}") assert not paths.envset("THIS_VARIABLE_SHOULD_NOT_BE_SET") +@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows") def test_config_dir_darwin(): with darwin, no_config_env: config = jupyter_config_dir() @@ -74,23 +73,24 @@ def test_config_dir_darwin(): config = jupyter_config_dir() assert config == jupyter_config_env - +@pytest.mark.skipif(sys.platform != "win32", reason="only run on windows") def test_config_dir_windows(): - with windows, no_config_env: + with no_config_env: config = jupyter_config_dir() assert config == home_jupyter - with windows, config_env: + with config_env: config = jupyter_config_dir() assert config == jupyter_config_env +@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows") def test_config_dir_linux(): - with windows, no_config_env: + with linux, no_config_env: config = jupyter_config_dir() assert config == home_jupyter - with windows, config_env: + with linux, config_env: config = jupyter_config_dir() assert config == jupyter_config_env @@ -102,6 +102,7 @@ def test_data_dir_env(): assert data == data_env +@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows") def test_data_dir_darwin(): with darwin: data = jupyter_data_dir() @@ -112,18 +113,18 @@ def test_data_dir_darwin(): data = jupyter_data_dir() assert data == realpath('~/Library/Jupyter') - +@pytest.mark.skipif(sys.platform != "win32", reason="only run on windows") def test_data_dir_windows(): - with windows, appdata: - data = jupyter_data_dir() - assert data == pjoin('appdata', 'jupyter') + data = jupyter_data_dir() + assert data == realpath(pjoin(os.environ.get('APPDATA', None), 'jupyter')) - with windows, appdata, xdg: + with xdg: # windows should ignore xdg data = jupyter_data_dir() - assert data == pjoin('appdata', 'jupyter') + assert data == realpath(pjoin(os.environ.get('APPDATA', None), 'jupyter')) +@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows") def test_data_dir_linux(): with linux, no_xdg: data = jupyter_data_dir() @@ -141,6 +142,7 @@ def test_runtime_dir_env(): assert runtime == rtd_env +@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows") def test_runtime_dir_darwin(): with darwin: runtime = jupyter_runtime_dir() @@ -151,18 +153,18 @@ def test_runtime_dir_darwin(): runtime = jupyter_runtime_dir() assert runtime == realpath('~/Library/Jupyter/runtime') - +@pytest.mark.skipif(sys.platform != "win32", reason="only run on windows") def test_runtime_dir_windows(): - with windows, appdata: - runtime = jupyter_runtime_dir() - assert runtime == pjoin('appdata', 'jupyter', 'runtime') + runtime = jupyter_runtime_dir() + assert runtime == realpath(pjoin(os.environ.get('APPDATA', None), 'jupyter', 'runtime')) - with windows, appdata, xdg: + with xdg: # windows should ignore xdg runtime = jupyter_runtime_dir() - assert runtime == pjoin('appdata', 'jupyter', 'runtime') + assert runtime == realpath(pjoin(os.environ.get('APPDATA', None), 'jupyter', 'runtime')) +@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows") def test_runtime_dir_linux(): with linux, no_xdg: runtime = jupyter_runtime_dir()