summaryrefslogtreecommitdiff
path: root/git/test
diff options
context:
space:
mode:
Diffstat (limited to 'git/test')
-rw-r--r--git/test/test_exc.py142
-rw-r--r--git/test/test_git.py6
-rw-r--r--git/test/test_index.py2
-rw-r--r--git/test/test_util.py3
4 files changed, 148 insertions, 5 deletions
diff --git a/git/test/test_exc.py b/git/test/test_exc.py
new file mode 100644
index 00000000..7e6b023e
--- /dev/null
+++ b/git/test/test_exc.py
@@ -0,0 +1,142 @@
+# -*- coding: utf-8 -*-
+# test_exc.py
+# Copyright (C) 2008, 2009, 2016 Michael Trier (mtrier@gmail.com) and contributors
+#
+# This module is part of GitPython and is released under
+# the BSD License: http://www.opensource.org/licenses/bsd-license.php
+
+
+import re
+
+import ddt
+from git.exc import (
+ CommandError,
+ GitCommandNotFound,
+ GitCommandError,
+ HookExecutionError,
+)
+from git.test.lib import TestBase
+
+import itertools as itt
+
+
+_cmd_argvs = (
+ ('cmd', ),
+ ('θνιψοδε', ),
+ ('θνιψοδε', 'normal', 'argvs'),
+ ('cmd', 'ελληνικα', 'args'),
+ ('θνιψοδε', 'κι', 'αλλα', 'strange', 'args'),
+ ('θνιψοδε', 'κι', 'αλλα', 'non-unicode', 'args'),
+)
+_causes_n_substrings = (
+ (None, None), # noqa: E241
+ (7, "exit code(7)"), # noqa: E241
+ ('Some string', "'Some string'"), # noqa: E241
+ ('παλιο string', "'παλιο string'"), # noqa: E241
+ (Exception("An exc."), "Exception('An exc.')"), # noqa: E241
+ (Exception("Κακια exc."), "Exception('Κακια exc.')"), # noqa: E241
+ (object(), "<object object at "), # noqa: E241
+)
+
+_streams_n_substrings = (None, 'steram', 'ομορφο stream', )
+
+
+@ddt.ddt
+class TExc(TestBase):
+
+ @ddt.data(*list(itt.product(_cmd_argvs, _causes_n_substrings, _streams_n_substrings)))
+ def test_CommandError_unicode(self, case):
+ argv, (cause, subs), stream = case
+ cls = CommandError
+ c = cls(argv, cause)
+ s = str(c)
+
+ self.assertIsNotNone(c._msg)
+ self.assertIn(' cmdline: ', s)
+
+ for a in argv:
+ self.assertIn(a, s)
+
+ if not cause:
+ self.assertIn("failed!", s)
+ else:
+ self.assertIn(" failed due to:", s)
+
+ if subs is not None:
+ # Substrings (must) already contain opening `'`.
+ subs = "(?<!')%s(?!')" % re.escape(subs)
+ self.assertRegexpMatches(s, subs)
+
+ if not stream:
+ c = cls(argv, cause)
+ s = str(c)
+ self.assertNotIn(" stdout:", s)
+ self.assertNotIn(" stderr:", s)
+ else:
+ c = cls(argv, cause, stream)
+ s = str(c)
+ self.assertIn(" stderr:", s)
+ self.assertIn(stream, s)
+
+ c = cls(argv, cause, None, stream)
+ s = str(c)
+ self.assertIn(" stdout:", s)
+ self.assertIn(stream, s)
+
+ c = cls(argv, cause, stream, stream + 'no2')
+ s = str(c)
+ self.assertIn(" stderr:", s)
+ self.assertIn(stream, s)
+ self.assertIn(" stdout:", s)
+ self.assertIn(stream + 'no2', s)
+
+ @ddt.data(
+ (['cmd1'], None),
+ (['cmd1'], "some cause"),
+ (['cmd1'], Exception()),
+ )
+ def test_GitCommandNotFound(self, init_args):
+ argv, cause = init_args
+ c = GitCommandNotFound(argv, cause)
+ s = str(c)
+
+ self.assertIn(argv[0], s)
+ if cause:
+ self.assertIn(' not found due to: ', s)
+ self.assertIn(str(cause), s)
+ else:
+ self.assertIn(' not found!', s)
+
+ @ddt.data(
+ (['cmd1'], None),
+ (['cmd1'], "some cause"),
+ (['cmd1'], Exception()),
+ )
+ def test_GitCommandError(self, init_args):
+ argv, cause = init_args
+ c = GitCommandError(argv, cause)
+ s = str(c)
+
+ self.assertIn(argv[0], s)
+ if cause:
+ self.assertIn(' failed due to: ', s)
+ self.assertIn(str(cause), s)
+ else:
+ self.assertIn(' failed!', s)
+
+ @ddt.data(
+ (['cmd1'], None),
+ (['cmd1'], "some cause"),
+ (['cmd1'], Exception()),
+ )
+ def test_HookExecutionError(self, init_args):
+ argv, cause = init_args
+ c = HookExecutionError(argv, cause)
+ s = str(c)
+
+ self.assertIn(argv[0], s)
+ if cause:
+ self.assertTrue(s.startswith('Hook('), s)
+ self.assertIn(str(cause), s)
+ else:
+ self.assertIn(' failed!', s)
diff --git a/git/test/test_git.py b/git/test/test_git.py
index a676d7f7..8a0242e6 100644
--- a/git/test/test_git.py
+++ b/git/test/test_git.py
@@ -27,6 +27,7 @@ from git import (
from git.test.lib import with_rw_directory
from git.compat import PY3, is_darwin
+from git.util import finalize_process
try:
from unittest import mock
@@ -233,7 +234,8 @@ class TestGit(TestBase):
def counter_stderr(line):
count[2] += 1
- proc = subprocess.Popen([sys.executable, fixture_path('cat_file.py'), str(fixture_path('issue-301_stderr'))],
+ cmdline = [sys.executable, fixture_path('cat_file.py'), str(fixture_path('issue-301_stderr'))]
+ proc = subprocess.Popen(cmdline,
stdin=None,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
@@ -241,7 +243,7 @@ class TestGit(TestBase):
creationflags=cmd.PROC_CREATIONFLAGS,
)
- handle_process_output(proc, counter_stdout, counter_stderr, lambda proc: proc.wait())
+ handle_process_output(proc, counter_stdout, counter_stderr, finalize_process)
self.assertEqual(count[1], line_count)
self.assertEqual(count[2], line_count)
diff --git a/git/test/test_index.py b/git/test/test_index.py
index c78890ae..08d6491d 100644
--- a/git/test/test_index.py
+++ b/git/test/test_index.py
@@ -730,7 +730,7 @@ class TestIndex(TestBase):
index.commit("This should fail")
except HookExecutionError as err:
if is_win:
- self.assertIsInstance(err.status, WindowsError)
+ self.assertIsInstance(err.status, OSError)
self.assertEqual(err.command, hp)
self.assertIsNone(err.stdout)
self.assertIsNone(err.stderr)
diff --git a/git/test/test_util.py b/git/test/test_util.py
index 9fc159df..eae9fbc7 100644
--- a/git/test/test_util.py
+++ b/git/test/test_util.py
@@ -90,10 +90,9 @@ class TestUtils(TestBase):
wait_lock = BlockingLockFile(my_file, 0.05, wait_time)
self.failUnlessRaises(IOError, wait_lock._obtain_lock)
elapsed = time.time() - start
- # More extra time costs, but...
extra_time = 0.2
if is_win:
- extra_time *= 4
+ extra_time *= 6 # NOTE: Indeterministic failures here...
self.assertLess(elapsed, wait_time + 0.02)
def test_user_id(self):