2
2
import os
3
3
import posixpath
4
4
import sys
5
+ from typing import Generator
5
6
from unittest import mock
6
7
7
8
import pytest
11
12
12
13
13
14
@pytest .fixture ()
14
- def platformdirs_win32 (monkeypatch ):
15
+ def platformdirs_win32 (monkeypatch : pytest .MonkeyPatch ) -> Generator [None , None , None ]:
16
+
15
17
# Monkeypatch platformdirs to pretend we're running on Windows
16
18
17
19
with monkeypatch .context () as m :
@@ -24,7 +26,8 @@ def platformdirs_win32(monkeypatch):
24
26
25
27
26
28
@pytest .fixture ()
27
- def platformdirs_darwin (monkeypatch ):
29
+ def platformdirs_darwin (monkeypatch : pytest .MonkeyPatch ) -> Generator [None , None , None ]:
30
+
28
31
# Monkeypatch platformdirs to pretend we're running on macOS
29
32
30
33
with monkeypatch .context () as m :
@@ -37,7 +40,8 @@ def platformdirs_darwin(monkeypatch):
37
40
38
41
39
42
@pytest .fixture ()
40
- def platformdirs_linux (monkeypatch ):
43
+ def platformdirs_linux (monkeypatch : pytest .MonkeyPatch ) -> Generator [None , None , None ]:
44
+
41
45
# Monkeypatch platformdirs to pretend we're running on Linux
42
46
43
47
with monkeypatch .context () as m :
@@ -50,11 +54,12 @@ def platformdirs_linux(monkeypatch):
50
54
51
55
52
56
class TestUserCacheDir :
53
- def test_user_cache_dir_win (self , monkeypatch : pytest .MonkeyPatch , platformdirs_win32 ) -> None :
57
+ @pytest .mark .usefixtures ("platformdirs_win32" )
58
+ def test_user_cache_dir_win (self , monkeypatch : pytest .MonkeyPatch ) -> None :
54
59
_get_win_folder = mock .Mock (return_value = "C:\\ Users\\ test\\ AppData\\ Local" )
55
60
56
61
monkeypatch .setattr (
57
- platformdirs .windows ,
62
+ platformdirs .windows , # type: ignore[attr-defined]
58
63
"get_win_folder" ,
59
64
_get_win_folder ,
60
65
raising = False ,
@@ -66,27 +71,31 @@ def test_user_cache_dir_win(self, monkeypatch: pytest.MonkeyPatch, platformdirs_
66
71
)
67
72
assert _get_win_folder .call_args_list == [mock .call ("CSIDL_LOCAL_APPDATA" )]
68
73
69
- def test_user_cache_dir_osx (self , monkeypatch : pytest .MonkeyPatch , platformdirs_darwin ) -> None :
74
+ @pytest .mark .usefixtures ("platformdirs_darwin" )
75
+ def test_user_cache_dir_osx (self , monkeypatch : pytest .MonkeyPatch ) -> None :
70
76
monkeypatch .setenv ("HOME" , "/home/test" )
71
77
72
78
assert appdirs .user_cache_dir ("pip" ) == "/home/test/Library/Caches/pip"
73
79
74
- def test_user_cache_dir_linux (self , monkeypatch : pytest .MonkeyPatch , platformdirs_linux ) -> None :
80
+ @pytest .mark .usefixtures ("platformdirs_linux" )
81
+ def test_user_cache_dir_linux (self , monkeypatch : pytest .MonkeyPatch ) -> None :
75
82
monkeypatch .delenv ("XDG_CACHE_HOME" , raising = False )
76
83
monkeypatch .setenv ("HOME" , "/home/test" )
77
84
78
85
assert appdirs .user_cache_dir ("pip" ) == "/home/test/.cache/pip"
79
86
87
+ @pytest .mark .usefixtures ("platformdirs_linux" )
80
88
def test_user_cache_dir_linux_override (
81
- self , monkeypatch : pytest .MonkeyPatch , platformdirs_linux
89
+ self , monkeypatch : pytest .MonkeyPatch
82
90
) -> None :
83
91
monkeypatch .setenv ("XDG_CACHE_HOME" , "/home/test/.other-cache" )
84
92
monkeypatch .setenv ("HOME" , "/home/test" )
85
93
86
94
assert appdirs .user_cache_dir ("pip" ) == "/home/test/.other-cache/pip"
87
95
96
+ @pytest .mark .usefixtures ("platformdirs_linux" )
88
97
def test_user_cache_dir_linux_home_slash (
89
- self , monkeypatch : pytest .MonkeyPatch , platformdirs_linux
98
+ self , monkeypatch : pytest .MonkeyPatch
90
99
) -> None :
91
100
# Verify that we are not affected by https://bugs.python.org/issue14768
92
101
monkeypatch .delenv ("XDG_CACHE_HOME" , raising = False )
@@ -116,11 +125,12 @@ def my_get_win_folder(csidl_name):
116
125
117
126
118
127
class TestSiteConfigDirs :
119
- def test_site_config_dirs_win (self , monkeypatch : pytest .MonkeyPatch , platformdirs_win32 ) -> None :
128
+ @pytest .mark .usefixtures ("platformdirs_win32" )
129
+ def test_site_config_dirs_win (self , monkeypatch : pytest .MonkeyPatch ) -> None :
120
130
_get_win_folder = mock .Mock (return_value = "C:\\ ProgramData" )
121
131
122
132
monkeypatch .setattr (
123
- platformdirs .windows ,
133
+ platformdirs .windows , # type: ignore[attr-defined]
124
134
"get_win_folder" ,
125
135
_get_win_folder ,
126
136
raising = False ,
@@ -129,21 +139,24 @@ def test_site_config_dirs_win(self, monkeypatch: pytest.MonkeyPatch, platformdir
129
139
assert appdirs .site_config_dirs ("pip" ) == ["C:\\ ProgramData\\ pip" ]
130
140
assert _get_win_folder .call_args_list == [mock .call ("CSIDL_COMMON_APPDATA" )]
131
141
132
- def test_site_config_dirs_osx (self , monkeypatch : pytest .MonkeyPatch , platformdirs_darwin ) -> None :
142
+ @pytest .mark .usefixtures ("platformdirs_darwin" )
143
+ def test_site_config_dirs_osx (self , monkeypatch : pytest .MonkeyPatch ) -> None :
133
144
monkeypatch .setenv ("HOME" , "/home/test" )
134
145
135
146
assert appdirs .site_config_dirs ("pip" ) == [
136
147
"/Library/Preferences/pip" ,
137
148
"/Library/Application Support/pip" ,
138
149
]
139
150
140
- def test_site_config_dirs_linux (self , monkeypatch : pytest .MonkeyPatch , platformdirs_linux ) -> None :
151
+ @pytest .mark .usefixtures ("platformdirs_linux" )
152
+ def test_site_config_dirs_linux (self , monkeypatch : pytest .MonkeyPatch ) -> None :
141
153
monkeypatch .delenv ("XDG_CONFIG_DIRS" , raising = False )
142
154
143
155
assert appdirs .site_config_dirs ("pip" ) == ["/etc/xdg/pip" , "/etc" ]
144
156
157
+ @pytest .mark .usefixtures ("platformdirs_linux" )
145
158
def test_site_config_dirs_linux_override (
146
- self , monkeypatch : pytest .MonkeyPatch , platformdirs_linux
159
+ self , monkeypatch : pytest .MonkeyPatch
147
160
) -> None :
148
161
monkeypatch .setattr (os , "pathsep" , ":" )
149
162
monkeypatch .setenv ("XDG_CONFIG_DIRS" , "/spam:/etc:/etc/xdg" )
@@ -155,22 +168,24 @@ def test_site_config_dirs_linux_override(
155
168
"/etc" ,
156
169
]
157
170
171
+ @pytest .mark .usefixtures ("platformdirs_linux" )
158
172
def test_site_config_dirs_linux_empty (
159
- self , monkeypatch : pytest .MonkeyPatch , platformdirs_linux
173
+ self , monkeypatch : pytest .MonkeyPatch
160
174
) -> None :
161
175
monkeypatch .setattr (os , "pathsep" , ":" )
162
176
monkeypatch .setenv ("XDG_CONFIG_DIRS" , "" )
163
177
assert appdirs .site_config_dirs ("pip" ) == ["/etc/xdg/pip" , "/etc" ]
164
178
165
179
166
180
class TestUserConfigDir :
181
+ @pytest .mark .usefixtures ("platformdirs_win32" )
167
182
def test_user_config_dir_win_no_roaming (
168
- self , monkeypatch : pytest .MonkeyPatch , platformdirs_win32
183
+ self , monkeypatch : pytest .MonkeyPatch
169
184
) -> None :
170
185
_get_win_folder = mock .Mock (return_value = "C:\\ Users\\ test\\ AppData\\ Local" )
171
186
172
187
monkeypatch .setattr (
173
- platformdirs .windows ,
188
+ platformdirs .windows , # type: ignore[attr-defined]
174
189
"get_win_folder" ,
175
190
_get_win_folder ,
176
191
raising = False ,
@@ -182,13 +197,14 @@ def test_user_config_dir_win_no_roaming(
182
197
)
183
198
assert _get_win_folder .call_args_list == [mock .call ("CSIDL_LOCAL_APPDATA" )]
184
199
200
+ @pytest .mark .usefixtures ("platformdirs_win32" )
185
201
def test_user_config_dir_win_yes_roaming (
186
- self , monkeypatch : pytest .MonkeyPatch , platformdirs_win32
202
+ self , monkeypatch : pytest .MonkeyPatch
187
203
) -> None :
188
204
_get_win_folder = mock .Mock (return_value = "C:\\ Users\\ test\\ AppData\\ Roaming" )
189
205
190
206
monkeypatch .setattr (
191
- platformdirs .windows ,
207
+ platformdirs .windows , # type: ignore[attr-defined]
192
208
"get_win_folder" ,
193
209
_get_win_folder ,
194
210
raising = False ,
@@ -199,7 +215,8 @@ def test_user_config_dir_win_yes_roaming(
199
215
)
200
216
assert _get_win_folder .call_args_list == [mock .call ("CSIDL_APPDATA" )]
201
217
202
- def test_user_config_dir_osx (self , monkeypatch : pytest .MonkeyPatch , platformdirs_darwin ) -> None :
218
+ @pytest .mark .usefixtures ("platformdirs_darwin" )
219
+ def test_user_config_dir_osx (self , monkeypatch : pytest .MonkeyPatch ) -> None :
203
220
monkeypatch .setenv ("HOME" , "/home/test" )
204
221
205
222
if os .path .isdir ("/home/test/Library/Application Support/" ):
@@ -210,22 +227,25 @@ def test_user_config_dir_osx(self, monkeypatch: pytest.MonkeyPatch, platformdirs
210
227
else :
211
228
assert appdirs .user_config_dir ("pip" ) == "/home/test/.config/pip"
212
229
213
- def test_user_config_dir_linux (self , monkeypatch : pytest .MonkeyPatch , platformdirs_darwin ) -> None :
230
+ @pytest .mark .usefixtures ("platformdirs_linux" )
231
+ def test_user_config_dir_linux (self , monkeypatch : pytest .MonkeyPatch ) -> None :
214
232
monkeypatch .delenv ("XDG_CONFIG_HOME" , raising = False )
215
233
monkeypatch .setenv ("HOME" , "/home/test" )
216
234
217
235
assert appdirs .user_config_dir ("pip" ) == "/home/test/.config/pip"
218
236
237
+ @pytest .mark .usefixtures ("platformdirs_linux" )
219
238
def test_user_config_dir_linux_override (
220
- self , monkeypatch : pytest .MonkeyPatch , platformdirs_linux
239
+ self , monkeypatch : pytest .MonkeyPatch
221
240
) -> None :
222
241
monkeypatch .setenv ("XDG_CONFIG_HOME" , "/home/test/.other-config" )
223
242
monkeypatch .setenv ("HOME" , "/home/test" )
224
243
225
244
assert appdirs .user_config_dir ("pip" ) == "/home/test/.other-config/pip"
226
245
246
+ @pytest .mark .usefixtures ("platformdirs_linux" )
227
247
def test_user_config_dir_linux_home_slash (
228
- self , monkeypatch : pytest .MonkeyPatch , platformdirs_linux
248
+ self , monkeypatch : pytest .MonkeyPatch
229
249
) -> None :
230
250
# Verify that we are not affected by https://bugs.python.org/issue14768
231
251
monkeypatch .delenv ("XDG_CONFIG_HOME" , raising = False )
0 commit comments