# Path: pypeman/tests/common.py
# def generate_msg(timestamp=None, message_content=default_message_content,
#                  message_meta=None, with_context=False):
#     """ generates a default message """
#     m = message.Message()
#     if timestamp:
#         if isinstance(timestamp, tuple):
#             m.timestamp = datetime.datetime(*timestamp)
#         else:  # assume it's a datetime object
#             m.timestamp = timestamp
#     else:  # just use current time
#         m.timestamp = datetime.datetime.utcnow()
# 
#     m.payload = message_content
# 
#     if message_meta is None:
#         m.meta = dict(default_message_meta)
#     else:
#         m.meta = message_meta
# 
#     if with_context:
#         # Add context message
#         mctx = generate_msg(message_content={'question': 'known'}, message_meta={'answer': 43})
#         m.add_context('test', mctx)
# 
#     return m
# 
# Path: pypeman/test.py
# class TearDownProjectTestCase(TestCase):
#     """ unittest for tests creating a project
# 
#     this testcase ensures, that at the end of the test the project is
#     removed
#     """
# 
#     def tearDown(self):
#         clear_pypeman_project()


import logging
from unittest import mock
from .common import generate_msg
from pypeman.message import Message
from pypeman.test import TearDownProjectTestCase as TestCase
        self.assertNotEqual(m.uuid, compare_to.uuid, "Uuid should not be copied")
        self.assertNotEqual(m.timestamp, compare_to.timestamp, "Timestamp should not be copied")
        self.assertEqual(m.meta['question'],
                         compare_to.meta['question'], "Bad meta copy")

        self.assertEqual(
            m.ctx['test']['payload']['question'],
            compare_to.ctx['test']['payload']['question'], "Bad ctx copy")
        self.assertEqual(m.ctx['test']['meta']['answer'],
                         compare_to.ctx['test']['meta']['answer'], "Bad ctx")

    def test_message_logging(self):
        """
        Whether message logging is working well.
        """
        m = generate_msg(message_content={'answer': 42}, with_context=True)

        mock_logger = mock.MagicMock()
        m.log(logger=mock_logger)

        mock_logger.log.assert_called_with(logging.DEBUG, 'Meta: %r', {'question': 'unknown'})
        mock_logger.reset()

        m.log(logger=mock_logger, payload=True, meta=True, context=True, log_level=logging.INFO)
        mock_logger.log.assert_called_with(logging.INFO, 'Meta: %r', {'answer': 43})

    def test_message_print(self):
        """
        Whether message print version is working well.
        """

# Path: pypeman/tests/common.py
# def generate_msg(timestamp=None, message_content=default_message_content,
#                  message_meta=None, with_context=False):
#     """ generates a default message """
#     m = message.Message()
#     if timestamp:
#         if isinstance(timestamp, tuple):
#             m.timestamp = datetime.datetime(*timestamp)
#         else:  # assume it's a datetime object
#             m.timestamp = timestamp
#     else:  # just use current time
#         m.timestamp = datetime.datetime.utcnow()
# 
#     m.payload = message_content
# 
#     if message_meta is None:
#         m.meta = dict(default_message_meta)
#     else:
#         m.meta = message_meta
# 
#     if with_context:
#         # Add context message
#         mctx = generate_msg(message_content={'question': 'known'}, message_meta={'answer': 43})
#         m.add_context('test', mctx)
# 
#     return m
# 
# Path: pypeman/test.py
# class TearDownProjectTestCase(TestCase):
#     """ unittest for tests creating a project
# 
#     this testcase ensures, that at the end of the test the project is
#     removed
#     """
# 
#     def tearDown(self):
#         clear_pypeman_project()


# Path: pypeman/tests/test_message.py
import logging
from unittest import mock
from .common import generate_msg
from pypeman.message import Message
from pypeman.test import TearDownProjectTestCase as TestCase

        self.assertNotEqual(m.uuid, compare_to.uuid, "Uuid should not be copied")
        self.assertNotEqual(m.timestamp, compare_to.timestamp, "Timestamp should not be copied")
        self.assertEqual(m.meta['question'],
                         compare_to.meta['question'], "Bad meta copy")

        self.assertEqual(
            m.ctx['test']['payload']['question'],
            compare_to.ctx['test']['payload']['question'], "Bad ctx copy")
        self.assertEqual(m.ctx['test']['meta']['answer'],
                         compare_to.ctx['test']['meta']['answer'], "Bad ctx")

    def test_message_logging(self):
        """
        Whether message logging is working well.
        """
        m = generate_msg(message_content={'answer': 42}, with_context=True)

        mock_logger = mock.MagicMock()
        m.log(logger=mock_logger)

        mock_logger.log.assert_called_with(logging.DEBUG, 'Meta: %r', {'question': 'unknown'})
        mock_logger.reset()

        m.log(logger=mock_logger, payload=True, meta=True, context=True, log_level=logging.INFO)
        mock_logger.log.assert_called_with(logging.INFO, 'Meta: %r', {'answer': 43})

    def test_message_print(self):
        """
        Whether message print version is working well.
        """

        m = generate_msg(