From 403ed13cfd77c32c527fda361bd2a6297b3ddb9a Mon Sep 17 00:00:00 2001
From: SKAJohanVenter <aventer@ska.ac.za>
Date: Thu, 1 Oct 2020 11:55:46 +0200
Subject: [PATCH] SAR-150 Updated test names. Simplified ThreadingLogsGenerator

---
 tests/test_transactions.py          |  4 +--
 tests/test_transactions_threaded.py | 40 ++++++++++-------------------
 2 files changed, 16 insertions(+), 28 deletions(-)

diff --git a/tests/test_transactions.py b/tests/test_transactions.py
index 445df74..91157d3 100644
--- a/tests/test_transactions.py
+++ b/tests/test_transactions.py
@@ -191,7 +191,7 @@ class TestTransactionLogging:
         assert last_log_message.funcName == "test_log_override_enter_exit_no_logger"
         assert last_log_message.filename == "test_transactions.py"
 
-    def test_specified_logger(self):
+    def test_specified_logger_is_used(self):
         logger = MagicMock()
         parameters = {}
         with transaction("name", parameters, logger=logger) as transaction_id:
@@ -200,7 +200,7 @@ class TestTransactionLogging:
             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}"
 
-    def test_unspecified_logger(self):
+    def test_unspecified_logger_is_not_used(self):
         logger = MagicMock()
         parameters = {}
         with transaction("name", parameters) as transaction_id:
diff --git a/tests/test_transactions_threaded.py b/tests/test_transactions_threaded.py
index b6b35fb..9696139 100644
--- a/tests/test_transactions_threaded.py
+++ b/tests/test_transactions_threaded.py
@@ -18,34 +18,22 @@ class ThreadingLogsGenerator:
         self.pass_logger = pass_logger
 
     def thread_with_transaction_exception(self, thread_index):
-        if self.pass_logger:
-            try:
-                with transaction(f"Transaction thread [{thread_index}]", logger=self.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(
-                        f"Transaction thread in transaction [{thread_index}], in transaction"
-                    )
-                    raise RuntimeError("An exception has occurred")
-            except RuntimeError:
-                pass
+        logger = self.logger if self.pass_logger else None
+        try:
+            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
 
     def thread_with_transaction(self, thread_index):
-        if self.pass_logger:
-            with transaction(f"Transaction thread [{thread_index}]", logger=self.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"Thread log [{thread_index}], no transaction")
+        logger = self.logger if self.pass_logger else None
+        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")
+
 
     def thread_without_transaction(self, thread_index):
         self.logger.info(f"Thread log [{thread_index}], no transaction")
-- 
GitLab