From e6e23ed24b35c6154b4ee0da5ae51cd5688e5e67 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Thu, 13 Oct 2016 15:35:51 +0200 Subject: cygwin, #533: Try to make it work with Cygwin's Git. + Make `Git.polish_url()` convert paths into Cygwin-friendly paths. + Add utility and soe TCs for funcs for detecting cygwin and converting abs-paths to `/cygdrive/c/...`. - Cygwin TCs failing: - PY2: err: 14, fail: 3 - PY3: err: 13, fail: 3 --- git/test/test_util.py | 67 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 12 deletions(-) (limited to 'git/test/test_util.py') diff --git a/git/test/test_util.py b/git/test/test_util.py index e07417b4..eb9e16b2 100644 --- a/git/test/test_util.py +++ b/git/test/test_util.py @@ -5,7 +5,19 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php import tempfile +import time +from unittest.case import skipIf + +import ddt +from git.cmd import dashify +from git.compat import string_types, is_win +from git.objects.util import ( + altz_to_utctz_str, + utctz_to_altz, + verify_utctz, + parse_date, +) from git.test.lib import ( TestBase, assert_equal @@ -15,19 +27,9 @@ from git.util import ( BlockingLockFile, get_user_id, Actor, - IterableList + IterableList, + cygpath, ) -from git.objects.util import ( - altz_to_utctz_str, - utctz_to_altz, - verify_utctz, - parse_date, -) -from git.cmd import dashify -from git.compat import string_types, is_win - -import time -import ddt class TestIterableMember(object): @@ -52,6 +54,47 @@ class TestUtils(TestBase): "array": [42], } + @skipIf(not is_win, "Paths specifically for Windows.") + @ddt.data( + (r'foo\bar', 'foo/bar'), + (r'foo/bar', 'foo/bar'), + (r'./bar', 'bar'), + (r'.\bar', 'bar'), + (r'../bar', '../bar'), + (r'..\bar', '../bar'), + (r'../bar/.\foo/../chu', '../bar/chu'), + + (r'C:\Users', '/cygdrive/c/Users'), + (r'C:\d/e', '/cygdrive/c/d/e'), + + (r'\\?\a:\com', '/cygdrive/a/com'), + (r'\\?\a:/com', '/cygdrive/a/com'), + + (r'\\server\C$\Users', '//server/C$/Users'), + (r'\\server\C$', '//server/C$'), + (r'\\server\BAR/', '//server/BAR/'), + (r'\\?\UNC\server\D$\Apps', '//server/D$/Apps'), + + (r'D:/Apps', '/cygdrive/d/Apps'), + (r'D:/Apps\fOO', '/cygdrive/d/Apps/fOO'), + (r'D:\Apps/123', '/cygdrive/d/Apps/123'), + ) + def test_cygpath_ok(self, case): + wpath, cpath = case + self.assertEqual(cygpath(wpath), cpath or wpath) + + @skipIf(not is_win, "Paths specifically for Windows.") + @ddt.data( + (r'C:Relative', None), + (r'D:Apps\123', None), + (r'D:Apps/123', None), + (r'\\?\a:rel', None), + (r'\\share\a:rel', None), + ) + def test_cygpath_invalids(self, case): + wpath, cpath = case + self.assertEqual(cygpath(wpath), cpath or wpath.replace('\\', '/')) + def test_it_should_dashify(self): assert_equal('this-is-my-argument', dashify('this_is_my_argument')) assert_equal('foo', dashify('foo')) -- cgit v1.2.1 From 3b1cfcc629e856b1384b811b8cf30b92a1e34fe1 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Fri, 14 Oct 2016 16:43:52 +0200 Subject: cygwin, #533: Allow '/cygdrive/c/' paths on repo init - Cygwin TCs failing: - PY2: err: 13, fail: 2 - PY3: err: 12, fail: 2 --- git/test/test_util.py | 79 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 26 deletions(-) (limited to 'git/test/test_util.py') diff --git a/git/test/test_util.py b/git/test/test_util.py index eb9e16b2..8f8d2272 100644 --- a/git/test/test_util.py +++ b/git/test/test_util.py @@ -29,6 +29,34 @@ from git.util import ( Actor, IterableList, cygpath, + decygpath +) + + +_norm_cygpath_pairs = ( + (r'foo\bar', 'foo/bar'), + (r'foo/bar', 'foo/bar'), + + (r'C:\Users', '/cygdrive/c/Users'), + (r'C:\d/e', '/cygdrive/c/d/e'), + + ('C:\\', '/cygdrive/c/'), + + (r'\\server\C$\Users', '//server/C$/Users'), + (r'\\server\C$', '//server/C$'), + ('\\\\server\\c$\\', '//server/c$/'), + (r'\\server\BAR/', '//server/BAR/'), + + (r'D:/Apps', '/cygdrive/d/Apps'), + (r'D:/Apps\fOO', '/cygdrive/d/Apps/fOO'), + (r'D:\Apps/123', '/cygdrive/d/Apps/123'), +) + +_unc_cygpath_pairs = ( + (r'\\?\a:\com', '/cygdrive/a/com'), + (r'\\?\a:/com', '/cygdrive/a/com'), + + (r'\\?\UNC\server\D$\Apps', '//server/D$/Apps'), ) @@ -54,46 +82,45 @@ class TestUtils(TestBase): "array": [42], } + @skipIf(not is_win, "Paths specifically for Windows.") + @ddt.idata(_norm_cygpath_pairs + _unc_cygpath_pairs) + def test_cygpath_ok(self, case): + wpath, cpath = case + cwpath = cygpath(wpath) + self.assertEqual(cwpath, cpath, wpath) + @skipIf(not is_win, "Paths specifically for Windows.") @ddt.data( - (r'foo\bar', 'foo/bar'), - (r'foo/bar', 'foo/bar'), (r'./bar', 'bar'), (r'.\bar', 'bar'), (r'../bar', '../bar'), (r'..\bar', '../bar'), (r'../bar/.\foo/../chu', '../bar/chu'), - - (r'C:\Users', '/cygdrive/c/Users'), - (r'C:\d/e', '/cygdrive/c/d/e'), - - (r'\\?\a:\com', '/cygdrive/a/com'), - (r'\\?\a:/com', '/cygdrive/a/com'), - - (r'\\server\C$\Users', '//server/C$/Users'), - (r'\\server\C$', '//server/C$'), - (r'\\server\BAR/', '//server/BAR/'), - (r'\\?\UNC\server\D$\Apps', '//server/D$/Apps'), - - (r'D:/Apps', '/cygdrive/d/Apps'), - (r'D:/Apps\fOO', '/cygdrive/d/Apps/fOO'), - (r'D:\Apps/123', '/cygdrive/d/Apps/123'), ) - def test_cygpath_ok(self, case): + def test_cygpath_norm_ok(self, case): wpath, cpath = case - self.assertEqual(cygpath(wpath), cpath or wpath) + cwpath = cygpath(wpath) + self.assertEqual(cwpath, cpath or wpath, wpath) @skipIf(not is_win, "Paths specifically for Windows.") @ddt.data( - (r'C:Relative', None), - (r'D:Apps\123', None), - (r'D:Apps/123', None), - (r'\\?\a:rel', None), - (r'\\share\a:rel', None), + r'C:', + r'C:Relative', + r'D:Apps\123', + r'D:Apps/123', + r'\\?\a:rel', + r'\\share\a:rel', ) - def test_cygpath_invalids(self, case): + def test_cygpath_invalids(self, wpath): + cwpath = cygpath(wpath) + self.assertEqual(cwpath, wpath.replace('\\', '/'), wpath) + + @skipIf(not is_win, "Paths specifically for Windows.") + @ddt.idata(_norm_cygpath_pairs) + def test_decygpath(self, case): wpath, cpath = case - self.assertEqual(cygpath(wpath), cpath or wpath.replace('\\', '/')) + wcpath = decygpath(cpath) + self.assertEqual(wcpath, wpath.replace('/', '\\'), cpath) def test_it_should_dashify(self): assert_equal('this-is-my-argument', dashify('this_is_my_argument')) -- cgit v1.2.1