forked from pydoit/doit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--HG-- extra : convert_revision : eduardo%40eduardo-laptop-20100427152644-5ksuie1mstcgjz5q
- Loading branch information
1 parent
71a4571
commit 6af06f0
Showing
10 changed files
with
110 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
0.8 | ||
------ | ||
|
||
. task cleanup property | ||
. deprecate setup objects | ||
|
||
. support for depedency scanner (#218303) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import sys | ||
import traceback | ||
|
||
|
||
class CatchedException(object): | ||
"""This used to save info from catched exceptions | ||
The traceback from the original exception is saved | ||
""" | ||
def __init__(self, msg, exception=None): | ||
self.message = msg | ||
self.traceback = '' | ||
|
||
if isinstance(exception, CatchedException): | ||
self.traceback = exception.traceback | ||
elif exception is not None: | ||
self.traceback = traceback.format_exception( | ||
exception.__class__, exception, sys.exc_info()[2]) | ||
|
||
|
||
def get_msg(self): | ||
"""return full exception description (includes traceback)""" | ||
return "%s\n%s" % (self.message, "".join(self.traceback)) | ||
|
||
def get_name(self): | ||
return self.__class__.__name__ | ||
|
||
def __repr__(self): | ||
return "(<%s> %s)" % (self.get_name(), self.message) | ||
|
||
def __str__(self): | ||
return "%s\n%s" % (self.get_name(), self.get_msg()) | ||
|
||
|
||
class TaskFailed(CatchedException): | ||
"""Task execution was not successful.""" | ||
pass | ||
|
||
|
||
class TaskError(CatchedException): | ||
"""Error while trying to execute task.""" | ||
pass | ||
|
||
|
||
class SetupError(CatchedException): | ||
"""Error while trying to execute setup object""" | ||
pass | ||
|
||
|
||
class DependencyError(CatchedException): | ||
"""Error while trying to check if task is up-to-date""" | ||
pass | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from doit import exceptions | ||
|
||
|
||
class TestCatchedException(object): | ||
def test_name(self): | ||
class XYZ(exceptions.CatchedException): | ||
pass | ||
my_excp = XYZ("hello") | ||
assert 'XYZ' == my_excp.get_name() | ||
assert 'XYZ' in str(my_excp) | ||
assert 'XYZ' in repr(my_excp) | ||
|
||
def test_msg_notraceback(self): | ||
my_excp = exceptions.CatchedException('got you') | ||
msg = my_excp.get_msg() | ||
assert 'got you' in msg | ||
|
||
def test_exception(self): | ||
try: | ||
raise IndexError('too big') | ||
except Exception, e: | ||
my_excp = exceptions.CatchedException('got this', e) | ||
msg = my_excp.get_msg() | ||
assert 'got this' in msg | ||
assert 'too big' in msg | ||
assert 'IndexError' in msg | ||
|
||
def test_catched(self): | ||
try: | ||
raise IndexError('too big') | ||
except Exception, e: | ||
my_excp = exceptions.CatchedException('got this', e) | ||
my_excp2 = exceptions.CatchedException('handle that', my_excp) | ||
msg = my_excp2.get_msg() | ||
assert 'handle that' in msg | ||
assert 'got this' not in msg # could be there too... | ||
assert 'too big' in msg | ||
assert 'IndexError' in msg | ||
|
||
|
||
class TestAllCatched(object): | ||
def test(self): | ||
assert issubclass(exceptions.TaskFailed, exceptions.CatchedException) | ||
assert issubclass(exceptions.TaskError, exceptions.CatchedException) | ||
assert issubclass(exceptions.SetupError, exceptions.CatchedException) | ||
assert issubclass(exceptions.DependencyError, | ||
exceptions.CatchedException) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters