Merge "More Unit Tests for utils module"
[functest.git] / functest / tests / unit / utils / test_functest_logger.py
1 #!/usr/bin/env python
2
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
7
8 import logging
9 import unittest
10
11 import mock
12
13 from functest.utils import functest_logger
14 from functest.utils.constants import CONST
15
16
17 class OSUtilsLogger(unittest.TestCase):
18
19     logging.disable(logging.CRITICAL)
20
21     def setUp(self):
22         with mock.patch('__builtin__.open', mock.mock_open()):
23             with mock.patch('functest.utils.functest_logger.os.path.exists',
24                             return_value=True), \
25                 mock.patch('functest.utils.functest_logger.'
26                            'json.load'), \
27                 mock.patch('functest.utils.functest_logger.'
28                            'logging.config.dictConfig') as m:
29                 self.logger = functest_logger.Logger('os_utils')
30                 self.assertTrue(m.called)
31             with mock.patch('functest.utils.functest_logger.os.path.exists',
32                             return_value=False), \
33                 mock.patch('functest.utils.functest_logger.'
34                            'logging.basicConfig') as m:
35                 self.logger = functest_logger.Logger('os_utils')
36                 self.assertTrue(m.called)
37
38     def test_is_debug_false(self):
39         CONST.CI_DEBUG = False
40         self.assertFalse(self.logger.is_debug())
41
42     def test_is_debug_true(self):
43         CONST.CI_DEBUG = "True"
44         self.assertTrue(self.logger.is_debug())
45
46
47 if __name__ == "__main__":
48     unittest.main(verbosity=2)