[Python-checkins] distutils2: Use lazy form in logging calls, again.

tarek.ziade python-checkins at python.org
Wed Feb 16 22:23:56 CET 2011


tarek.ziade pushed 2318e50ccda4 to distutils2:

http://hg.python.org/distutils2/rev/2318e50ccda4
changeset:   1015:2318e50ccda4
user:        ?ric Araujo <merwok at netwok.org>
date:        Thu Feb 10 00:51:42 2011 +0100
summary:
  Use lazy form in logging calls, again.

Logging calls have the signature (msg, *args, **kwargs) so that the
%-formatting can be delayed until it is needed.  Logger objects also have an
isEnabledFor method that can be used to isolate expensive code.

Next steps: use only one of d2.logger methods or logging module functions;
use a proper handler in our test machinery instead of monkey-patching; remove
cmd.warn and cmd.announce and use logging instead.  TODOs have been added in
the modules and on the wiki.

files:
  distutils2/command/bdist_dumb.py
  distutils2/command/bdist_wininst.py
  distutils2/command/clean.py
  distutils2/command/cmd.py
  distutils2/command/config.py
  distutils2/command/install_dist.py
  distutils2/command/register.py
  distutils2/command/sdist.py
  distutils2/compiler/msvc9compiler.py
  distutils2/config.py
  distutils2/dist.py
  distutils2/index/simple.py
  distutils2/index/xmlrpc.py
  distutils2/install.py
  distutils2/manifest.py
  distutils2/tests/support.py
  distutils2/tests/test_command_build_py.py
  distutils2/tests/test_command_install_lib.py
  distutils2/tests/test_command_sdist.py
  distutils2/tests/test_manifest.py

diff --git a/distutils2/command/bdist_dumb.py b/distutils2/command/bdist_dumb.py
--- a/distutils2/command/bdist_dumb.py
+++ b/distutils2/command/bdist_dumb.py
@@ -87,7 +87,7 @@
         install.skip_build = self.skip_build
         install.warn_dir = 0
 
-        logger.info("installing to %s" % self.bdist_dir)
+        logger.info("installing to %s", self.bdist_dir)
         self.run_command('install_dist')
 
         # And make an archive relative to the root of the
@@ -106,11 +106,10 @@
         else:
             if (self.distribution.has_ext_modules() and
                 (install.install_base != install.install_platbase)):
-                raise DistutilsPlatformError, \
-                      ("can't make a dumb built distribution where "
-                       "base and platbase are different (%s, %s)"
-                       % (repr(install.install_base),
-                          repr(install.install_platbase)))
+                raise DistutilsPlatformError(
+                    "can't make a dumb built distribution where base and "
+                    "platbase are different (%r, %r)" %
+                    (install.install_base, install.install_platbase))
             else:
                 archive_root = os.path.join(
                     self.bdist_dir,
@@ -129,7 +128,7 @@
 
         if not self.keep_temp:
             if self.dry_run:
-                logger.info('Removing %s' % self.bdist_dir)
+                logger.info('Removing %s', self.bdist_dir)
             else:
                 rmtree(self.bdist_dir)
 
diff --git a/distutils2/command/bdist_wininst.py b/distutils2/command/bdist_wininst.py
--- a/distutils2/command/bdist_wininst.py
+++ b/distutils2/command/bdist_wininst.py
@@ -192,7 +192,7 @@
 
         if not self.keep_temp:
             if self.dry_run:
-                logger.info('Removing %s' % self.bdist_dir)
+                logger.info('Removing %s', self.bdist_dir)
             else:
                 rmtree(self.bdist_dir)
 
diff --git a/distutils2/command/clean.py b/distutils2/command/clean.py
--- a/distutils2/command/clean.py
+++ b/distutils2/command/clean.py
@@ -48,7 +48,7 @@
         # gone)
         if os.path.exists(self.build_temp):
             if self.dry_run:
-                logger.info('Removing %s' % self.build_temp)
+                logger.info('Removing %s', self.build_temp)
             else:
                 rmtree(self.build_temp)
         else:
@@ -62,7 +62,7 @@
                               self.build_scripts):
                 if os.path.exists(directory):
                     if self.dry_run:
