'Various tests for log readers.
First of all, log readers can get logs by number and read what
was written to those log files. Getting nonexistent log files
raises C{ValueError}. Using anything other than an integer
index raises C{TypeError}. As logs get older, their log
numbers increase.'

def test_logReader(self):

    log = logfile.LogFile(self.name, self.dir)
    self.addCleanup(log.close)
    log.write('abc\n')
    log.write('def\n')
    log.rotate()
    log.write('ghi\n')
    log.flush()
    self.assertEqual(log.listLogs(), [1])
    with contextlib.closing(log.getCurrentLog()) as reader:
        reader._file.seek(0)
        self.assertEqual(reader.readLines(), ['ghi\n'])
        self.assertEqual(reader.readLines(), [])
    with contextlib.closing(log.getLog(1)) as reader:
        self.assertEqual(reader.readLines(), ['abc\n', 'def\n'])
        self.assertEqual(reader.readLines(), [])
    self.assertRaises(ValueError, log.getLog, 2)
    self.assertRaises(TypeError, log.getLog, '1')
    log.rotate()
    self.assertEqual(log.listLogs(), [1, 2])
    with contextlib.closing(log.getLog(1)) as reader:
        reader._file.seek(0)
        self.assertEqual(reader.readLines(), ['ghi\n'])
        self.assertEqual(reader.readLines(), [])
    with contextlib.closing(log.getLog(2)) as reader:
        self.assertEqual(reader.readLines(), ['abc\n', 'def\n'])
        self.assertEqual(reader.readLines(), [])
