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

[Dy2Stat-debugging] Fix bug: Returns True if the verbosity level set by the...

[Dy2Stat-debugging] Fix bug: Returns True if the verbosity level set by the user is greater than or equal to the log level (#26858)
上级 1e50b2a6
......@@ -98,8 +98,15 @@ class TranslatorLogger(object):
return level == self.transformed_code_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)
return level >= self.verbosity_level
return self.verbosity_level >= level
def error(self, msg, *args, **kwargs):
self.logger.error(msg, *args, **kwargs)
......
......@@ -86,11 +86,11 @@ class TestLoggingUtils(unittest.TestCase):
with mock.patch.object(sys, 'stdout', stream):
logging_utils.warn(warn_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(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())
def test_log_transformed_code(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册