-                        logger.info('Removing %s' % directory)
+                        logger.info('Removing %s', directory)
                     else:
                         rmtree(directory)
                 else:
diff --git a/distutils2/command/cmd.py b/distutils2/command/cmd.py
--- a/distutils2/command/cmd.py
+++ b/distutils2/command/cmd.py
@@ -182,6 +182,7 @@
         raise RuntimeError(
             "abstract method -- subclass %s must override" % self.__class__)
 
+    # TODO remove this method, just use logging
     def announce(self, msg, level=logging.INFO):
         """If the current verbosity level is of greater than or equal to
         'level' print 'msg' to stdout.
@@ -363,8 +364,9 @@
 
     # -- External world manipulation -----------------------------------
 
+    # TODO remove this method, just use logging
     def warn(self, msg):
-        logger.warning("warning: %s: %s\n" % (self.get_command_name(), msg))
+        logger.warning("warning: %s: %s\n", self.get_command_name(), msg)
 
     def execute(self, func, args, msg=None, level=1):
         util.execute(func, args, msg, dry_run=self.dry_run)
diff --git a/distutils2/command/config.py b/distutils2/command/config.py
--- a/distutils2/command/config.py
+++ b/distutils2/command/config.py
@@ -345,7 +345,7 @@
     If head is not None, will be dumped before the file content.
     """
     if head is None:
-        logger.info('%s' % filename)
+        logger.info(filename)
     else:
         logger.info(head)
     file = open(filename)
diff --git a/distutils2/command/install_dist.py b/distutils2/command/install_dist.py
--- a/distutils2/command/install_dist.py
+++ b/distutils2/command/install_dist.py
@@ -418,7 +418,7 @@
             else:
                 opt_name = opt_name.replace('-', '_')
                 val = getattr(self, opt_name)
-            logger.debug("  %s: %s" % (opt_name, val))
+            logger.debug("  %s: %s", opt_name, val)
 
     def select_scheme(self, name):
         """Set the install directories by applying the install schemes."""
