# Path: ingenico/connect/sdk/log/sys_out_communicator_logger.py
# class SysOutCommunicatorLogger(CommunicatorLogger):
#     """
#     A communicator logger that prints its message to sys.stdout
#     It includes a timestamp in yyyy-MM-ddTHH:mm:ss format in the system time zone.
#     """
# 
#     def __init__(self):
#         CommunicatorLogger.__init__(self)
# 
#     _global_lock = Lock()
#     _old_print = print
# 
#     @staticmethod
#     def INSTANCE():
#         return _SYS_OUT_COMMUNICATOR_LOGGER_INSTANCE
# 
#     def __print(self, *a):
#         with self._global_lock:
#             self._old_print(*a)
# 
#     def log(self, message, thrown=None):
#         # Make sure the same object is used for locking and printing
#         self.__print(self.__get_date_prefix() + message)
#         if thrown:
#             self.__print(str(thrown))
# 
#     def __get_date_prefix(self):
#         return datetime.now().strftime("%Y-%m-%dT%H:%M:%S ")


import io
import re
import sys
import unittest
from ingenico.connect.sdk.log.sys_out_communicator_logger import SysOutCommunicatorLogger



class SysOutCommunicatorLoggerTest(unittest.TestCase):
    """Test if the SysOutCommunicatorLogger appropriately logs messages and exceptions"""

    def setUp(self):
        self.stdout = sys.stdout
        sys.stdout = self.mock_io = io.StringIO()

    def tearDown(self):
        sys.stdout = self.stdout
        self.mock_io.close()

    def test_log(self):
        """Test if the SysOutCommunicatorLogger correctly logs a message"""

        logger = SysOutCommunicatorLogger.INSTANCE()
        logger.log("test 123")

        text = self.mock_io.getvalue()
        self.assertMessage(text, "test 123")

    def test_log_exception(self):
        """Test if the SysOutCommunicatorLogger correctly logs an exception"""

# Path: ingenico/connect/sdk/log/sys_out_communicator_logger.py
# class SysOutCommunicatorLogger(CommunicatorLogger):
#     """
#     A communicator logger that prints its message to sys.stdout
#     It includes a timestamp in yyyy-MM-ddTHH:mm:ss format in the system time zone.
#     """
# 
#     def __init__(self):
#         CommunicatorLogger.__init__(self)
# 
#     _global_lock = Lock()
#     _old_print = print
# 
#     @staticmethod
#     def INSTANCE():
#         return _SYS_OUT_COMMUNICATOR_LOGGER_INSTANCE
# 
#     def __print(self, *a):
#         with self._global_lock:
#             self._old_print(*a)
# 
#     def log(self, message, thrown=None):
#         # Make sure the same object is used for locking and printing
#         self.__print(self.__get_date_prefix() + message)
#         if thrown:
#             self.__print(str(thrown))
# 
#     def __get_date_prefix(self):
#         return datetime.now().strftime("%Y-%m-%dT%H:%M:%S ")


# Path: tests/unit/test_sysout_communicator_logger.py
import io
import re
import sys
import unittest
from ingenico.connect.sdk.log.sys_out_communicator_logger import SysOutCommunicatorLogger




class SysOutCommunicatorLoggerTest(unittest.TestCase):
    """Test if the SysOutCommunicatorLogger appropriately logs messages and exceptions"""

    def setUp(self):
        self.stdout = sys.stdout
        sys.stdout = self.mock_io = io.StringIO()

    def tearDown(self):
        sys.stdout = self.stdout
        self.mock_io.close()

    def test_log(self):
        """Test if the SysOutCommunicatorLogger correctly logs a message"""

        logger = SysOutCommunicatorLogger.INSTANCE()
        logger.log("test 123")

        text = self.mock_io.getvalue()
        self.assertMessage(text, "test 123")

    def test_log_exception(self):
        """Test if the SysOutCommunicatorLogger correctly logs an exception"""

        logger = SysOutCommunicatorLogger.INSTANCE()