[Python-checkins] cpython: Minor tweaks in packaging’s test_dist.

eric.araujo python-checkins at python.org
Fri Jun 17 19:41:37 CEST 2011


http://hg.python.org/cpython/rev/322ba22aa3c0
changeset:   70849:322ba22aa3c0
user:        Éric Araujo <merwok at netwok.org>
date:        Fri Jun 17 13:24:33 2011 +0200
summary:
  Minor tweaks in packaging’s test_dist.

- Use different Metadata objects to write and read a PKG-INFO (METADATA)
  file, to make sure the tested values come from the file

- No need to restore methods on an instance after monkey-patching them:
  the methods are still the same on the class

- Harmonize dedent calls

files:
  Lib/packaging/tests/test_dist.py |  36 ++++++++-----------
  1 files changed, 15 insertions(+), 21 deletions(-)


diff --git a/Lib/packaging/tests/test_dist.py b/Lib/packaging/tests/test_dist.py
--- a/Lib/packaging/tests/test_dist.py
+++ b/Lib/packaging/tests/test_dist.py
@@ -10,6 +10,7 @@
 from packaging.dist import Distribution
 from packaging.command import set_command
 from packaging.command.cmd import Command
+from packaging.metadata import Metadata
 from packaging.errors import PackagingModuleError, PackagingOptionError
 from packaging.tests import TESTFN, captured_stdout
 from packaging.tests import support, unittest
@@ -203,21 +204,21 @@
         config_file = os.path.join(temp_home, "config1.cfg")
         hooks_module = os.path.join(temp_home, pyname)
 
-        self.write_file(config_file, textwrap.dedent('''
+        self.write_file(config_file, textwrap.dedent('''\
             [test_dist]
             pre-hook.test = %(modname)s.log_pre_call
             post-hook.test = %(modname)s.log_post_call'''
             % {'modname': module_name}))
 
-        self.write_file(hooks_module, textwrap.dedent('''
-        record = []
+        self.write_file(hooks_module, textwrap.dedent('''\
+            record = []
 
-        def log_pre_call(cmd):
-            record.append('pre-%s' % cmd.get_command_name())
+            def log_pre_call(cmd):
+                record.append('pre-%s' % cmd.get_command_name())
 
-        def log_post_call(cmd):
-            record.append('post-%s' % cmd.get_command_name())
-        '''))
+            def log_post_call(cmd):
+                record.append('post-%s' % cmd.get_command_name())
+            '''))
 
         set_command('packaging.tests.test_dist.test_dist')
         d = create_distribution([config_file])
@@ -229,15 +230,9 @@
         self.addCleanup(unload, module_name)
         record = __import__(module_name).record
 
-        old_run = cmd.run
-        old_finalize = cmd.finalize_options
         cmd.run = lambda: record.append('run')
         cmd.finalize_options = lambda: record.append('finalize')
-        try:
-            d.run_command('test_dist')
-        finally:
-            cmd.run = old_run
-            cmd.finalize_options = old_finalize
+        d.run_command('test_dist')
 
         self.assertEqual(record, ['finalize',
                                   'pre-test_dist',
@@ -248,7 +243,7 @@
         temp_home = self.mkdtemp()
         config_file = os.path.join(temp_home, "config1.cfg")
 
-        self.write_file(config_file, textwrap.dedent('''
+        self.write_file(config_file, textwrap.dedent('''\
             [test_dist]
             pre-hook.test = nonexistent.dotted.name'''))
 
@@ -263,7 +258,7 @@
         temp_home = self.mkdtemp()
         config_file = os.path.join(temp_home, "config1.cfg")
 
-        self.write_file(config_file, textwrap.dedent('''
+        self.write_file(config_file, textwrap.dedent('''\
             [test_dist]
             pre-hook.test = packaging.tests.test_dist.__doc__'''))
 
@@ -429,14 +424,13 @@
                  "requires_dist": ['foo']}
 
         dist = Distribution(attrs)
-        metadata = dist.metadata
-
-        # write it then reloads it
         PKG_INFO = io.StringIO()
-        metadata.write_file(PKG_INFO)
+        dist.metadata.write_file(PKG_INFO)
         PKG_INFO.seek(0)
 
+        metadata = Metadata()
         metadata.read_file(PKG_INFO)
+
         self.assertEqual(metadata['name'], "package")
         self.assertEqual(metadata['version'], "1.0")
         self.assertEqual(metadata['summary'], "xxx")

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


More information about the Python-checkins mailing list