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