[Python-checkins] cpython: Make packaging.tests.support.LoggingCatcher.get_logs flush the log handler.

eric.araujo python-checkins at python.org
Thu Jun 2 16:43:47 CEST 2011


http://hg.python.org/cpython/rev/c25c403e54cb
changeset: 70604:c25c403e54cb
parent: 70595:22f077f82e74
user: Éric Araujo <merwok at netwok.org>
date: Thu Jun 02 14:53:59 2011 +0200
summary:
 Make packaging.tests.support.LoggingCatcher.get_logs flush the log handler.
This removes the need to call flush manually in each test, except when
testing code that creates warning without checking them.
files:
 Lib/packaging/tests/support.py | 20 +++++++---
 Lib/packaging/tests/test_command_check.py | 11 +++--
 Lib/packaging/tests/test_manifest.py | 3 -
 3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/Lib/packaging/tests/support.py b/Lib/packaging/tests/support.py
--- a/Lib/packaging/tests/support.py
+++ b/Lib/packaging/tests/support.py
@@ -90,17 +90,23 @@
 def get_logs(self, *levels):
 """Return all log messages with level in *levels*.
 
- Without explicit levels given, returns all messages.
- *levels* defaults to all levels. For log calls with arguments (i.e.
- logger.info('bla bla %s', arg)), the messages
- Returns a list.
+ Without explicit levels given, returns all messages. *levels* defaults
+ to all levels. For log calls with arguments (i.e.
+ logger.info('bla bla %r', arg)), the messages will be formatted before
+ being returned (e.g. "bla bla 'thing'").
+
+ Returns a list. Automatically flushes the loghandler after being
+ called.
 
 Example: self.get_logs(logging.WARN, logging.DEBUG).
 """
 if not levels:
- return [log.getMessage() for log in self.loghandler.buffer]
- return [log.getMessage() for log in self.loghandler.buffer
- if log.levelno in levels]
+ messages = [log.getMessage() for log in self.loghandler.buffer]
+ else:
+ messages = [log.getMessage() for log in self.loghandler.buffer
+ if log.levelno in levels]
+ self.loghandler.flush()
+ return messages
 
 
 class TempdirManager:
diff --git a/Lib/packaging/tests/test_command_check.py b/Lib/packaging/tests/test_command_check.py
--- a/Lib/packaging/tests/test_command_check.py
+++ b/Lib/packaging/tests/test_command_check.py
@@ -36,7 +36,6 @@
 # now let's add the required fields
 # and run it again, to make sure we don't get
 # any warning anymore
- self.loghandler.flush()
 metadata = {'home_page': 'xxx', 'author': 'xxx',
 'author_email': 'xxx',
 'name': 'xxx', 'version': '4.2',
@@ -50,8 +49,10 @@
 self.assertRaises(PackagingSetupError, self._run,
 {'name': 'xxx', 'version': 'xxx'}, **{'strict': 1})
 
+ # clear warnings from the previous calls
+ self.loghandler.flush()
+
 # and of course, no error when all metadata fields are present
- self.loghandler.flush()
 cmd = self._run(metadata, strict=True)
 self.assertEqual([], self.get_logs(logging.WARNING))
 
@@ -70,7 +71,6 @@
 'name': 'xxx', 'version': '4.2',
 'requires_python': '2.4',
 }
- self.loghandler.flush()
 cmd = self._run(metadata)
 self.assertEqual([], self.get_logs(logging.WARNING))
 
@@ -85,9 +85,11 @@
 self.assertRaises(PackagingSetupError, self._run, metadata,
 **{'strict': 1})
 
+ # clear warnings from the previous calls
+ self.loghandler.flush()
+
 # now with correct version format again
 metadata['version'] = '4.2'
- self.loghandler.flush()
 cmd = self._run(metadata, strict=True)
 self.assertEqual([], self.get_logs(logging.WARNING))
 
@@ -100,7 +102,6 @@
 cmd.check_restructuredtext()
 self.assertEqual(len(self.get_logs(logging.WARNING)), 1)
 
- self.loghandler.flush()
 pkg_info, dist = self.create_dist(description='title\n=====\n\ntest')
 cmd = check(dist)
 cmd.check_restructuredtext()
diff --git a/Lib/packaging/tests/test_manifest.py b/Lib/packaging/tests/test_manifest.py
--- a/Lib/packaging/tests/test_manifest.py
+++ b/Lib/packaging/tests/test_manifest.py
@@ -50,9 +50,6 @@
 for warning in warnings:
 self.assertIn('no files found matching', warning)
 
- # reset logs for the next assert
- self.loghandler.flush()
-
 # manifest also accepts file-like objects
 with open(MANIFEST) as f:
 manifest.read_template(f)
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /