[Python-checkins] distutils2: Fix writing of the RESOURCES file (#12386).
eric.araujo
python-checkins at python.org
Mon Nov 14 15:24:07 CET 2011
http://hg.python.org/distutils2/rev/cb49bc384957
changeset: 1228:cb49bc384957
user: Éric Araujo <merwok at netwok.org>
date: Fri Nov 11 11:41:17 2011 +0100
summary:
Fix writing of the RESOURCES file (#12386).
This was not broken in d2 because codecs.open allows 'b' in mode.
files:
distutils2/command/install_distinfo.py | 2 +-
distutils2/tests/test_command_install_data.py | 70 +++++++++-
distutils2/tests/test_command_install_distinfo.py | 5 +-
3 files changed, 72 insertions(+), 5 deletions(-)
diff --git a/distutils2/command/install_distinfo.py b/distutils2/command/install_distinfo.py
--- a/distutils2/command/install_distinfo.py
+++ b/distutils2/command/install_distinfo.py
@@ -111,7 +111,7 @@
'RESOURCES')
logger.info('creating %s', resources_path)
if not self.dry_run:
- f = open(resources_path, 'wb')
+ f = open(resources_path, 'w')
try:
writer = csv.writer(f, delimiter=',',
lineterminator='\n',
diff --git a/distutils2/tests/test_command_install_data.py b/distutils2/tests/test_command_install_data.py
--- a/distutils2/tests/test_command_install_data.py
+++ b/distutils2/tests/test_command_install_data.py
@@ -1,28 +1,37 @@
"""Tests for distutils2.command.install_data."""
import os
+import sys
+import distutils2.database
from distutils2._backport import sysconfig
from distutils2._backport.sysconfig import _get_default_scheme
from distutils2.tests import unittest, support
from distutils2.command.install_data import install_data
+from distutils2.command.install_dist import install_dist
+from distutils2.command.install_distinfo import install_distinfo
class InstallDataTestCase(support.TempdirManager,
support.LoggingCatcher,
unittest.TestCase):
- def test_simple_run(self):
+ def setUp(self):
+ super(InstallDataTestCase, self).setUp()
scheme = _get_default_scheme()
old_items = sysconfig._SCHEMES.items(scheme)
+
def restore():
sysconfig._SCHEMES.remove_section(scheme)
sysconfig._SCHEMES.add_section(scheme)
for option, value in old_items:
sysconfig._SCHEMES.set(scheme, option, value)
+
self.addCleanup(restore)
+ def test_simple_run(self):
pkg_dir, dist = self.create_dist()
cmd = install_data(dist)
cmd.install_dir = inst = os.path.join(pkg_dir, 'inst')
+ scheme = _get_default_scheme()
sysconfig._SCHEMES.set(scheme, 'inst',
os.path.join(pkg_dir, 'inst'))
@@ -67,8 +76,7 @@
three = os.path.join(cmd.install_dir, 'three')
self.write_file(three, 'xx')
- sysconfig._SCHEMES.set(scheme, 'inst3',
- cmd.install_dir)
+ sysconfig._SCHEMES.set(scheme, 'inst3', cmd.install_dir)
cmd.data_files = {one: '{inst}/one', two: '{inst2}/two',
three: '{inst3}/three'}
@@ -80,6 +88,62 @@
self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
self.assertTrue(os.path.exists(os.path.join(inst, rone)))
+ def test_resources(self):
+ install_dir = self.mkdtemp()
+ scripts_dir = self.mkdtemp()
+ project_dir, dist = self.create_dist(
+ name='Spamlib', version='0.1',
+ data_files={'spamd': '{scripts}/spamd'})
+
+ os.chdir(project_dir)
+ self.write_file('spamd', '# Python script')
+ sysconfig._SCHEMES.set(_get_default_scheme(), 'scripts', scripts_dir)
+ sys.path.insert(0, install_dir)
+ distutils2.database.disable_cache()
+ self.addCleanup(sys.path.remove, install_dir)
+ self.addCleanup(distutils2.database.enable_cache)
+
+ cmd = install_dist(dist)
+ cmd.outputs = ['spamd']
+ cmd.install_lib = install_dir
+ dist.command_obj['install_dist'] = cmd
+
+ cmd = install_data(dist)
+ cmd.install_dir = install_dir
+ cmd.ensure_finalized()
+ dist.command_obj['install_data'] = cmd
+ cmd.run()
+
+ cmd = install_distinfo(dist)
+ cmd.ensure_finalized()
+ dist.command_obj['install_distinfo'] = cmd
+ cmd.run()
+
+ # first a few sanity checks
+ self.assertEqual(os.listdir(scripts_dir), ['spamd'])
+ self.assertEqual(os.listdir(install_dir), ['Spamlib-0.1.dist-info'])
+
+ # now the real test
+ fn = os.path.join(install_dir, 'Spamlib-0.1.dist-info', 'RESOURCES')
+ fp = open(fn)
+ try:
+ content = fp.read().strip()
+ finally:
+ fp.close()
+
+ expected = 'spamd,%s' % os.path.join(scripts_dir, 'spamd')
+ self.assertEqual(content, expected)
+
+ # just to be sure, we also test that get_file works here, even though
+ # packaging.database has its own test file
+ fp = distutils2.database.get_file('Spamlib', 'spamd')
+ try:
+ content = fp.read()
+ finally:
+ fp.close()
+
+ self.assertEqual('# Python script', content)
+
def test_suite():
return unittest.makeSuite(InstallDataTestCase)
diff --git a/distutils2/tests/test_command_install_distinfo.py b/distutils2/tests/test_command_install_distinfo.py
--- a/distutils2/tests/test_command_install_distinfo.py
+++ b/distutils2/tests/test_command_install_distinfo.py
@@ -1,4 +1,7 @@
-"""Tests for ``distutils2.command.install_distinfo``. """
+"""Tests for ``distutils2.command.install_distinfo``.
+
+Writing of the RESOURCES file is tested in test_command_install_data.
+"""
import os
import csv
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list