blob: a05c6288dd91fe7150fc4a5f207f972d672f8342 [file] [log] [blame]
Kuang-che Wu6e4beca2018-06-27 17:45:02 +08001# -*- coding: utf-8 -*-
Kuang-che Wue2fe6c32017-11-14 22:14:45 +08002# 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
7from __future__ import print_function
8import argparse
9import logging
10import os
11import tempfile
12import unittest
13
14from bisect_kit import common
Kuang-che Wue1b329e2018-03-31 11:39:33 +080015from bisect_kit import configure
Kuang-che Wue2fe6c32017-11-14 22:14:45 +080016
17logger = logging.getLogger(__name__)
18
19
20class 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 Wue1b329e2018-03-31 11:39:33 +080029 configure.reset()
Kuang-che Wue2fe6c32017-11-14 22:14:45 +080030
31 def test_logging(self):
Kuang-che Wue1b329e2018-03-31 11:39:33 +080032 common.init()
Kuang-che Wue2fe6c32017-11-14 22:14:45 +080033 parser = argparse.ArgumentParser()
34 common.add_common_arguments(parser)
35 opts = parser.parse_args(['--log_file', self.log_file])
36 common.config_logging(opts)
37
38 logger.debug('test')
Kuang-che Wua5723492019-11-25 20:59:34 +080039 with open(self.log_file) as f:
40 self.assertIn('test', f.read())
Kuang-che Wue2fe6c32017-11-14 22:14:45 +080041
42
43if __name__ == '__main__':
44 unittest.main()