Skip to content

Commit

Permalink
Merge pull request #13 from QualiSystems/feature/borismod_context2
Browse files Browse the repository at this point in the history
remove context from ctor of ErrorHandlingContext
  • Loading branch information
borismod committed Jul 24, 2016
2 parents 2e3f769 + fc81fb1 commit ac6aaf4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
6 changes: 1 addition & 5 deletions cloudshell/core/context/context_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@


class ContextBasedService(object):
@abstractmethod
def get_objects(self):
pass

@abstractmethod
def context_started(self):
pass
Expand All @@ -15,7 +11,7 @@ def context_ended(self, exc_type, exc_val, exc_tb):
pass

def __enter__(self):
self.context_started()
return self.context_started()

def __exit__(self, exc_type, exc_val, exc_tb):
self.context_ended(exc_type, exc_val, exc_tb)
4 changes: 1 addition & 3 deletions cloudshell/core/context/error_handling_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@


class ErrorHandlingContext(ContextBasedService):
def __init__(self, context, logger):
def __init__(self, logger):
"""
Initializes an instance of ErrorHandlingContext
Allows proper logging on exception
:param context: ResourceCommandContext
:param logger: Logger
:type logger: Logger
"""
self.context = context
self.logger = logger

def get_objects(self):
Expand Down
3 changes: 1 addition & 2 deletions tests/core/context/test_error_handling_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
class TestLoggingSession(TestCase):

def test_log_written_when_exception_occurs(self):
context = Mock()
logger = Mock()
logger.error = MagicMock()
try:
with ErrorHandlingContext(context=context, logger=logger):
with ErrorHandlingContext(logger=logger):
raise ValueError('some value error occurred')
except ValueError:
self.assertTrue(logger.error.called)
Expand Down

0 comments on commit ac6aaf4

Please sign in to comment.