1
- import ntpath
2
1
import os
3
- import posixpath
4
2
import sys
5
- from typing import Generator
6
3
from unittest import mock
7
4
8
5
import pytest
11
8
from pip ._internal .utils import appdirs
12
9
13
10
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
-
56
11
class TestUserCacheDir :
57
- @pytest .mark .usefixtures ( "platformdirs_win32 " )
12
+ @pytest .mark .skipif ( sys . platform != "win32" , reason = "Windows-only test " )
58
13
def test_user_cache_dir_win (self , monkeypatch : pytest .MonkeyPatch ) -> None :
59
14
_get_win_folder = mock .Mock (return_value = "C:\\ Users\\ test\\ AppData\\ Local" )
60
15
@@ -71,20 +26,20 @@ def test_user_cache_dir_win(self, monkeypatch: pytest.MonkeyPatch) -> None:
71
26
)
72
27
assert _get_win_folder .call_args_list == [mock .call ("CSIDL_LOCAL_APPDATA" )]
73
28
74
- @pytest .mark .usefixtures ( "platformdirs_darwin " )
29
+ @pytest .mark .skipif ( sys . platform != "darwin" , reason = "MacOS-only test " )
75
30
def test_user_cache_dir_osx (self , monkeypatch : pytest .MonkeyPatch ) -> None :
76
31
monkeypatch .setenv ("HOME" , "/home/test" )
77
32
78
33
assert appdirs .user_cache_dir ("pip" ) == "/home/test/Library/Caches/pip"
79
34
80
- @pytest .mark .usefixtures ( "platformdirs_linux " )
35
+ @pytest .mark .skipif ( sys . platform != "linux" , reason = "Linux-only test " )
81
36
def test_user_cache_dir_linux (self , monkeypatch : pytest .MonkeyPatch ) -> None :
82
37
monkeypatch .delenv ("XDG_CACHE_HOME" , raising = False )
83
38
monkeypatch .setenv ("HOME" , "/home/test" )
84
39
85
40
assert appdirs .user_cache_dir ("pip" ) == "/home/test/.cache/pip"
86
41
87
- @pytest .mark .usefixtures ( "platformdirs_linux " )
42
+ @pytest .mark .skipif ( sys . platform != "linux" , reason = "Linux-only test " )
88
43
def test_user_cache_dir_linux_override (
89
44
self , monkeypatch : pytest .MonkeyPatch
90
45
) -> None :
@@ -93,7 +48,7 @@ def test_user_cache_dir_linux_override(
93
48
94
49
assert appdirs .user_cache_dir ("pip" ) == "/home/test/.other-cache/pip"
95
50
96
- @pytest .mark .usefixtures ( "platformdirs_linux " )
51
+ @pytest .mark .skipif ( sys . platform != "linux" , reason = "Linux-only test " )
97
52
def test_user_cache_dir_linux_home_slash (
98
53
self , monkeypatch : pytest .MonkeyPatch
99
54
) -> None :
@@ -125,7 +80,7 @@ def my_get_win_folder(csidl_name):
125
80
126
81
127
82
class TestSiteConfigDirs :
128
- @pytest .mark .usefixtures ( "platformdirs_win32 " )
83
+ @pytest .mark .skipif ( sys . platform != "win32" , reason = "Windows-only test " )
129
84
def test_site_config_dirs_win (self , monkeypatch : pytest .MonkeyPatch ) -> None :
130
85
_get_win_folder = mock .Mock (return_value = "C:\\ ProgramData" )
131
86
@@ -139,7 +94,7 @@ def test_site_config_dirs_win(self, monkeypatch: pytest.MonkeyPatch) -> None:
139
94
assert appdirs .site_config_dirs ("pip" ) == ["C:\\ ProgramData\\ pip" ]
140
95
assert _get_win_folder .call_args_list == [mock .call ("CSIDL_COMMON_APPDATA" )]
141
96
142
- @pytest .mark .usefixtures ( "platformdirs_darwin " )
97
+ @pytest .mark .skipif ( sys . platform != "darwin" , reason = "MacOS-only test " )
143
98
def test_site_config_dirs_osx (self , monkeypatch : pytest .MonkeyPatch ) -> None :
144
99
monkeypatch .setenv ("HOME" , "/home/test" )
145
100
@@ -148,13 +103,13 @@ def test_site_config_dirs_osx(self, monkeypatch: pytest.MonkeyPatch) -> None:
148
103
"/Library/Application Support/pip" ,
149
104
]
150
105
151
- @pytest .mark .usefixtures ( "platformdirs_linux " )
106
+ @pytest .mark .skipif ( sys . platform != "linux" , reason = "Linux-only test " )
152
107
def test_site_config_dirs_linux (self , monkeypatch : pytest .MonkeyPatch ) -> None :
153
108
monkeypatch .delenv ("XDG_CONFIG_DIRS" , raising = False )
154
109
155
110
assert appdirs .site_config_dirs ("pip" ) == ["/etc/xdg/pip" , "/etc" ]
156
111
157
- @pytest .mark .usefixtures ( "platformdirs_linux " )
112
+ @pytest .mark .skipif ( sys . platform != "linux" , reason = "Linux-only test " )
158
113
def test_site_config_dirs_linux_override (
159
114
self , monkeypatch : pytest .MonkeyPatch
160
115
) -> None :
@@ -168,7 +123,7 @@ def test_site_config_dirs_linux_override(
168
123
"/etc" ,
169
124
]
170
125
171
- @pytest .mark .usefixtures ( "platformdirs_linux " )
126
+ @pytest .mark .skipif ( sys . platform != "linux" , reason = "Linux-only test " )
172
127
def test_site_config_dirs_linux_empty (
173
128
self , monkeypatch : pytest .MonkeyPatch
174
129
) -> None :
@@ -178,7 +133,7 @@ def test_site_config_dirs_linux_empty(
178
133
179
134
180
135
class TestUserConfigDir :
181
- @pytest .mark .usefixtures ( "platformdirs_win32 " )
136
+ @pytest .mark .skipif ( sys . platform != "win32" , reason = "Windows-only test " )
182
137
def test_user_config_dir_win_no_roaming (
183
138
self , monkeypatch : pytest .MonkeyPatch
184
139
) -> None :
@@ -197,7 +152,7 @@ def test_user_config_dir_win_no_roaming(
197
152
)
198
153
assert _get_win_folder .call_args_list == [mock .call ("CSIDL_LOCAL_APPDATA" )]
199
154
200
- @pytest .mark .usefixtures ( "platformdirs_win32 " )
155
+ @pytest .mark .skipif ( sys . platform != "win32" , reason = "Windows-only test " )
201
156
def test_user_config_dir_win_yes_roaming (
202
157
self , monkeypatch : pytest .MonkeyPatch
203
158
) -> None :
@@ -215,7 +170,7 @@ def test_user_config_dir_win_yes_roaming(
215
170
)
216
171
assert _get_win_folder .call_args_list == [mock .call ("CSIDL_APPDATA" )]
217
172
218
- @pytest .mark .usefixtures ( "platformdirs_darwin " )
173
+ @pytest .mark .skipif ( sys . platform != "darwin" , reason = "MacOS-only test " )
219
174
def test_user_config_dir_osx (self , monkeypatch : pytest .MonkeyPatch ) -> None :
220
175
monkeypatch .setenv ("HOME" , "/home/test" )
221
176
@@ -227,14 +182,14 @@ def test_user_config_dir_osx(self, monkeypatch: pytest.MonkeyPatch) -> None:
227
182
else :
228
183
assert appdirs .user_config_dir ("pip" ) == "/home/test/.config/pip"
229
184
230
- @pytest .mark .usefixtures ( "platformdirs_linux " )
185
+ @pytest .mark .skipif ( sys . platform != "linux" , reason = "Linux-only test " )
231
186
def test_user_config_dir_linux (self , monkeypatch : pytest .MonkeyPatch ) -> None :
232
187
monkeypatch .delenv ("XDG_CONFIG_HOME" , raising = False )
233
188
monkeypatch .setenv ("HOME" , "/home/test" )
234
189
235
190
assert appdirs .user_config_dir ("pip" ) == "/home/test/.config/pip"
236
191
237
- @pytest .mark .usefixtures ( "platformdirs_linux " )
192
+ @pytest .mark .skipif ( sys . platform != "linux" , reason = "Linux-only test " )
238
193
def test_user_config_dir_linux_override (
239
194
self , monkeypatch : pytest .MonkeyPatch
240
195
) -> None :
@@ -243,7 +198,7 @@ def test_user_config_dir_linux_override(
243
198
244
199
assert appdirs .user_config_dir ("pip" ) == "/home/test/.other-config/pip"
245
200
246
- @pytest .mark .usefixtures ( "platformdirs_linux " )
201
+ @pytest .mark .skipif ( sys . platform != "linux" , reason = "Linux-only test " )
247
202
def test_user_config_dir_linux_home_slash (
248
203
self , monkeypatch : pytest .MonkeyPatch
249
204
) -> None :
0 commit comments