diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2016-10-22 11:11:25 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2016-10-22 11:11:25 +0200 |
commit | caa0ea7a0893fe90ea043843d4e6ad407126d7b8 (patch) | |
tree | 2f688eb182f2e76091134c47c4a327681c12e15b /git/test/test_util.py | |
parent | afcd64ebbb770908bd2a751279ff070dea5bb97c (diff) | |
parent | cc77e6b2862733a211c55cf29cc7a83c36c27919 (diff) | |
download | gitpython-caa0ea7a0893fe90ea043843d4e6ad407126d7b8.tar.gz |
Merge branch 'cygwin' of https://github.com/ankostis/GitPython into ankostis-cygwin
Diffstat (limited to 'git/test/test_util.py')
-rw-r--r-- | git/test/test_util.py | 90 |
1 files changed, 80 insertions, 10 deletions
diff --git a/git/test/test_util.py b/git/test/test_util.py index e07417b4..8f8d2272 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,37 @@ from git.util import ( BlockingLockFile, get_user_id, Actor, - IterableList + IterableList, + cygpath, + decygpath ) -from git.objects.util import ( - altz_to_utctz_str, - utctz_to_altz, - verify_utctz, - parse_date, + + +_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'), ) -from git.cmd import dashify -from git.compat import string_types, is_win -import time -import ddt +_unc_cygpath_pairs = ( + (r'\\?\a:\com', '/cygdrive/a/com'), + (r'\\?\a:/com', '/cygdrive/a/com'), + + (r'\\?\UNC\server\D$\Apps', '//server/D$/Apps'), +) class TestIterableMember(object): @@ -52,6 +82,46 @@ 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'./bar', 'bar'), + (r'.\bar', 'bar'), + (r'../bar', '../bar'), + (r'..\bar', '../bar'), + (r'../bar/.\foo/../chu', '../bar/chu'), + ) + def test_cygpath_norm_ok(self, case): + wpath, cpath = case + cwpath = cygpath(wpath) + self.assertEqual(cwpath, cpath or wpath, wpath) + + @skipIf(not is_win, "Paths specifically for Windows.") + @ddt.data( + 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, 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 + 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')) assert_equal('foo', dashify('foo')) |