Kuang-che Wu | 6e4beca | 2018-06-27 17:45:02 +0800 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Kuang-che Wu | e2fe6c3 | 2017-11-14 22:14:45 +0800 | [diff] [blame] | 2 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | """Test common module.""" |
| 6 | |
| 7 | from __future__ import print_function |
| 8 | import argparse |
| 9 | import logging |
| 10 | import os |
| 11 | import tempfile |
| 12 | import unittest |
| 13 | |
| 14 | from bisect_kit import common |
Kuang-che Wu | e1b329e | 2018-03-31 11:39:33 +0800 | [diff] [blame] | 15 | from bisect_kit import configure |
Kuang-che Wu | e2fe6c3 | 2017-11-14 22:14:45 +0800 | [diff] [blame] | 16 | |
| 17 | logger = logging.getLogger(__name__) |
| 18 | |
| 19 | |
| 20 | class TestCommon(unittest.TestCase): |
| 21 | """Test functions in common module.""" |
| 22 | |
| 23 | def setUp(self): |
| 24 | self.log_file = tempfile.mktemp() |
| 25 | |
| 26 | def tearDown(self): |
| 27 | if os.path.exists(self.log_file): |
| 28 | os.unlink(self.log_file) |
Kuang-che Wu | e1b329e | 2018-03-31 11:39:33 +0800 | [diff] [blame] | 29 | configure.reset() |
Kuang-che Wu | e2fe6c3 | 2017-11-14 22:14:45 +0800 | [diff] [blame] | 30 | |
| 31 | def test_logging(self): |
Kuang-che Wu | e1b329e | 2018-03-31 11:39:33 +0800 | [diff] [blame] | 32 | common.init() |
Kuang-che Wu | d2d6e41 | 2021-01-28 16:26:41 +0800 | [diff] [blame^] | 33 | parents = [common.common_argument_parser] |
| 34 | parser = argparse.ArgumentParser(parents=parents) |
Kuang-che Wu | e2fe6c3 | 2017-11-14 22:14:45 +0800 | [diff] [blame] | 35 | opts = parser.parse_args(['--log_file', self.log_file]) |
| 36 | common.config_logging(opts) |
| 37 | |
| 38 | logger.debug('test') |
Kuang-che Wu | a572349 | 2019-11-25 20:59:34 +0800 | [diff] [blame] | 39 | with open(self.log_file) as f: |
| 40 | self.assertIn('test', f.read()) |
Kuang-che Wu | e2fe6c3 | 2017-11-14 22:14:45 +0800 | [diff] [blame] | 41 | |
| 42 | |
| 43 | if __name__ == '__main__': |
| 44 | unittest.main() |