diff --git a/distutils2/command/register.py b/distutils2/command/register.py
--- a/distutils2/command/register.py
+++ b/distutils2/command/register.py
@@ -92,7 +92,7 @@
         '''
         # send the info to the server and report the result
         code, result = self.post_to_server(self.build_post_data('verify'))
-        logger.info('Server response (%s): %s' % (code, result))
+        logger.info('Server response (%s): %s', code, result)
 
 
     def send_metadata(self):
@@ -206,18 +206,18 @@
                 data['email'] = raw_input('   EMail: ')
             code, result = self.post_to_server(data)
             if code != 200:
-                logger.info('Server response (%s): %s' % (code, result))
+                logger.info('Server response (%s): %s', code, result)
             else:
                 logger.info('You will receive an email shortly.')
-                logger.info(('Follow the instructions in it to '
-                             'complete registration.'))
+                logger.info('Follow the instructions in it to '
+                            'complete registration.')
         elif choice == '3':
             data = {':action': 'password_reset'}
             data['email'] = ''
             while not data['email']:
                 data['email'] = raw_input('Your email address: ')
             code, result = self.post_to_server(data)
-            logger.info('Server response (%s): %s' % (code, result))
+            logger.info('Server response (%s): %s', (code, result))
 
     def build_post_data(self, action):
         # figure the data to send - the metadata plus some additional
diff --git a/distutils2/command/sdist.py b/distutils2/command/sdist.py
--- a/distutils2/command/sdist.py
+++ b/distutils2/command/sdist.py
@@ -2,10 +2,7 @@
 
 Implements the Distutils 'sdist' command (create a source distribution)."""
 import os
-import string
 import sys
-from glob import glob
-from warnings import warn
 from shutil import rmtree
 import re
 from StringIO import StringIO
@@ -18,11 +15,10 @@
 from distutils2.command import get_command_names
 from distutils2.command.cmd import Command
 from distutils2.errors import (DistutilsPlatformError, DistutilsOptionError,
-                               DistutilsTemplateError, DistutilsModuleError,
-                               DistutilsFileError)
+                               DistutilsModuleError, DistutilsFileError)
 from distutils2.manifest import Manifest
 from distutils2 import logger
-from distutils2.util import convert_path, resolve_name
+from distutils2.util import resolve_name
 
 def show_formats():
     """Print all possible values for the 'formats' option (used by
@@ -300,7 +296,7 @@
 
         for file in files:
             if not os.path.isfile(file):
-                logger.warn("'%s' not a regular file -- skipping" % file)
+                logger.warn("'%s' not a regular file -- skipping", file)
             else:
                 dest = os.path.join(base_dir, file)
                 self.copy_file(file, dest, link=link)
@@ -336,7 +332,7 @@
 
         if not self.keep_temp:
             if self.dry_run:
-                logger.info('Removing %s' % base_dir)
+                logger.info('Removing %s', base_dir)
             else:
                 rmtree(base_dir)
 
diff --git a/distutils2/compiler/msvc9compiler.py b/distutils2/compiler/msvc9compiler.py
--- a/distutils2/compiler/msvc9compiler.py
+++ b/distutils2/compiler/msvc9compiler.py
@@ -226,10 +226,10 @@
             productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
             productdir = os.path.abspath(productdir)
             if not os.path.isdir(productdir):
-                logger.debug("%s is not a valid directory" % productdir)
+                logger.debug("%s is not a valid directory", productdir)
                 return None
         else:
-            logger.debug("Env var %s is not set or invalid" % toolskey)
+            logger.debug("Env var %s is not set or invalid", toolskey)
     if not productdir:
         logger.debug("No productdir found")
         return None
diff --git a/distutils2/config.py b/distutils2/config.py
--- a/distutils2/config.py
+++ b/distutils2/config.py
@@ -3,8 +3,8 @@
     Know how to read all config files Distutils2 uses.
 """
 import os
-import re
 import sys
+import logging
 from ConfigParser import RawConfigParser
 from shlex import split
 
@@ -90,7 +90,8 @@
         if os.path.isfile(local_file):
             files.append(local_file)
 
-        logger.debug("using config files: %s" % ', '.join(files))
+        if logger.isEnabledFor(logging.DEBUG):
+            logger.debug("using config files: %s", ', '.join(files))
         return files
 
     def _convert_metadata(self, name, value):
@@ -168,7 +169,7 @@
             files = dict([(key, _convert(key, value))
                           for key, value in content['files'].iteritems()])
             self.dist.packages = []
-            self.dist.package_dir = pkg_dir = files.get('packages_root')
+            self.dist.package_dir = files.get('packages_root')
 
             packages = files.get('packages', [])
             if isinstance(packages, str):
@@ -241,7 +242,7 @@
         parser = RawConfigParser()
 
         for filename in filenames:
-            logger.debug("  reading %s" % filename)
+            logger.debug("  reading %s", filename)
             parser.read(filename)
 
             if os.path.split(filename)[-1] == 'setup.cfg':
diff --git a/distutils2/dist.py b/distutils2/dist.py
--- a/distutils2/dist.py
+++ b/distutils2/dist.py
@@ -293,10 +293,10 @@
             opt_dict = self.command_options.get(cmd_name)
             if opt_dict is None:
                 self.announce(indent +
-                              "no option dict for '%s' command" % cmd_name)
+                              "no option dict for %r command" % cmd_name)
             else:
                 self.announce(indent +
-                              "option dict for '%s' command:" % cmd_name)
+                              "option dict for %r command:" % cmd_name)
                 out = pformat(opt_dict)
                 for line in out.split('\n'):
                     self.announce(indent + "  " + line)
@@ -401,7 +401,7 @@
         # Pull the current command from the head of the command line
         command = args[0]
         if not command_re.match(command):
-            raise SystemExit("invalid command name '%s'" % command)
+            raise SystemExit("invalid command name %r" % command)
         self.commands.append(command)
 
         # Dig up the command class that implements this command, so we
@@ -420,15 +420,15 @@
             if hasattr(cmd_class, meth):
                 continue
             raise DistutilsClassError(
-                  'command "%s" must implement "%s"' % (cmd_class, meth))
+                'command %r must implement %r' % (cmd_class, meth))
 
         # Also make sure that the command object provides a list of its
         # known options.
         if not (hasattr(cmd_class, 'user_options') and
                 isinstance(cmd_class.user_options, list)):
             raise DistutilsClassError(
-                  ("command class %s must provide "
-                   "'user_options' attribute (a list of tuples)") % cmd_class)
+                "command class %s must provide "
+                "'user_options' attribute (a list of tuples)" % cmd_class)
 
         # If the command class has a list of negative alias options,
         # merge it in with the global negative aliases.
@@ -466,7 +466,7 @@
                         func()
                     else:
                         raise DistutilsClassError(
-                            "invalid help function %r for help option '%s': "
+                            "invalid help function %r for help option %r: "
                             "must be a callable object (function, etc.)"
                             % (func, help_option))
 
@@ -537,7 +537,7 @@
                                         fix_help_options(cls.help_options))
             else:
                 parser.set_option_table(cls.user_options)
-            parser.print_help("Options for '%s' command:" % cls.__name__)
+            parser.print_help("Options for %r command:" % cls.__name__)
             print('')
 
         print(gen_usage(self.script_name))
@@ -639,7 +639,7 @@
         cmd_obj = self.command_obj.get(command)
         if not cmd_obj and create:
             logger.debug("Distribution.get_command_obj(): " \
-                         "creating '%s' command object" % command)
+                         "creating %r command object", command)
 
             cls = get_command_class(command)
             cmd_obj = self.command_obj[command] = cls(self)
@@ -669,10 +669,10 @@
         if option_dict is None:
             option_dict = self.get_option_dict(command_name)
 
-        logger.debug("  setting options for '%s' command:" % command_name)
+        logger.debug("  setting options for %r command:", command_name)
 
         for (option, (source, value)) in option_dict.iteritems():
-            logger.debug("    %s = %s (from %s)" % (option, value, source))
+            logger.debug("    %s = %s (from %s)", option, value, source)
             try:
                 bool_opts = [x.replace('-', '_')
                              for x in command_obj.boolean_options]
@@ -693,7 +693,7 @@
                     setattr(command_obj, option, value)
                 else:
                     raise DistutilsOptionError(
-                        "error in %s: command '%s' has no such option '%s'" %
+                        "error in %s: command %r has no such option %r" %
                         (source, command_name, option))
             except ValueError, msg:
                 raise DistutilsOptionError(msg)
diff --git a/distutils2/index/simple.py b/distutils2/index/simple.py
--- a/distutils2/index/simple.py
+++ b/distutils2/index/simple.py
@@ -11,7 +11,6 @@
 import sys
 import urllib2
 import urlparse
-import logging
 import os
 
 from distutils2 import logger
@@ -168,7 +167,7 @@
         if predicate.name.lower() in self._projects and not force_update:
             return self._projects.get(predicate.name.lower())
         prefer_final = self._get_prefer_final(prefer_final)
-        logger.info('Reading info on PyPI about %s' % predicate.name)
+        logger.info('Reading info on PyPI about %s', predicate.name)
         self._process_index_page(predicate.name)
 
         if predicate.name.lower() not in self._projects:
@@ -306,8 +305,8 @@
                             infos = get_infos_from_url(link, project_name,
                                         is_external=not self.index_url in url)
                         except CantParseArchiveName, e:
-                            logging.warning("version has not been parsed: %s"
-                                            % e)
+                            logger.warning(
+                                "version has not been parsed: %s", e)
                         else:
                             self._register_release(release_info=infos)
                     else:
diff --git a/distutils2/index/xmlrpc.py b/distutils2/index/xmlrpc.py
--- a/distutils2/index/xmlrpc.py
+++ b/distutils2/index/xmlrpc.py
@@ -165,7 +165,7 @@
                     p['version'], metadata={'summary': p['summary']},
                     index=self._index))
             except IrrationalVersionError, e:
-                logging.warn("Irrational version error found: %s" % e)
+                logging.warn("Irrational version error found: %s", e)
         return [self._projects[p['name'].lower()] for p in projects]
 
     def get_all_projects(self):
diff --git a/distutils2/install.py b/distutils2/install.py
--- a/distutils2/install.py
+++ b/distutils2/install.py
@@ -12,6 +12,7 @@
 import stat
 import errno
 import itertools
+import logging
 import tempfile
 
 from distutils2 import logger
@@ -134,12 +135,12 @@
 
     installed_dists, installed_files = [], []
     for dist in dists:
-        logger.info('Installing %s %s' % (dist.name, dist.version))
+        logger.info('Installing %s %s', dist.name, dist.version)
         try:
             installed_files.extend(_install_dist(dist, path))
             installed_dists.append(dist)
         except Exception, e:
-            logger.info('Failed. %s' % str(e))
+            logger.info('Failed. %s', e)
 
             # reverting
             for installed_dist in installed_dists:
@@ -258,8 +259,8 @@
         if predicate.name.lower() != installed_project.name.lower():
             continue
         found = True
-        logger.info('Found %s %s' % (installed_project.name,
-                                     installed_project.version))
+        logger.info('Found %s %s', installed_project.name,
+                    installed_project.version)
 
         # if we already have something installed, check it matches the
         # requirements
@@ -358,7 +359,7 @@
     finally:
         shutil.rmtree(tmp)
 
-    logger.info('Removing %r...' % project_name)
+    logger.info('Removing %r...', project_name)
 
     file_count = 0
     for file_ in rmfiles:
@@ -391,16 +392,16 @@
     if os.path.exists(dist.path):
         shutil.rmtree(dist.path)
 
-    logger.info('Success ! Removed %d files and %d dirs' % \
-            (file_count, dir_count))
+    logger.info('Success! Removed %d files and %d dirs',
+                file_count, dir_count)
 
 
 def install(project):
-    logger.info('Getting information about "%s".' % project)
+    logger.info('Getting information about "%s".', project)
     try:
         info = get_infos(project)
     except InstallationException:
-        logger.info('Cound not find "%s".' % project)
+        logger.info('Cound not find "%s".', project)
         return
 
     if info['install'] == []:
@@ -413,8 +414,9 @@
                            info['install'], info['remove'], info['conflict'])
 
     except InstallationConflict, e:
-        projects = ['%s %s' % (p.name, p.version) for p in e.args[0]]
-        logger.info('"%s" conflicts with "%s"' % (project, ','.join(projects)))
+        if logger.isEnabledFor(logging.INFO):
+            projects = ['%s %s' % (p.name, p.version) for p in e.args[0]]
+            logger.info('%r conflicts with %s', project, ','.join(projects))
 
 
 def _main(**attrs):
diff --git a/distutils2/manifest.py b/distutils2/manifest.py
--- a/distutils2/manifest.py
+++ b/distutils2/manifest.py
@@ -95,7 +95,7 @@
             try:
                 self._process_template_line(line)
             except DistutilsTemplateError, msg:
-                logging.warning("%s, %s" % (path_or_file, msg))
+                logging.warning("%s, %s", path_or_file, msg)
 
     def write(self, path):
         """Write the file list in 'self.filelist' (presumably as filled in
@@ -111,14 +111,14 @@
 
             if first_line != '# file GENERATED by distutils, do NOT edit\n':
                 logging.info("not writing to manually maintained "
-                             "manifest file '%s'", path)
+                             "manifest file %r", path)
                 return
 
         self.sort()
         self.remove_duplicates()
         content = self.files[:]
         content.insert(0, '# file GENERATED by distutils, do NOT edit')
-        logging.info("writing manifest file '%s'", path)
+        logging.info("writing manifest file %r", path)
         write_file(path, content)
 
     def read(self, path):
@@ -126,7 +126,7 @@
         fill in 'self.filelist', the list of files to include in the source
         distribution.
         """
-        logging.info("reading manifest file '%s'" % path)
+        logging.info("reading manifest file %r", path)
         manifest = open(path)
         try:
             for line in manifest.readlines():
@@ -168,14 +168,14 @@
                       'global-include', 'global-exclude'):
             if len(words) < 2:
                 raise DistutilsTemplateError(
-                      "'%s' expects <pattern1> <pattern2> ..." % action)
+                      "%r expects <pattern1> <pattern2> ..." % action)
 
             patterns = map(convert_path, words[1:])
 
         elif action in ('recursive-include', 'recursive-exclude'):
             if len(words) < 3:
                 raise DistutilsTemplateError(
-                      "'%s' expects <dir> <pattern1> <pattern2> ..." % action)
+                      "%r expects <dir> <pattern1> <pattern2> ..." % action)
 
             dir = convert_path(words[1])
             patterns = map(convert_path, words[2:])
@@ -183,12 +183,12 @@
         elif action in ('graft', 'prune'):
             if len(words) != 2:
                 raise DistutilsTemplateError(
-                     "'%s' expects a single <dir_pattern>" % action)
+                     "%r expects a single <dir_pattern>" % action)
 
             dir_pattern = convert_path(words[1])
 
         else:
-            raise DistutilsTemplateError("unknown action '%s'" % action)
+            raise DistutilsTemplateError("unknown action %r" % action)
 
         return action, patterns, dir, dir_pattern
 
@@ -206,53 +206,53 @@
         if action == 'include':
             for pattern in patterns:
                 if not self._include_pattern(pattern, anchor=1):
-                    logging.warning("warning: no files found matching '%s'" %
-                             pattern)
+                    logging.warning("warning: no files found matching %r",
+                                    pattern)
 
         elif action == 'exclude':
             for pattern in patterns:
                 if not self.exclude_pattern(pattern, anchor=1):
-                    logging.warning(("warning: no previously-included files "
-                              "found matching '%s'") % pattern)
+                    logging.warning("warning: no previously-included files "
+                                    "found matching %r", pattern)
 
         elif action == 'global-include':
             for pattern in patterns:
                 if not self._include_pattern(pattern, anchor=0):
-                    logging.warning(("warning: no files found matching '%s' " +
-                              "anywhere in distribution") % pattern)
+                    logging.warning("warning: no files found matching %r "
+                                    "anywhere in distribution", pattern)
 
         elif action == 'global-exclude':
             for pattern in patterns:
                 if not self.exclude_pattern(pattern, anchor=0):
-                    logging.warning(("warning: no previously-included files "
-                              "matching '%s' found anywhere in distribution") %
-                             pattern)
+                    logging.warning("warning: no previously-included files "
+                                    "matching %r found anywhere in "
+                                    "distribution", pattern)
 
         elif action == 'recursive-include':
             for pattern in patterns:
                 if not self._include_pattern(pattern, prefix=dir):
-                    logging.warning(("warning: no files found matching '%s' "
-                                "under directory '%s'" % (pattern, dir)))
+                    logging.warning("warning: no files found matching %r "
+                                    "under directory %r", pattern, dir)
 
         elif action == 'recursive-exclude':
             for pattern in patterns:
                 if not self.exclude_pattern(pattern, prefix=dir):
-                    logging.warning(("warning: no previously-included files "
-                              "matching '%s' found under directory '%s'") %
-                             (pattern, dir))
+                    logging.warning("warning: no previously-included files "
+                                    "matching %r found under directory %r",
+                                    pattern, dir)
 
         elif action == 'graft':
             if not self._include_pattern(None, prefix=dir_pattern):
-                logging.warning("warning: no directories found matching '%s'" %
-                         dir_pattern)
+                logging.warning("warning: no directories found matching %r",
+                                dir_pattern)
 
         elif action == 'prune':
             if not self.exclude_pattern(None, prefix=dir_pattern):
-                logging.warning(("no previously-included directories found " +
-                          "matching '%s'") % dir_pattern)
+                logging.warning("no previously-included directories found "
+                                "matching %r", dir_pattern)
         else:
             raise DistutilsInternalError(
-                  "this cannot happen: invalid action '%s'" % action)
+                  "this cannot happen: invalid action %r" % action)
 
     def _include_pattern(self, pattern, anchor=1, prefix=None, is_regex=0):
         """Select strings (presumably filenames) from 'self.files' that
diff --git a/distutils2/tests/support.py b/distutils2/tests/support.py
--- a/distutils2/tests/support.py
+++ b/distutils2/tests/support.py
@@ -51,6 +51,9 @@
 
     def setUp(self):
         super(LoggingCatcher, self).setUp()
+        # TODO read the new logging docs and/or the python-dev posts about
+        # logging and tests to properly use a handler instead of
+        # monkey-patching
         self.old_log = logger._log
         logger._log = self._log
         logger.setLevel(logging.INFO)
diff --git a/distutils2/tests/test_command_build_py.py b/distutils2/tests/test_command_build_py.py
--- a/distutils2/tests/test_command_build_py.py
+++ b/distutils2/tests/test_command_build_py.py
@@ -116,7 +116,7 @@
         finally:
             sys.dont_write_bytecode = old_dont_write_bytecode
 
-        self.assertTrue('byte-compiling is disabled' in self.logs[0][1])
+        self.assertIn('byte-compiling is disabled', self.logs[0][2][1])
 
 def test_suite():
     return unittest.makeSuite(BuildPyTestCase)
diff --git a/distutils2/tests/test_command_install_lib.py b/distutils2/tests/test_command_install_lib.py
--- a/distutils2/tests/test_command_install_lib.py
+++ b/distutils2/tests/test_command_install_lib.py
@@ -97,7 +97,7 @@
         finally:
             sys.dont_write_bytecode = old_dont_write_bytecode
 
-        self.assertTrue('byte-compiling is disabled' in self.logs[0][1])
+        self.assertIn('byte-compiling is disabled', self.logs[0][2][1])
 
 def test_suite():
     return unittest.makeSuite(InstallLibTestCase)
diff --git a/distutils2/tests/test_command_sdist.py b/distutils2/tests/test_command_sdist.py
--- a/distutils2/tests/test_command_sdist.py
+++ b/distutils2/tests/test_command_sdist.py
@@ -95,9 +95,6 @@
         dist.include_package_data = True
         cmd = sdist(dist)
         cmd.dist_dir = 'dist'
-        def _warn(*args):
-            pass
-        cmd.warn = _warn
         return dist, cmd
 
     @unittest.skipUnless(zlib, "requires zlib")
@@ -251,7 +248,7 @@
         cmd.ensure_finalized()
         cmd.run()
         warnings = self.get_logs(logging.WARN)
-        self.assertEqual(len(warnings), 1)
+        self.assertEqual(len(warnings), 2)
 
         # trying with a complete set of metadata
         self.clear_logs()
@@ -263,7 +260,8 @@
         # removing manifest generated warnings
         warnings = [warn for warn in warnings if
                     not warn.endswith('-- skipping')]
-        self.assertEqual(len(warnings), 0)
+        # the remaining warning is about the use of the default file list
+        self.assertEqual(len(warnings), 1)
 
 
     def test_show_formats(self):
diff --git a/distutils2/tests/test_manifest.py b/distutils2/tests/test_manifest.py
--- a/distutils2/tests/test_manifest.py
+++ b/distutils2/tests/test_manifest.py
@@ -1,6 +1,5 @@
 """Tests for distutils.manifest."""
 import os
-import sys
 import logging
 from StringIO import StringIO
 
@@ -25,10 +24,11 @@
 
 
 class ManifestTestCase(support.TempdirManager,
+                       # enable this after LoggingCatcher is fixed
+                       #support.LoggingCatcher,
                        unittest.TestCase):
 
     def test_manifest_reader(self):
-
         tmpdir = self.mkdtemp()
         MANIFEST = os.path.join(tmpdir, 'MANIFEST.in')
         f = open(MANIFEST, 'w')
@@ -38,9 +38,10 @@
             f.close()
         manifest = Manifest()
 
+        # remove this when LoggingCatcher is fixed
         warns = []
-        def _warn(msg):
-            warns.append(msg)
+        def _warn(*args):
+            warns.append(args[0])
 
         old_warn = logging.warning
         logging.warning = _warn

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list