Skip to content

Commit 377754b

Browse files
committed
Drop the hacky appdirs tests
There is no reason to try to test for other platforms.
1 parent df31815 commit 377754b

File tree

1 file changed

+16
-61
lines changed

1 file changed

+16
-61
lines changed

tests/unit/test_appdirs.py

Lines changed: 16 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import ntpath
21
import os
3-
import posixpath
42
import sys
5-
from typing import Generator
63
from unittest import mock
74

85
import pytest
@@ -11,50 +8,8 @@
118
from pip._internal.utils import appdirs
129

1310

14-
@pytest.fixture()
15-
def platformdirs_win32(monkeypatch: pytest.MonkeyPatch) -> Generator[None, None, None]:
16-
17-
# Monkeypatch platformdirs to pretend we're running on Windows
18-
19-
with monkeypatch.context() as m:
20-
m.setattr(sys, "platform", "win32")
21-
m.setattr(os, "path", ntpath)
22-
platformdirs.PlatformDirs = platformdirs._set_platform_dir_class()
23-
yield
24-
25-
platformdirs.PlatformDirs = platformdirs._set_platform_dir_class()
26-
27-
28-
@pytest.fixture()
29-
def platformdirs_darwin(monkeypatch: pytest.MonkeyPatch) -> Generator[None, None, None]:
30-
31-
# Monkeypatch platformdirs to pretend we're running on macOS
32-
33-
with monkeypatch.context() as m:
34-
m.setattr(sys, "platform", "darwin")
35-
m.setattr(os, "path", posixpath)
36-
platformdirs.PlatformDirs = platformdirs._set_platform_dir_class()
37-
yield
38-
39-
platformdirs.PlatformDirs = platformdirs._set_platform_dir_class()
40-
41-
42-
@pytest.fixture()
43-
def platformdirs_linux(monkeypatch: pytest.MonkeyPatch) -> Generator[None, None, None]:
44-
45-
# Monkeypatch platformdirs to pretend we're running on Linux
46-
47-
with monkeypatch.context() as m:
48-
m.setattr(sys, "platform", "linux")
49-
m.setattr(os, "path", posixpath)
50-
platformdirs.PlatformDirs = platformdirs._set_platform_dir_class()
51-
yield
52-
53-
platformdirs.PlatformDirs = platformdirs._set_platform_dir_class()
54-
55-
5611
class TestUserCacheDir:
57-
@pytest.mark.usefixtures("platformdirs_win32")
12+
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test")
5813
def test_user_cache_dir_win(self, monkeypatch: pytest.MonkeyPatch) -> None:
5914
_get_win_folder = mock.Mock(return_value="C:\\Users\\test\\AppData\\Local")
6015

@@ -71,20 +26,20 @@ def test_user_cache_dir_win(self, monkeypatch: pytest.MonkeyPatch) -> None:
7126
)
7227
assert _get_win_folder.call_args_list == [mock.call("CSIDL_LOCAL_APPDATA")]
7328

74-
@pytest.mark.usefixtures("platformdirs_darwin")
29+
@pytest.mark.skipif(sys.platform != "darwin", reason="MacOS-only test")
7530
def test_user_cache_dir_osx(self, monkeypatch: pytest.MonkeyPatch) -> None:
7631
monkeypatch.setenv("HOME", "/home/test")
7732

7833
assert appdirs.user_cache_dir("pip") == "/home/test/Library/Caches/pip"
7934

80-
@pytest.mark.usefixtures("platformdirs_linux")
35+
@pytest.mark.skipif(sys.platform != "linux", reason="Linux-only test")
8136
def test_user_cache_dir_linux(self, monkeypatch: pytest.MonkeyPatch) -> None:
8237
monkeypatch.delenv("XDG_CACHE_HOME", raising=False)
8338
monkeypatch.setenv("HOME", "/home/test")
8439

8540
assert appdirs.user_cache_dir("pip") == "/home/test/.cache/pip"
8641

87-
@pytest.mark.usefixtures("platformdirs_linux")
42+
@pytest.mark.skipif(sys.platform != "linux", reason="Linux-only test")
8843
def test_user_cache_dir_linux_override(
8944
self, monkeypatch: pytest.MonkeyPatch
9045
) -> None:
@@ -93,7 +48,7 @@ def test_user_cache_dir_linux_override(
9348

9449
assert appdirs.user_cache_dir("pip") == "/home/test/.other-cache/pip"
9550

96-
@pytest.mark.usefixtures("platformdirs_linux")
51+
@pytest.mark.skipif(sys.platform != "linux", reason="Linux-only test")
9752
def test_user_cache_dir_linux_home_slash(
9853
self, monkeypatch: pytest.MonkeyPatch
9954
) -> None:
@@ -125,7 +80,7 @@ def my_get_win_folder(csidl_name):
12580

12681

12782
class TestSiteConfigDirs:
128-
@pytest.mark.usefixtures("platformdirs_win32")
83+
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test")
12984
def test_site_config_dirs_win(self, monkeypatch: pytest.MonkeyPatch) -> None:
13085
_get_win_folder = mock.Mock(return_value="C:\\ProgramData")
13186

@@ -139,7 +94,7 @@ def test_site_config_dirs_win(self, monkeypatch: pytest.MonkeyPatch) -> None:
13994
assert appdirs.site_config_dirs("pip") == ["C:\\ProgramData\\pip"]
14095
assert _get_win_folder.call_args_list == [mock.call("CSIDL_COMMON_APPDATA")]
14196

142-
@pytest.mark.usefixtures("platformdirs_darwin")
97+
@pytest.mark.skipif(sys.platform != "darwin", reason="MacOS-only test")
14398
def test_site_config_dirs_osx(self, monkeypatch: pytest.MonkeyPatch) -> None:
14499
monkeypatch.setenv("HOME", "/home/test")
145100

@@ -148,13 +103,13 @@ def test_site_config_dirs_osx(self, monkeypatch: pytest.MonkeyPatch) -> None:
148103
"/Library/Application Support/pip",
149104
]
150105

