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 |
| 14 | |
| 15 | logger = logging.getLogger(__name__) |
| 16 | |
| 17 | |
| 18 | class TestCommon(unittest.TestCase): |
| 19 | """Test functions in common module.""" |
| 20 | |
| 21 | def setUp(self): |
| 22 | self.log_file = tempfile.mktemp() |
| 23 | |
| 24 | def tearDown(self): |
| 25 | if os.path.exists(self.log_file): |
| 26 | os.unlink(self.log_file) |
| 27 | |
| 28 | def test_logging(self): |
| 29 | parser = argparse.ArgumentParser() |
| 30 | common.add_common_arguments(parser) |
| 31 | opts = parser.parse_args(['--log_file', self.log_file]) |
| 32 | common.config_logging(opts) |
| 33 | |
| 34 | logger.debug('test') |
| 35 | self.assertIn('test', open(self.log_file).read()) |
| 36 | |
| 37 | |
| 38 | if __name__ == '__main__': |
| 39 | unittest.main() |