summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-08-20 07:31:25 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-08-20 07:31:25 (GMT)
commit0a733627f968e7a886fea64cb3c5bddc32eb55ea (patch)
tree2d6624dd311879ddabfac15cf282d24f5863e21e /Lib
parentba9b2689be0746c36171311dadcb64464ce6baae (diff)
downloadcpython-0a733627f968e7a886fea64cb3c5bddc32eb55ea.zip
cpython-0a733627f968e7a886fea64cb3c5bddc32eb55ea.tar.gz
cpython-0a733627f968e7a886fea64cb3c5bddc32eb55ea.tar.bz2
Add a simple test for the packaging RECORD file.
The existing test_record is not easily extendable to add script files or extension modules: it collects all files from fake_dists and generates a RECORD file at runtime. I felt more comfortable adding a new test written from scratch more self-contained (just one project with well-defined files) and more stupid (the checksums and sizes are computed once and hard-coded).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/packaging/tests/test_command_install_distinfo.py54
1 files changed, 53 insertions, 1 deletions
diff --git a/Lib/packaging/tests/test_command_install_distinfo.py b/Lib/packaging/tests/test_command_install_distinfo.py
index 9853700..994cdd8 100644
--- a/Lib/packaging/tests/test_command_install_distinfo.py
+++ b/Lib/packaging/tests/test_command_install_distinfo.py
@@ -3,10 +3,11 @@
import os
import csv
import hashlib
-import sys
+import sysconfig
from packaging.command.install_distinfo import install_distinfo
from packaging.command.cmd import Command
+from packaging.compiler.extension import Extension
from packaging.metadata import Metadata
from packaging.tests import unittest, support
@@ -121,6 +122,57 @@ class InstallDistinfoTestCase(support.TempdirManager,
self.checkLists(os.listdir(dist_info),
['METADATA', 'REQUESTED', 'INSTALLER'])
+ def test_record_basic(self):
+ install_dir = self.mkdtemp()
+ modules_dest = os.path.join(install_dir, 'lib')
+ scripts_dest = os.path.join(install_dir, 'bin')
+ project_dir, dist = self.create_dist(
+ name='Spamlib', version='0.1',
+ py_modules=['spam'], scripts=['spamd'],
+ ext_modules=[Extension('_speedspam', ['_speedspam.c'])])
+
+ # using a real install_dist command is too painful, so we use a mock
+ # class that's only a holder for options to be used by install_distinfo
+ # and we create placeholder files manually instead of using build_*.
+ # the install_* commands will still be consulted by install_distinfo.
+ os.chdir(project_dir)
+ self.write_file('spam', '# Python module')
+ self.write_file('spamd', '# Python script')
+ extmod = '_speedspam%s' % sysconfig.get_config_var('SO')
+ self.write_file(extmod, '')
+
+ install = DummyInstallCmd(dist)
+ install.outputs = ['spam', 'spamd', extmod]
+ install.install_lib = modules_dest
+ install.install_scripts = scripts_dest
+ dist.command_obj['install_dist'] = install
+
+ cmd = install_distinfo(dist)
+ cmd.ensure_finalized()
+ dist.command_obj['install_distinfo'] = cmd
+ cmd.run()
+
+ record = os.path.join(modules_dest, 'Spamlib-0.1.dist-info', 'RECORD')
+ with open(record, encoding='utf-8') as fp:
+ content = fp.read()
+
+ found = []
+ for line in content.splitlines():
+ filename, checksum, size = line.split(',')
+ filename = os.path.basename(filename)
+ found.append((filename, checksum, size))
+
+ expected = [
+ ('spam', '6ab2f288ef2545868effe68757448b45', '15'),
+ ('spamd','d13e6156ce78919a981e424b2fdcd974', '15'),
+ (extmod, 'd41d8cd98f00b204e9800998ecf8427e', '0'),
+ ('METADATA', '846de67e49c3b92c81fb1ebd7bc07046', '172'),
+ ('INSTALLER', '44e3fde05f3f537ed85831969acf396d', '9'),
+ ('REQUESTED', 'd41d8cd98f00b204e9800998ecf8427e', '0'),
+ ('RECORD', '', ''),
+ ]
+ self.assertEqual(found, expected)
+
def test_record(self):
pkg_dir, dist = self.create_dist(name='foo',
version='1.0')