Skip to content
Snippets Groups Projects
Unverified Commit 403ed13c authored by SKAJohanVenter's avatar SKAJohanVenter
Browse files

SAR-150 Updated test names. Simplified ThreadingLogsGenerator

parent 569def50
No related branches found
No related tags found
No related merge requests found
...@@ -191,7 +191,7 @@ class TestTransactionLogging: ...@@ -191,7 +191,7 @@ class TestTransactionLogging:
assert last_log_message.funcName == "test_log_override_enter_exit_no_logger" assert last_log_message.funcName == "test_log_override_enter_exit_no_logger"
assert last_log_message.filename == "test_transactions.py" assert last_log_message.filename == "test_transactions.py"
def test_specified_logger(self): def test_specified_logger_is_used(self):
logger = MagicMock() logger = MagicMock()
parameters = {} parameters = {}
with transaction("name", parameters, logger=logger) as transaction_id: with transaction("name", parameters, logger=logger) as transaction_id:
...@@ -200,7 +200,7 @@ class TestTransactionLogging: ...@@ -200,7 +200,7 @@ class TestTransactionLogging:
assert logger.info.call_args_list[i].starts_with(message) assert logger.info.call_args_list[i].starts_with(message)
assert logger.info.call_count == 4, f"Log calls incorrect {logger.info.call_args_list}" assert logger.info.call_count == 4, f"Log calls incorrect {logger.info.call_args_list}"
def test_unspecified_logger(self): def test_unspecified_logger_is_not_used(self):
logger = MagicMock() logger = MagicMock()
parameters = {} parameters = {}
with transaction("name", parameters) as transaction_id: with transaction("name", parameters) as transaction_id:
......
...@@ -18,18 +18,9 @@ class ThreadingLogsGenerator: ...@@ -18,18 +18,9 @@ class ThreadingLogsGenerator:
self.pass_logger = pass_logger self.pass_logger = pass_logger
def thread_with_transaction_exception(self, thread_index): def thread_with_transaction_exception(self, thread_index):
if self.pass_logger: logger = self.logger if self.pass_logger else None
try: try:
with transaction(f"Transaction thread [{thread_index}]", logger=self.logger): with transaction(f"Transaction thread [{thread_index}]", logger=logger):
self.logger.info(
f"Transaction thread in transaction [{thread_index}], in transaction"
)
raise RuntimeError("An exception has occurred")
except RuntimeError:
pass
else:
try:
with transaction(f"Transaction thread [{thread_index}]"):
self.logger.info( self.logger.info(
f"Transaction thread in transaction [{thread_index}], in transaction" f"Transaction thread in transaction [{thread_index}], in transaction"
) )
...@@ -38,15 +29,12 @@ class ThreadingLogsGenerator: ...@@ -38,15 +29,12 @@ class ThreadingLogsGenerator:
pass pass
def thread_with_transaction(self, thread_index): def thread_with_transaction(self, thread_index):
if self.pass_logger: logger = self.logger if self.pass_logger else None
with transaction(f"Transaction thread [{thread_index}]", logger=self.logger): with transaction(f"Transaction thread [{thread_index}]", logger=logger):
self.logger.info(f"Transaction thread [{thread_index}], in transaction")
self.logger.info(f"Thread log [{thread_index}], no transaction")
else:
with transaction(f"Transaction thread [{thread_index}]"):
self.logger.info(f"Transaction thread [{thread_index}], in transaction") self.logger.info(f"Transaction thread [{thread_index}], in transaction")
self.logger.info(f"Thread log [{thread_index}], no transaction") self.logger.info(f"Thread log [{thread_index}], no transaction")
def thread_without_transaction(self, thread_index): def thread_without_transaction(self, thread_index):
self.logger.info(f"Thread log [{thread_index}], no transaction") self.logger.info(f"Thread log [{thread_index}], no transaction")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment