Ejemplo n.º 1
0
    def test_level_filtration(self):
        task2.LOGGING_LEVEL = logging.WARNING

        lines = task2.file_iterator(LOG_FILES[1], 'a')
        self.assertEqual(len(list(lines)), 2)

        task2.LOGGING_LEVEL = logging.ERROR

        lines = task2.file_iterator(LOG_FILES[1], 'a')
        self.assertEqual(len(list(lines)), 1)
Ejemplo n.º 2
0
        '[Wed Oct 24 2012 8:32:52 +0200] [error] [client 127.0.0.1] log1',
        '[Wed Oct 24 2012 11:32:52 +0200] [error] [client 127.0.0.1] log4'
    ],
    [
        '[Wed Oct 24 2012 9:32:52 +0200] [error] [client 127.0.0.1] log2',
        '[Wed Oct 24 2012 12:32:52 +0200] [info] [client 127.0.0.1] log5',
        '[Wed Oct 24 2012 14:32:52 +0200] [warning] [client 127.0.0.1] log7'
    ],
    [
        '[Wed Oct 24 2012 10:32:52 +0200] [error] [client 127.0.0.1] log3',
        '[Wed Oct 24 2012 13:32:52 +0200] [error] [client 127.0.0.1] log6'
    ],
]

SOURCES = {
    'a': task2.file_iterator(LOG_FILES[0], 'a'),
    'b': task2.file_iterator(LOG_FILES[1], 'b'),
    'c': task2.file_iterator(LOG_FILES[2], 'c')
}


class MergeFilesTest(unittest.TestCase):
    @patch('task2.open_sources', return_value=SOURCES)
    def test_merge(self, isfile):
        task2.LOGGING_LEVEL = logging.DEBUG

        res = task2.merge_log_files(['a', 'b', 'c'])

        logs = [line[-1] for line in res]
        self.assertEqual(logs, map(str, range(1, 8)))