summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-06-02 14:43:25 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-06-02 14:43:25 (GMT)
commitacf71b89ffee503874178720dfb98b1651047891 (patch)
treec110656df2c74cad80b7a86dac2dfd1a1b4970d9 /Lib
parent721ccd0ce128234a3a4fb703f056154c4b9a9e36 (diff)
parent55729fe7189ab3d21c14cc6be6896ca4f0ebad65 (diff)
downloadcpython-acf71b89ffee503874178720dfb98b1651047891.zip
cpython-acf71b89ffee503874178720dfb98b1651047891.tar.gz
cpython-acf71b89ffee503874178720dfb98b1651047891.tar.bz2
Merge packaging doc fix
Diffstat (limited to 'Lib')
-rw-r--r--Lib/packaging/command/check.py2
-rw-r--r--Lib/packaging/tests/support.py20
-rw-r--r--Lib/packaging/tests/test_command_check.py22
-rw-r--r--Lib/packaging/tests/test_manifest.py3
4 files changed, 31 insertions, 16 deletions
diff --git a/Lib/packaging/command/check.py b/Lib/packaging/command/check.py
index 94c4a97..6715db9 100644
--- a/Lib/packaging/command/check.py
+++ b/Lib/packaging/command/check.py
@@ -32,7 +32,7 @@ class check(Command):
# XXX we could use a special handler for this, but would need to test
# if it works even if the logger has a too high level
self._warnings.append((msg, args))
- return logger.warning(self.get_command_name() + msg, *args)
+ return logger.warning('%s: %s' % (self.get_command_name(), msg), *args)
def run(self):
"""Runs the command."""
diff --git a/Lib/packaging/tests/support.py b/Lib/packaging/tests/support.py
index 66b5583..ae65a1d 100644
--- a/Lib/packaging/tests/support.py
+++ b/Lib/packaging/tests/support.py
@@ -90,17 +90,23 @@ class LoggingCatcher:
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
index 8b32673..271e457 100644
--- a/Lib/packaging/tests/test_command_check.py
+++ b/Lib/packaging/tests/test_command_check.py
@@ -36,7 +36,6 @@ class CheckTestCase(support.LoggingCatcher,
# 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 @@ class CheckTestCase(support.LoggingCatcher,
self.assertRaises(PackagingSetupError, self._run,
{'name': 'xxx', 'version': 'xxx'}, **{'strict': 1})
- # and of course, no error when all metadata fields are present
+ # clear warnings from the previous calls
self.loghandler.flush()
+
+ # and of course, no error when all metadata fields are present
cmd = self._run(metadata, strict=True)
self.assertEqual([], self.get_logs(logging.WARNING))
@@ -70,7 +71,6 @@ class CheckTestCase(support.LoggingCatcher,
'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 @@ class CheckTestCase(support.LoggingCatcher,
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 @@ class CheckTestCase(support.LoggingCatcher,
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()
@@ -123,6 +124,17 @@ class CheckTestCase(support.LoggingCatcher,
cmd.check_hooks_resolvable()
self.assertEqual(len(self.get_logs(logging.WARNING)), 1)
+ def test_warn(self):
+ _, dist = self.create_dist()
+ cmd = check(dist)
+ self.assertEqual([], self.get_logs())
+ cmd.warn('hello')
+ self.assertEqual(['check: hello'], self.get_logs())
+ cmd.warn('hello %s', 'world')
+ self.assertEqual(['check: hello world'], self.get_logs())
+ cmd.warn('hello %s %s', 'beautiful', 'world')
+ self.assertEqual(['check: hello beautiful world'], self.get_logs())
+
def test_suite():
return unittest.makeSuite(CheckTestCase)
diff --git a/Lib/packaging/tests/test_manifest.py b/Lib/packaging/tests/test_manifest.py
index 9fb8b63..e0bcbbc 100644
--- a/Lib/packaging/tests/test_manifest.py
+++ b/Lib/packaging/tests/test_manifest.py
@@ -50,9 +50,6 @@ class ManifestTestCase(support.TempdirManager,
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)