test that 4 occurences of log "skipping url replacement" are found

This commit is contained in:
Bruno Binet 2012-11-30 15:10:51 +01:00
commit a6dd3178b1
2 changed files with 26 additions and 0 deletions

View file

@ -8,6 +8,8 @@ import os
import re
import subprocess
import sys
import logging
from logging.handlers import BufferingHandler
from functools import wraps
from contextlib import contextmanager
@ -157,3 +159,18 @@ def get_settings():
settings['DIRECT_TEMPLATES'] = ['archives']
settings['filenames'] = {}
return settings
class LogCountHandler(BufferingHandler):
"""
Capturing and counting logged messages.
"""
def __init__(self, capacity=1000):
logging.handlers.BufferingHandler.__init__(self, capacity)
def count_logs(self, msg=None, level=None):
return len([l for l in self.buffer
if (msg is None or re.match(msg, l.getMessage()))
and (level is None or l.levelno == level)
])