Exemplo n.º 1
0
 def test_pp_dis_enabled(self, pformat):
     pformat.return_value = 'something pprinted'
     logger = mock.MagicMock()
     logger.isEnabledFor.return_value = False
     lg = getLogger()
     lg.pprint('object', logger=logger)
     self.assertFalse(logger._log.called)
Exemplo n.º 2
0
 def test_pp_enabled(self, pformat):
     pformat.return_value = 'something pprinted'
     logger = mock.MagicMock()
     logger.isEnabledFor.return_value = True
     lg = getLogger()
     lg.pprint('object', logger=logger)
     logger._log.assert_called_with(logging.DEBUG, '\nsomething pprinted', [], {})
Exemplo n.º 3
0
 def test_logger_before_queries(self, connection):
     connection.queries = [1, 2]
     logger = mock.MagicMock()
     logger.isEnabledFor.return_value = True
     lg = getLogger()
     lg.before_queries(txt='object', logger=logger)
     logger._log.assert_called_with(logging.DEBUG, 'object', [], {})
     self.assertEqual(logger._num_queries, 2)
Exemplo n.º 4
0
 def test_logger_before_queries_notxt(self, connection):
     connection.queries = [1, 2]
     logger = mock.MagicMock()
     logger.isEnabledFor.return_value = True
     lg = getLogger()
     lg.before_queries(logger=logger)
     self.assertFalse(logger._log.called)
     self.assertEqual(logger._num_queries, 2)
Exemplo n.º 5
0
    def test_logger(self):
        func = mock.MagicMock(return_value=None, name='logger', spec=['func_code'])

        func_code = mock.MagicMock(name='func_code')
        func.func_code = func_code

        func_code.co_filename = 'file name'
        func_code.co_firstlineno = 23
        func_code.co_name = 'name'

        logger = mock.MagicMock()

        lg = getLogger()
        lg.callable(func, logger=logger)
        logger._log.assert_called_with(logging.DEBUG, 'file name:23 name', [], {})
Exemplo n.º 6
0
    def test_logger_alert(self):
        logger = mock.MagicMock()

        lg = getLogger()
        lg.alert('object', marker='1', logger=logger)
        bannerEdge = '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'

        calls = [
            mock.call(logging.DEBUG, bannerEdge, [], {}),
            mock.call(logging.DEBUG, bannerEdge, [], {}),
            mock.call(logging.DEBUG, '                                     object', [], {}),
            mock.call(logging.DEBUG, bannerEdge, [], {}),
            mock.call(logging.DEBUG, bannerEdge, [], {}),

        ]
        logger._log.assert_has_calls(calls)
Exemplo n.º 7
0
    def test_logger_after_queries_enabled(self, connection):
        logger = mock.MagicMock()
        logger._num_queries = 1
        qry1 = {'name': 'qry1', 'time': '1', 'sql': 'select'}
        qry2 = {'name': 'qry2', 'time': '2', 'sql': 'insert'}
        qry3 = {'name': 'qry3', 'time': '3', 'sql': 'update'}

        connection.queries = [qry1, qry2, qry3]
        logger.isEnabledFor.return_value = True

        lg = getLogger()
        lg.after_queries(obj='object', logger=logger)

        calls = [
            mock.call(logging.DEBUG, 'Database hits: 2', [], {}),
            mock.call(logging.DEBUG, 'Database hit, 2 seconds\ninsert', [], {}),
            mock.call(logging.DEBUG, 'Database hit, 3 seconds\nupdate', [], {}),
        ]
        logger._log.assert_has_calls(calls)
Exemplo n.º 8
0
 def test_logger_callable(self):
     with self.assertRaises(AssertionError):
         logger = getLogger()
         logger.callable('some var', logger=None)
Exemplo n.º 9
0
 def test_logger_before_disabled(self):
     logger = mock.MagicMock()
     logger.isEnabledFor.return_value = False
     lg = getLogger()
     lg.before_queries(txt='object', logger=logger)
     self.assertFalse(logger._log.called)