blob: d6c93c0591f8a230aaccd2262eef67171b8c41b4 [file] [log] [blame]
Kuang-che Wue2fe6c32017-11-14 22:14:45 +08001# 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
6from __future__ import print_function
7import argparse
8import logging
9import os
10import tempfile
11import unittest
12
13from bisect_kit import common
Kuang-che Wue1b329e2018-03-31 11:39:33 +080014from bisect_kit import configure
Kuang-che Wue2fe6c32017-11-14 22:14:45 +080015
16logger = logging.getLogger(__name__)
17
18
19class 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 Wue1b329e2018-03-31 11:39:33 +080028 configure.reset()
Kuang-che Wue2fe6c32017-11-14 22:14:45 +080029
30 def test_logging(self):
Kuang-che Wue1b329e2018-03-31 11:39:33 +080031 common.init()
Kuang-che Wue2fe6c32017-11-14 22:14:45 +080032 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
41if __name__ == '__main__':
42 unittest.main()