Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(165163)

Side by Side Diff: Lib/distutils/tests/test_sdist.py

Issue 6516: reset owner/group to root for distutils tarballs
Patch Set: Created 5 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/distutils/tests/test_archive_util.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Tests for distutils.command.sdist.""" 1 """Tests for distutils.command.sdist."""
2 import os 2 import os
3 import tarfile 3 import tarfile
4 import unittest 4 import unittest
5 import warnings 5 import warnings
6 import zipfile 6 import zipfile
7 from os.path import join 7 from os.path import join
8 from textwrap import dedent 8 from textwrap import dedent
9 from test.support import captured_stdout, check_warnings, run_unittest 9 from test.support import captured_stdout, check_warnings, run_unittest
10 10
11 try: 11 try:
12 import zlib 12 import zlib
13 ZLIB_SUPPORT = True 13 ZLIB_SUPPORT = True
14 except ImportError: 14 except ImportError:
15 ZLIB_SUPPORT = False 15 ZLIB_SUPPORT = False
16 16
17 try:
18 import grp
19 import pwd
20 UID_GID_SUPPORT = True
21 except ImportError:
22 UID_GID_SUPPORT = False
17 23
18 from distutils.command.sdist import sdist, show_formats 24 from distutils.command.sdist import sdist, show_formats
19 from distutils.core import Distribution 25 from distutils.core import Distribution
20 from distutils.tests.test_config import PyPIRCCommandTestCase 26 from distutils.tests.test_config import PyPIRCCommandTestCase
21 from distutils.errors import DistutilsOptionError 27 from distutils.errors import DistutilsOptionError
22 from distutils.spawn import find_executable 28 from distutils.spawn import find_executable
23 from distutils.log import WARN 29 from distutils.log import WARN
24 from distutils.filelist import FileList 30 from distutils.filelist import FileList
25 from distutils.archive_util import ARCHIVE_FORMATS 31 from distutils.archive_util import ARCHIVE_FORMATS
26 32
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 self.assertEqual(manifest, ['README.manual']) 423 self.assertEqual(manifest, ['README.manual'])
418 424
419 archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz') 425 archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
420 archive = tarfile.open(archive_name) 426 archive = tarfile.open(archive_name)
421 try: 427 try:
422 filenames = [tarinfo.name for tarinfo in archive] 428 filenames = [tarinfo.name for tarinfo in archive]
423 finally: 429 finally:
424 archive.close() 430 archive.close()
425 self.assertEqual(sorted(filenames), ['fake-1.0', 'fake-1.0/PKG-INFO', 431 self.assertEqual(sorted(filenames), ['fake-1.0', 'fake-1.0/PKG-INFO',
426 'fake-1.0/README.manual']) 432 'fake-1.0/README.manual'])
433
434 @unittest.skipUnless(zlib, "requires zlib")
435 @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
436 def test_make_distribution_owner_group(self):
437
438 # check if tar and gzip are installed
439 if (find_executable('tar') is None or
440 find_executable('gzip') is None):
441 return
442
443 # now building a sdist
444 dist, cmd = self.get_cmd()
445
446 # creating a gztar and specifying the owner+group
447 cmd.formats = ['gztar']
448 cmd.owner = pwd.getpwuid(0)[0]
449 cmd.group = grp.getgrgid(0)[0]
450 cmd.ensure_finalized()
451 cmd.run()
452
453 # making sure we have the good rights
454 archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
455 archive = tarfile.open(archive_name)
456 try:
457 for member in archive.getmembers():
458 self.assertEquals(member.uid, 0)
459 self.assertEquals(member.gid, 0)
460 finally:
461 archive.close()
462
463 # building a sdist again
464 dist, cmd = self.get_cmd()
465
466 # creating a gztar
467 cmd.formats = ['gztar']
468 cmd.ensure_finalized()
469 cmd.run()
470
471 # making sure we have the good rights
472 archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
473 archive = tarfile.open(archive_name)
474 try:
475 for member in archive.getmembers():
476 self.assertEquals(member.uid, os.getuid())
477 self.assertEquals(member.gid, os.getgid())
478 finally:
479 archive.close()
427 480
428 def test_suite(): 481 def test_suite():
429 return unittest.makeSuite(SDistTestCase) 482 return unittest.makeSuite(SDistTestCase)
430 483
431 if __name__ == "__main__": 484 if __name__ == "__main__":
432 run_unittest(test_suite()) 485 run_unittest(test_suite())
OLDNEW
« no previous file with comments | « Lib/distutils/tests/test_archive_util.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+