151-
@pytest.mark.usefixtures("platformdirs_linux")
106+
@pytest.mark.skipif(sys.platform != "linux", reason="Linux-only test")
152107
def test_site_config_dirs_linux(self, monkeypatch: pytest.MonkeyPatch) -> None:
153108
monkeypatch.delenv("XDG_CONFIG_DIRS", raising=False)
154109

155110
assert appdirs.site_config_dirs("pip") == ["/etc/xdg/pip", "/etc"]
156111

157-
@pytest.mark.usefixtures("platformdirs_linux")
112+
@pytest.mark.skipif(sys.platform != "linux", reason="Linux-only test")
158113
def test_site_config_dirs_linux_override(
159114
self, monkeypatch: pytest.MonkeyPatch
160115
) -> None:
@@ -168,7 +123,7 @@ def test_site_config_dirs_linux_override(
168123
"/etc",
169124
]
170125

171-
@pytest.mark.usefixtures("platformdirs_linux")
126+
@pytest.mark.skipif(sys.platform != "linux", reason="Linux-only test")
172127
def test_site_config_dirs_linux_empty(
173128
self, monkeypatch: pytest.MonkeyPatch
174129
) -> None:
@@ -178,7 +133,7 @@ def test_site_config_dirs_linux_empty(
178133

179134

180135
class TestUserConfigDir:
181-
@pytest.mark.usefixtures("platformdirs_win32")
136+
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test")
182137
def test_user_config_dir_win_no_roaming(
183138
self, monkeypatch: pytest.MonkeyPatch
184139
) -> None:
@@ -197,7 +152,7 @@ def test_user_config_dir_win_no_roaming(
197152
)
198153
assert _get_win_folder.call_args_list == [mock.call("CSIDL_LOCAL_APPDATA")]
199154

200-
@pytest.mark.usefixtures("platformdirs_win32")
155+
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test")
201156
def test_user_config_dir_win_yes_roaming(
202157
self, monkeypatch: pytest.MonkeyPatch
203158
) -> None:
@@ -215,7 +170,7 @@ def test_user_config_dir_win_yes_roaming(
215170
)
216171
assert _get_win_folder.call_args_list == [mock.call("CSIDL_APPDATA")]
217172

218-
@pytest.mark.usefixtures("platformdirs_darwin")
173+
@pytest.mark.skipif(sys.platform != "darwin", reason="MacOS-only test")
219174
def test_user_config_dir_osx(self, monkeypatch: pytest.MonkeyPatch) -> None:
220175
monkeypatch.setenv("HOME", "/home/test")
221176

@@ -227,14 +182,14 @@ def test_user_config_dir_osx(self, monkeypatch: pytest.MonkeyPatch) -> None:
227182
else:
228183
assert appdirs.user_config_dir("pip") == "/home/test/.config/pip"
229184

230-
@pytest.mark.usefixtures("platformdirs_linux")
185+
@pytest.mark.skipif(sys.platform != "linux", reason="Linux-only test")
231186
def test_user_config_dir_linux(self, monkeypatch: pytest.MonkeyPatch) -> None:
232187
monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)
233188
monkeypatch.setenv("HOME", "/home/test")
234189

235190
assert appdirs.user_config_dir("pip") == "/home/test/.config/pip"
236191

237-
@pytest.mark.usefixtures("platformdirs_linux")
192+
@pytest.mark.skipif(sys.platform != "linux", reason="Linux-only test")
238193
def test_user_config_dir_linux_override(
239194
self, monkeypatch: pytest.MonkeyPatch
240195
) -> None:
@@ -243,7 +198,7 @@ def test_user_config_dir_linux_override(
243198

244199
assert appdirs.user_config_dir("pip") == "/home/test/.other-config/pip"
245200

246-
@pytest.mark.usefixtures("platformdirs_linux")
201+
@pytest.mark.skipif(sys.platform != "linux", reason="Linux-only test")
247202
def test_user_config_dir_linux_home_slash(
248203
self, monkeypatch: pytest.MonkeyPatch
249204
) -> None:

0 commit comments

Comments
 (0)