diff --git a/Lib/packaging/tests/test_command_install_distinfo.py b/Lib/packaging/tests/test_command_install_distinfo.py --- a/Lib/packaging/tests/test_command_install_distinfo.py +++ b/Lib/packaging/tests/test_command_install_distinfo.py @@ -2,8 +2,9 @@ import os import csv +import sys import hashlib -import sys +import textwrap from packaging.command.install_distinfo import install_distinfo from packaging.command.cmd import Command @@ -32,6 +33,7 @@ class InstallDistinfoTestCase(support.Te support.LoggingCatcher, unittest.TestCase): + maxDiff = None checkLists = lambda self, x, y: self.assertListEqual(sorted(x), sorted(y)) def test_empty_install(self): @@ -183,6 +185,60 @@ class InstallDistinfoTestCase(support.Te self.maxDiff = None self.checkLists(parsed, expected) + def test_record_scripts(self): + # see bug #10191 + module = textwrap.dedent("""\ + __version__ = '2.1' + """) + + script = textwrap.dedent("""\ + #!/usr/bin/python + + print('Hello!') + """) + + tmpdir, dist = self.create_dist( + name='Hello3', version='2.1', + py_modules=['hellolib'], scripts=['hello']) + + project_dir = os.path.join(tmpdir, 'Hello3') + home_dir = self.mkdtemp() + os.mkdir(project_dir) + os.chdir(project_dir) + self.write_file('hellolib.py', module) + self.write_file('hello', script) + + cmd = dist.get_command_obj('install_dist') + cmd.home = home_dir + cmd.install_scripts = 'script' + cmd.verbose = 1 + cmd.ensure_finalized() + cmd.run() + + expected = [ + # we don't test the full contents of RECORD, just filenames + 'lib/python/hellolib.py', + 'lib/python/hellolib.pyc', + 'script/hello', + 'lib/python/Hello3-2.1.dist-info/METADATA', + 'lib/python/Hello3-2.1.dist-info/INSTALLER', + 'lib/python/Hello3-2.1.dist-info/REQUESTED', + 'lib/python/Hello3-2.1.dist-info/RECORD', + ] + + record = os.path.join(home_dir, 'lib', 'python', + 'Hello3-2.1.dist-info', 'RECORD') + + contents = [] + with open(record) as fp: + for line in fp: + filename, checksum, length = line.split(',') + if filename.startswith(home_dir): + filename = filename[len(home_dir)+1:] + contents.append(filename) + + self.assertEqual(contents, expected) + def test_suite(): return unittest.makeSuite(InstallDistinfoTestCase)