def test_group_handler_mail_combo(activation_strategy, logger): mail_handler = make_fake_mail_handler(level=logbook.DEBUG) handler = logbook.GroupHandler(mail_handler) with activation_strategy(handler): logger.error('The other way round') logger.warn('Testing') logger.debug('Even more') assert mail_handler.mails == [] assert len(mail_handler.mails) == 1 mail = mail_handler.mails[0][2] pieces = mail.split('Other log records in the same group:') assert len(pieces) == 2 body, rest = pieces rest = rest.replace('\r', '') assert re.search('Message type:\\s+ERROR', body) assert re.search('Module:\s+' + __name__, body) assert re.search('Function:\s+test_group_handler_mail_combo', body) related = rest.strip().split('\n\n') assert len(related) == 2 assert re.search('Message type:\s+WARNING', related[0]) assert re.search('Message type:\s+DEBUG', related[1])
def test_group_handler_mail_combo(self): mail_handler = make_fake_mail_handler(level=logbook.DEBUG) handler = logbook.GroupHandler(mail_handler) with handler: self.log.error('The other way round') self.log.warn('Testing') self.log.debug('Even more') self.assertEqual(mail_handler.mails, []) self.assertEqual(len(mail_handler.mails), 1) mail = mail_handler.mails[0][2] pieces = mail.split('Other log records in the same group:') self.assertEqual(len(pieces), 2) body, rest = pieces self.assert_(re.search('Message type:\s+ERROR', body)) self.assert_(re.search('Module:\s+logbook.testsuite.test_contextmanager', body)) self.assert_(re.search('Function:\s+test_group_handler_mail_combo', body)) related = rest.strip().split('\r\n\r\n') self.assertEqual(len(related), 2) self.assert_(re.search('Message type:\s+WARNING', related[0])) self.assert_(re.search('Message type:\s+DEBUG', related[1]))