1# Copyright 2017 The Abseil Authors. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""Tests -v/--verbosity flag and logging.root level's sync behavior.""" 16 17import logging 18 19assert logging.root.getEffectiveLevel() == logging.WARN, ( 20 'default logging.root level should be WARN, but found {}'.format( 21 logging.root.getEffectiveLevel())) 22 23# This is here to test importing logging won't change the level. 24logging.root.setLevel(logging.ERROR) 25 26assert logging.root.getEffectiveLevel() == logging.ERROR, ( 27 'logging.root level should be changed to ERROR, but found {}'.format( 28 logging.root.getEffectiveLevel())) 29 30from absl import flags 31from absl import logging as _ # pylint: disable=unused-import 32from absl.testing import absltest 33 34FLAGS = flags.FLAGS 35 36assert FLAGS['verbosity'].value == -1, ( 37 '-v/--verbosity should be -1 before flags are parsed.') 38 39assert logging.root.getEffectiveLevel() == logging.ERROR, ( 40 'logging.root level should be kept to ERROR, but found {}'.format( 41 logging.root.getEffectiveLevel())) 42 43 44class VerbosityFlagTest(absltest.TestCase): 45 46 def test_default_value_after_init(self): 47 self.assertEqual(0, FLAGS.verbosity) 48 self.assertEqual(logging.INFO, logging.root.getEffectiveLevel()) 49 50 51if __name__ == '__main__': 52 absltest.main() 53