Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1604)

Unified Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/system/logtesting_unittest.py

Issue 2373833002: In the logtesting support module, fix the setting of logging level. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Tools/Scripts/webkitpy/common/system/logtesting.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Tools/Scripts/webkitpy/common/system/logtesting_unittest.py
diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/common/system/logtesting_unittest.py b/third_party/WebKit/Tools/Scripts/webkitpy/common/system/logtesting_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..61c30c33aa529f9a0941e72415ce692065e764bc
--- /dev/null
+++ b/third_party/WebKit/Tools/Scripts/webkitpy/common/system/logtesting_unittest.py
@@ -0,0 +1,60 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import logging
+import unittest
+
+from webkitpy.common.system.logtesting import LoggingTestCase, LogTesting, TestLogStream
+
+
+class TestLogStreamTest(unittest.TestCase):
+
+ def test_passed_to_stream_handler(self):
+ stream = TestLogStream(self)
+ handler = logging.StreamHandler(stream)
+ logger = logging.getLogger('test.logger')
+ logger.addHandler(handler)
+ logger.setLevel(logging.INFO)
+ logger.info('bar')
+ stream.assertMessages(['bar\n'])
+
+ def test_direct_use(self):
+ stream = TestLogStream(self)
+ stream.write('foo')
+ stream.flush()
+ stream.assertMessages(['foo'])
+
+
+class LogTestingTest(unittest.TestCase):
+
+ def test_basic(self):
+ log_testing_instance = LogTesting.setUp(self)
+ logger = logging.getLogger('test.logger')
+ logger.info('my message')
+ log_testing_instance.assertMessages(['INFO: my message\n'])
+ # The list of messages is cleared after being checked once.
+ log_testing_instance.assertMessages([])
+
+ def test_log_level_warning(self):
+ log_testing_instance = LogTesting.setUp(self, logging_level=logging.WARNING)
+ logger = logging.getLogger('test.logger')
+ logger.info('my message')
+ log_testing_instance.assertMessages([])
+
+
+class LoggingTestCaseTest(LoggingTestCase):
+
+ def test_basic(self):
+ self.example_logging_code()
+ self.assertLog([
+ 'INFO: Informative message\n',
+ 'WARNING: Warning message\n',
+ ])
+
+ @staticmethod
+ def example_logging_code():
+ logger = logging.getLogger('test.logger')
+ logger.debug('Debugging message')
+ logger.info('Informative message')
+ logger.warning('Warning message')
« no previous file with comments | « third_party/WebKit/Tools/Scripts/webkitpy/common/system/logtesting.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698