未验证 提交 a068168f 编写于 作者: L liym27 提交者: GitHub

[cherry-pick 2.0 beta][Dy2Stat-debugging] Fix bug: Returns True if the...

[cherry-pick 2.0 beta][Dy2Stat-debugging] Fix bug: Returns True if the verbosity level set by the user is greater than or equal to the log level (#26858) (#27052)

Change-Id: Iea4eb55f733e4751cb58c3caef35cb7664d2efa6
上级 83baab9b
...@@ -98,8 +98,15 @@ class TranslatorLogger(object): ...@@ -98,8 +98,15 @@ class TranslatorLogger(object):
return level == self.transformed_code_level return level == self.transformed_code_level
def has_verbosity(self, level): def has_verbosity(self, level):
"""
Checks whether the verbosity level set by the user is greater than or equal to the log level.
Args:
level(int): The level of log.
Returns:
True if the verbosity level set by the user is greater than or equal to the log level, otherwise False.
"""
level = self.check_level(level) level = self.check_level(level)
return level >= self.verbosity_level return self.verbosity_level >= level
def error(self, msg, *args, **kwargs): def error(self, msg, *args, **kwargs):
self.logger.error(msg, *args, **kwargs) self.logger.error(msg, *args, **kwargs)
......
...@@ -86,11 +86,11 @@ class TestLoggingUtils(unittest.TestCase): ...@@ -86,11 +86,11 @@ class TestLoggingUtils(unittest.TestCase):
with mock.patch.object(sys, 'stdout', stream): with mock.patch.object(sys, 'stdout', stream):
logging_utils.warn(warn_msg) logging_utils.warn(warn_msg)
logging_utils.error(error_msg) logging_utils.error(error_msg)
self.translator_logger.verbosity_level = 2 self.translator_logger.verbosity_level = 1
logging_utils.log(1, log_msg_1) logging_utils.log(1, log_msg_1)
logging_utils.log(2, log_msg_2) logging_utils.log(2, log_msg_2)
result_msg = '\n'.join([warn_msg, error_msg, log_msg_2, ""]) result_msg = '\n'.join([warn_msg, error_msg, log_msg_1, ""])
self.assertEqual(result_msg, stream.getvalue()) self.assertEqual(result_msg, stream.getvalue())
def test_log_transformed_code(self): def test_log_transformed_code(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册