|
| 1 | +""" |
| 2 | +This file is part of CLIMADA. |
| 3 | +
|
| 4 | +Copyright (C) 2017 ETH Zurich, CLIMADA contributors listed in AUTHORS. |
| 5 | +
|
| 6 | +CLIMADA is free software: you can redistribute it and/or modify it under the |
| 7 | +terms of the GNU Lesser General Public License as published by the Free |
| 8 | +Software Foundation, version 3. |
| 9 | +
|
| 10 | +CLIMADA is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 | +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 12 | +PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 13 | +
|
| 14 | +You should have received a copy of the GNU Lesser General Public License along |
| 15 | +with CLIMADA. If not, see <https://www.gnu.org/licenses/>. |
| 16 | +
|
| 17 | +--- |
| 18 | +
|
| 19 | +Test config module. |
| 20 | +""" |
| 21 | +import unittest |
| 22 | +import logging |
| 23 | + |
| 24 | +from climada.util import log_level |
| 25 | + |
| 26 | +class TestUtilInit(unittest.TestCase): |
| 27 | + """Test util __init__ methods""" |
| 28 | + |
| 29 | + def test_log_level_pass(self): |
| 30 | + """Test log level context manager passes""" |
| 31 | + #Check loggers are set to level |
| 32 | + with self.assertLogs('climada', level='INFO') as cm: |
| 33 | + with log_level('WARNING'): |
| 34 | + logging.getLogger('climada').info('info') |
| 35 | + logging.getLogger('climada').error('error') |
| 36 | + self.assertEqual(cm.output, ['ERROR:climada:error']) |
| 37 | + #Check if only climada loggers level change |
| 38 | + with self.assertLogs('matplotlib', level='DEBUG') as cm: |
| 39 | + with log_level('ERROR', name_prefix='climada'): |
| 40 | + logging.getLogger('climada').info('info') |
| 41 | + logging.getLogger('matplotlib').debug('debug') |
| 42 | + self.assertEqual(cm.output, ['DEBUG:matplotlib:debug']) |
| 43 | + |
| 44 | +# Execute Tests |
| 45 | +if __name__ == "__main__": |
| 46 | + TESTS = unittest.TestLoader().loadTestsFromTestCase(TestUtilInit) |
| 47 | + unittest.TextTestRunner(verbosity=2).run(TESTS) |
0 commit comments