14
14
import sys
15
15
import tempfile
16
16
import time
17
- from unittest import SkipTest , mock , skipUnless
17
+ from unittest import SkipTest , mock
18
18
19
19
import ddt
20
20
import pytest
45
45
46
46
@pytest .fixture
47
47
def permission_error_tmpdir (tmp_path ):
48
- """Fixture to test permissions errors situations where they are not overcome."""
48
+ """Fixture to test permissions errors in situations where they are not overcome."""
49
49
td = tmp_path / "testdir"
50
50
td .mkdir ()
51
51
(td / "x" ).write_bytes (b"" )
@@ -211,21 +211,9 @@ def test_env_vars_for_windows_tests(self, name, env_var_value, expected_truth_va
211
211
assert actual_parsed_value is expected_truth_value
212
212
213
213
214
- class _Member :
215
- """A member of an IterableList."""
216
-
217
- __slots__ = ("name" ,)
218
-
219
- def __init__ (self , name ):
220
- self .name = name
221
-
222
- def __repr__ (self ):
223
- return f"{ type (self ).__name__ } ({ self .name !r} )"
224
-
225
-
226
- @ddt .ddt
227
- class TestUtils (TestBase ):
228
- """Tests for most utilities in :mod:`git.util`."""
214
+ @pytest .mark .skipif (sys .platform != "cygwin" , reason = "Paths specifically for Cygwin." )
215
+ class TestCygpath :
216
+ """Tests for :func:`git.util.cygpath` and :func:`git.util.decygpath`."""
229
217
230
218
_norm_cygpath_pairs = (
231
219
(R"foo\bar" , "foo/bar" ),
@@ -248,54 +236,70 @@ class TestUtils(TestBase):
248
236
(R"\\?\UNC\server\D$\Apps" , "//server/D$/Apps" ),
249
237
)
250
238
251
- # FIXME: Mark only the /proc-prefixing cases xfail, somehow (or fix them).
239
+ # FIXME: Mark only the /proc-prefixing cases xfail (or fix them).
252
240
@pytest .mark .xfail (
253
241
reason = "Many return paths prefixed /proc/cygdrive instead." ,
254
242
raises = AssertionError ,
255
243
)
256
- @skipUnless (sys .platform == "cygwin" , "Paths specifically for Cygwin." )
257
- @ddt .idata (_norm_cygpath_pairs + _unc_cygpath_pairs )
258
- def test_cygpath_ok (self , case ):
259
- wpath , cpath = case
244
+ @pytest .mark .parametrize ("wpath, cpath" , _norm_cygpath_pairs + _unc_cygpath_pairs )
245
+ def test_cygpath_ok (self , wpath , cpath ):
260
246
cwpath = cygpath (wpath )
261
- self . assertEqual ( cwpath , cpath , wpath )
247
+ assert cwpath == cpath , wpath
262
248
263
249
@pytest .mark .xfail (
264
250
reason = R'2nd example r".\bar" -> "bar" fails, returns "./bar"' ,
265
251
raises = AssertionError ,
266
252
)
267
- @skipUnless (sys .platform == "cygwin" , "Paths specifically for Cygwin." )
268
- @ddt .data (
269
- (R"./bar" , "bar" ),
270
- (R".\bar" , "bar" ), # FIXME: Mark only this one xfail, somehow (or fix it).
271
- (R"../bar" , "../bar" ),
272
- (R"..\bar" , "../bar" ),
273
- (R"../bar/.\foo/../chu" , "../bar/chu" ),
253
+ @pytest .mark .parametrize (
254
+ "wpath, cpath" ,
255
+ [
256
+ (R"./bar" , "bar" ),
257
+ (R".\bar" , "bar" ), # FIXME: Mark only this one xfail (or fix it).
258
+ (R"../bar" , "../bar" ),
259
+ (R"..\bar" , "../bar" ),
260
+ (R"../bar/.\foo/../chu" , "../bar/chu" ),
261
+ ],
274
262
)
275
- def test_cygpath_norm_ok (self , case ):
276
- wpath , cpath = case
263
+ def test_cygpath_norm_ok (self , wpath , cpath ):
277
264
cwpath = cygpath (wpath )
278
- self . assertEqual ( cwpath , cpath or wpath , wpath )
265
+ assert cwpath == ( cpath or wpath ) , wpath
279
266
280
- @skipUnless (sys .platform == "cygwin" , "Paths specifically for Cygwin." )
281
- @ddt .data (
282
- R"C:" ,
283
- R"C:Relative" ,
284
- R"D:Apps\123" ,
285
- R"D:Apps/123" ,
286
- R"\\?\a:rel" ,
287
- R"\\share\a:rel" ,
267
+ @pytest .mark .parametrize (
268
+ "wpath" ,
269
+ [
270
+ R"C:" ,
271
+ R"C:Relative" ,
272
+ R"D:Apps\123" ,
273
+ R"D:Apps/123" ,
274
+ R"\\?\a:rel" ,
275
+ R"\\share\a:rel" ,
276
+ ],
288
277
)
289
278
def test_cygpath_invalids (self , wpath ):
290
279
cwpath = cygpath (wpath )
291
- self . assertEqual ( cwpath , wpath .replace ("\\ " , "/" ), wpath )
280
+ assert cwpath == wpath .replace ("\\ " , "/" ), wpath
292
281
293
- @skipUnless (sys .platform == "cygwin" , "Paths specifically for Cygwin." )
294
- @ddt .idata (_norm_cygpath_pairs )
295
- def test_decygpath (self , case ):
296
- wpath , cpath = case
282
+ @pytest .mark .parametrize ("wpath, cpath" , _norm_cygpath_pairs )
283
+ def test_decygpath (self , wpath , cpath ):
297
284
wcpath = decygpath (cpath )
298
- self .assertEqual (wcpath , wpath .replace ("/" , "\\ " ), cpath )
285
+ assert wcpath == wpath .replace ("/" , "\\ " ), cpath
286
+
287
+
288
+ class _Member :
289
+ """A member of an IterableList."""
290
+
291
+ __slots__ = ("name" ,)
292
+
293
+ def __init__ (self , name ):
294
+ self .name = name
295
+
296
+ def __repr__ (self ):
297
+ return f"{ type (self ).__name__ } ({ self .name !r} )"
298
+
299
+
300
+ @ddt .ddt
301
+ class TestUtils (TestBase ):
302
+ """Tests for most utilities in :mod:`git.util`."""
299
303
300
304
def test_it_should_dashify (self ):
301
305
self .assertEqual ("this-is-my-argument" , dashify ("this_is_my_argument" ))
0 commit comments