diff options
author | Guido van Rossum <guido@python.org> | 2013-01-25 09:43:41 -0800 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2013-01-25 09:43:41 -0800 |
commit | 52d3ebbea1a7652891b1e8022e02a6f32053b9cb (patch) | |
tree | 98bc3c83d8ec6a7a244347e344c6080eae5a4604 | |
parent | ad7e6bb443a9c9329b0ca38055aac19256dadc0b (diff) | |
download | trollius-git-52d3ebbea1a7652891b1e8022e02a6f32053b9cb.tar.gz |
Logging tweaks for tests.
-rw-r--r-- | runtests.py | 12 | ||||
-rw-r--r-- | tulip/subprocess_test.py | 3 | ||||
-rw-r--r-- | tulip/tasks_test.py | 7 | ||||
-rw-r--r-- | tulip/test_utils.py | 21 |
4 files changed, 41 insertions, 2 deletions
diff --git a/runtests.py b/runtests.py index e2598c9..d7de974 100644 --- a/runtests.py +++ b/runtests.py @@ -15,6 +15,7 @@ e.g. 'tulip.events_test.PolicyTests.testPolicy'. # Originally written by Beech Horn (for NDB). +import logging import os import re import sys @@ -68,6 +69,17 @@ def main(): elif arg and not arg.startswith('-'): patterns.append(arg) tests = load_tests(includes, excludes) + logger = logging.getLogger() + if v == 0: + logger.setLevel(logging.CRITICAL) + elif v == 1: + logger.setLevel(logging.ERROR) + elif v == 2: + logger.setLevel(logging.WARNING) + elif v == 3: + logger.setLevel(logging.INFO) + elif v >= 4: + logger.setLevel(logging.DEBUG) result = unittest.TextTestRunner(verbosity=v).run(tests) sys.exit(not result.wasSuccessful()) diff --git a/tulip/subprocess_test.py b/tulip/subprocess_test.py index 4eb24e4..b4bcc26 100644 --- a/tulip/subprocess_test.py +++ b/tulip/subprocess_test.py @@ -1,5 +1,6 @@ """Tests for subprocess_transport.py.""" +import logging import unittest from . import events @@ -17,7 +18,7 @@ class MyProto(protocols.Protocol): self.state = 'CONNECTED' transport.write_eof() def data_received(self, data): - print('received:', data) + logging.info('received: %r', data) assert self.state == 'CONNECTED', self.state self.nbytes += len(data) def eof_received(self): diff --git a/tulip/tasks_test.py b/tulip/tasks_test.py index a738145..456cccf 100644 --- a/tulip/tasks_test.py +++ b/tulip/tasks_test.py @@ -6,6 +6,7 @@ import unittest from . import events from . import futures from . import tasks +from . import test_utils class Dummy: @@ -15,14 +16,16 @@ class Dummy: pass -class TaskTests(unittest.TestCase): +class TaskTests(test_utils.LogTrackingTestCase): def setUp(self): + super().setUp() self.event_loop = events.new_event_loop() events.set_event_loop(self.event_loop) def tearDown(self): self.event_loop.close() + super().tearDown() def testTaskClass(self): @tasks.coroutine @@ -100,6 +103,7 @@ class TaskTests(unittest.TestCase): # TODO: Test different return_when values. def testWaitWithException(self): + self.suppress_log_errors() a = tasks.sleep(0.1) @tasks.coroutine def sleeper(): @@ -164,6 +168,7 @@ class TaskTests(unittest.TestCase): self.assertTrue(t1-t0 <= 0.01) def testAsCompletedWithTimeout(self): + self.suppress_log_errors() a = tasks.sleep(0.1, 'a') b = tasks.sleep(0.15, 'b') @tasks.coroutine diff --git a/tulip/test_utils.py b/tulip/test_utils.py new file mode 100644 index 0000000..2d9e64b --- /dev/null +++ b/tulip/test_utils.py @@ -0,0 +1,21 @@ +"""Utilities shared by tests.""" + +import logging +import unittest + +class LogTrackingTestCase(unittest.TestCase): + + def setUp(self): + self._logger = logging.getLogger() + self._log_level = self._logger.getEffectiveLevel() + + def tearDown(self): + self._logger.setLevel(self._log_level) + + def suppress_log_errors(self): + if self._log_level >= logging.WARNING: + self._logger.setLevel(logging.CRITICAL) + + def suppress_log_warnings(self): + if self._log_level >= logging.WARNING: + self._logger.setLevel(logging.ERROR) |