1414import sys
1515import tempfile
1616import time
17- from unittest import SkipTest , mock , skipUnless
17+ from unittest import SkipTest , mock
1818
1919import ddt
2020import pytest
4545
4646@pytest .fixture
4747def 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."""
4949 td = tmp_path / "testdir"
5050 td .mkdir ()
5151 (td / "x" ).write_bytes (b"" )
@@ -211,21 +211,9 @@ def test_env_vars_for_windows_tests(self, name, env_var_value, expected_truth_va
211211 assert actual_parsed_value is expected_truth_value
212212
213213
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`."""
229217
230218 _norm_cygpath_pairs = (
231219 (R"foo\bar" , "foo/bar" ),
@@ -248,54 +236,70 @@ class TestUtils(TestBase):
248236 (R"\\?\UNC\server\D$\Apps" , "//server/D$/Apps" ),
249237 )
250238
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).
252240 @pytest .mark .xfail (
253241 reason = "Many return paths prefixed /proc/cygdrive instead." ,
254242 raises = AssertionError ,
255243 )
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 ):
260246 cwpath = cygpath (wpath )
261- self . assertEqual ( cwpath , cpath , wpath )
247+ assert cwpath == cpath , wpath
262248
263249 @pytest .mark .xfail (
264250 reason = R'2nd example r".\bar" -> "bar" fails, returns "./bar"' ,
265251 raises = AssertionError ,
266252 )
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+ ],
274262 )
275- def test_cygpath_norm_ok (self , case ):
276- wpath , cpath = case
263+ def test_cygpath_norm_ok (self , wpath , cpath ):
277264 cwpath = cygpath (wpath )
278- self . assertEqual ( cwpath , cpath or wpath , wpath )
265+ assert cwpath == ( cpath or wpath ) , wpath
279266
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+ ],
288277 )
289278 def test_cygpath_invalids (self , wpath ):
290279 cwpath = cygpath (wpath )
291- self . assertEqual ( cwpath , wpath .replace ("\\ " , "/" ), wpath )
280+ assert cwpath == wpath .replace ("\\ " , "/" ), wpath
292281
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 ):
297284 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`."""
299303
300304 def test_it_should_dashify (self ):
301305 self .assertEqual ("this-is-my-argument" , dashify ("this_is_my_argument" ))
0 commit comments