Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # Copyright (C) 2016 Intel Corporation |
| 4 | # Released under the MIT license (see COPYING.MIT) |
| 5 | |
| 6 | import unittest |
| 7 | import logging |
| 8 | import tempfile |
| 9 | |
| 10 | from common import setup_sys_path, TestBase |
| 11 | setup_sys_path() |
| 12 | |
| 13 | from oeqa.core.runner import OEStreamLogger |
| 14 | |
| 15 | class TestRunner(TestBase): |
| 16 | def test_stream_logger(self): |
| 17 | fp = tempfile.TemporaryFile(mode='w+') |
| 18 | |
| 19 | logging.basicConfig(format='%(message)s', stream=fp) |
| 20 | logger = logging.getLogger() |
| 21 | logger.setLevel(logging.INFO) |
| 22 | |
| 23 | oeSL = OEStreamLogger(logger) |
| 24 | |
| 25 | lines = ['init', 'bigline_' * 65535, 'morebigline_' * 65535 * 4, 'end'] |
| 26 | for line in lines: |
| 27 | oeSL.write(line) |
| 28 | |
| 29 | fp.seek(0) |
| 30 | fp_lines = fp.readlines() |
| 31 | for i, fp_line in enumerate(fp_lines): |
| 32 | fp_line = fp_line.strip() |
| 33 | self.assertEqual(lines[i], fp_line) |
| 34 | |
| 35 | fp.close() |
| 36 | |
| 37 | if __name__ == '__main__': |
| 38 | unittest.main() |