Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0bbcf2f

Browse files
konstantin-popovByron
authored andcommitted
Add base class for package exceptions.
1 parentc121f60 commit0bbcf2f

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

‎AUTHORS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ Contributors are:
1717
-Phil Elson <pelson _dot_ pub _at_ gmail.com>
1818
-Bernard `Guyzmo` Pratz <guyzmo+gitpython+pub@m0g.net>
1919
-Timothy B. Hartman <tbhartman _at_ gmail.com>
20+
-Konstantin Popov <konstantin.popov.89 _at_ yandex.ru>
2021

2122
Portions derived from other open source works and are clearly marked.

‎git/exc.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,23 @@
99
fromgit.compatimportUnicodeMixin,safe_decode,string_types
1010

1111

12-
classInvalidGitRepositoryError(Exception):
12+
classGitError(Exception):
13+
""" Base class for all package exceptions """
14+
15+
16+
classInvalidGitRepositoryError(GitError):
1317
""" Thrown if the given repository appears to have an invalid format. """
1418

1519

1620
classWorkTreeRepositoryUnsupported(InvalidGitRepositoryError):
1721
""" Thrown to indicate we can't handle work tree repositories """
1822

1923

20-
classNoSuchPathError(OSError):
24+
classNoSuchPathError(GitError,OSError):
2125
""" Thrown if a path could not be access by the system. """
2226

2327

24-
classCommandError(UnicodeMixin,Exception):
28+
classCommandError(UnicodeMixin,GitError):
2529
"""Base class for exceptions thrown at every stage of `Popen()` execution.
2630
2731
:param command:
@@ -74,7 +78,7 @@ def __init__(self, command, status, stderr=None, stdout=None):
7478
super(GitCommandError,self).__init__(command,status,stderr,stdout)
7579

7680

77-
classCheckoutError(Exception):
81+
classCheckoutError(GitError):
7882
"""Thrown if a file could not be checked out from the index as it contained
7983
changes.
8084
@@ -98,7 +102,7 @@ def __str__(self):
98102
returnException.__str__(self)+":%s"%self.failed_files
99103

100104

101-
classCacheError(Exception):
105+
classCacheError(GitError):
102106

103107
"""Base for all errors related to the git index, which is called cache internally"""
104108

@@ -117,7 +121,7 @@ def __init__(self, command, status, stderr=None, stdout=None):
117121
self._msg=u"Hook('%s') failed%s"
118122

119123

120-
classRepositoryDirtyError(Exception):
124+
classRepositoryDirtyError(GitError):
121125
"""Thrown whenever an operation on a repository fails as it has uncommitted changes that would be overwritten"""
122126

123127
def__init__(self,repo,message):

‎git/test/test_exc.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@
1010

1111
importddt
1212
fromgit.excimport (
13+
InvalidGitRepositoryError,
14+
WorkTreeRepositoryUnsupported,
15+
NoSuchPathError,
1316
CommandError,
1417
GitCommandNotFound,
1518
GitCommandError,
19+
CheckoutError,
20+
CacheError,
21+
UnmergedEntriesError,
1622
HookExecutionError,
23+
RepositoryDirtyError,
1724
)
1825
fromgit.test.libimportTestBase
1926

@@ -44,6 +51,26 @@
4451
@ddt.ddt
4552
classTExc(TestBase):
4653

54+
deftest_ExceptionsHaveBaseClass(self):
55+
fromgit.excimportGitError
56+
self.assertIsInstance(GitError(),Exception)
57+
58+
exception_classes= [
59+
InvalidGitRepositoryError,
60+
WorkTreeRepositoryUnsupported,
61+
NoSuchPathError,
62+
CommandError,
63+
GitCommandNotFound,
64+
GitCommandError,
65+
CheckoutError,
66+
CacheError,
67+
UnmergedEntriesError,
68+
HookExecutionError,
69+
RepositoryDirtyError,
70+
]
71+
forex_classinexception_classes:
72+
self.assertTrue(issubclass(ex_class,GitError))
73+
4774
@ddt.data(*list(itt.product(_cmd_argvs,_causes_n_substrings,_streams_n_substrings)))
4875
deftest_CommandError_unicode(self,case):
4976
argv, (cause,subs),stream=case

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp