Skip to content

Commit

Permalink
Merge pull request #14 from QualiSystems/feature/borismod_context2
Browse files Browse the repository at this point in the history
remove ContextBasedService
  • Loading branch information
Yaroslav Nikonorov committed Jul 25, 2016
2 parents ac6aaf4 + ffd55da commit ec41ab6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
17 changes: 0 additions & 17 deletions cloudshell/core/context/context_service.py

This file was deleted.

20 changes: 5 additions & 15 deletions cloudshell/core/context/error_handling_context.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import traceback

from cloudshell.core.context.context_service import ContextBasedService


class ErrorHandlingContext(ContextBasedService):
class ErrorHandlingContext(object):
def __init__(self, logger):
"""
Initializes an instance of ErrorHandlingContext
Expand All @@ -13,29 +11,21 @@ def __init__(self, logger):
"""
self.logger = logger

def get_objects(self):
"""
Returns context instance. Should not be called explicitly
:return: ErrorHandlingContext
:rtype ErrorHandlingContext
"""
return self

def context_started(self):
def __enter__(self):
"""
Called upon block start. Should not be called explicitly
:return: ErrorHandlingContext
:rtype ErrorHandlingContext
"""
return self

def context_ended(self, exc_type, exc_value, exc_traceback):
def __exit__(self, exc_type, exc_value, exc_traceback):
"""
Called upon block end. Should not be called explicitly
In case of exception during the block execution logs the error with debug severity
and allows the same exception to be thrown
:return: ErrorHandlingContext
:rtype ErrorHandlingContext
:return: True means exception handles, otherwise false
:rtype: bool
"""
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
self.logger.error('Error occurred: ' + ''.join(lines))
Expand Down
2 changes: 1 addition & 1 deletion tests/core/context/test_error_handling_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from cloudshell.core.context.error_handling_context import ErrorHandlingContext


class TestLoggingSession(TestCase):
class TestErrorHandlingContext(TestCase):

def test_log_written_when_exception_occurs(self):
logger = Mock()
Expand Down

0 comments on commit ec41ab6

Please sign in to comment.