Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 1 | """Tests for distutils.command.bdist_rpm.""" |
| 2 | |
| 3 | import unittest |
| 4 | import sys |
| 5 | import os |
| 6 | import tempfile |
| 7 | import shutil |
| 8 | |
Georg Brandl | 28aeb0d | 2010-02-06 23:53:52 +0000 | [diff] [blame] | 9 | from test.test_support import run_unittest |
| 10 | |
Serhiy Storchaka | 59addd6 | 2016-10-23 22:54:43 +0300 | [diff] [blame] | 11 | try: |
| 12 | import zlib |
| 13 | except ImportError: |
| 14 | zlib = None |
| 15 | |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 16 | from distutils.core import Distribution |
| 17 | from distutils.command.bdist_rpm import bdist_rpm |
| 18 | from distutils.tests import support |
| 19 | from distutils.spawn import find_executable |
| 20 | from distutils import spawn |
| 21 | from distutils.errors import DistutilsExecError |
| 22 | |
| 23 | SETUP_PY = """\ |
| 24 | from distutils.core import setup |
| 25 | import foo |
| 26 | |
| 27 | setup(name='foo', version='0.1', py_modules=['foo'], |
| 28 | url='xxx', author='xxx', author_email='xxx') |
| 29 | |
| 30 | """ |
| 31 | |
| 32 | class BuildRpmTestCase(support.TempdirManager, |
R David Murray | ece9d5a | 2014-09-30 20:57:24 -0400 | [diff] [blame] | 33 | support.EnvironGuard, |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 34 | support.LoggingSilencer, |
| 35 | unittest.TestCase): |
| 36 | |
| 37 | def setUp(self): |
| 38 | super(BuildRpmTestCase, self).setUp() |
| 39 | self.old_location = os.getcwd() |
Tarek Ziadé | 2b06d42 | 2009-10-18 09:28:26 +0000 | [diff] [blame] | 40 | self.old_sys_argv = sys.argv, sys.argv[:] |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 41 | |
| 42 | def tearDown(self): |
| 43 | os.chdir(self.old_location) |
Tarek Ziadé | 2b06d42 | 2009-10-18 09:28:26 +0000 | [diff] [blame] | 44 | sys.argv = self.old_sys_argv[0] |
| 45 | sys.argv[:] = self.old_sys_argv[1] |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 46 | super(BuildRpmTestCase, self).tearDown() |
| 47 | |
Serhiy Storchaka | 57bc6da | 2013-12-18 16:45:37 +0200 | [diff] [blame] | 48 | # XXX I am unable yet to make this test work without |
| 49 | # spurious sdtout/stderr output under Mac OS X |
| 50 | @unittest.skipUnless(sys.platform.startswith('linux'), |
| 51 | 'spurious sdtout/stderr output under Mac OS X') |
Serhiy Storchaka | 59addd6 | 2016-10-23 22:54:43 +0300 | [diff] [blame] | 52 | @unittest.skipUnless(zlib, "requires zlib") |
Serhiy Storchaka | 57bc6da | 2013-12-18 16:45:37 +0200 | [diff] [blame] | 53 | @unittest.skipIf(find_executable('rpm') is None, |
| 54 | 'the rpm command is not found') |
| 55 | @unittest.skipIf(find_executable('rpmbuild') is None, |
| 56 | 'the rpmbuild command is not found') |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 57 | def test_quiet(self): |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 58 | # let's create a package |
| 59 | tmp_dir = self.mkdtemp() |
R David Murray | ece9d5a | 2014-09-30 20:57:24 -0400 | [diff] [blame] | 60 | os.environ['HOME'] = tmp_dir # to confine dir '.rpmdb' creation |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 61 | pkg_dir = os.path.join(tmp_dir, 'foo') |
| 62 | os.mkdir(pkg_dir) |
| 63 | self.write_file((pkg_dir, 'setup.py'), SETUP_PY) |
| 64 | self.write_file((pkg_dir, 'foo.py'), '#') |
| 65 | self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py') |
| 66 | self.write_file((pkg_dir, 'README'), '') |
| 67 | |
| 68 | dist = Distribution({'name': 'foo', 'version': '0.1', |
| 69 | 'py_modules': ['foo'], |
| 70 | 'url': 'xxx', 'author': 'xxx', |
| 71 | 'author_email': 'xxx'}) |
| 72 | dist.script_name = 'setup.py' |
| 73 | os.chdir(pkg_dir) |
| 74 | |
| 75 | sys.argv = ['setup.py'] |
| 76 | cmd = bdist_rpm(dist) |
| 77 | cmd.fix_python = True |
| 78 | |
| 79 | # running in quiet mode |
| 80 | cmd.quiet = 1 |
| 81 | cmd.ensure_finalized() |
| 82 | cmd.run() |
| 83 | |
| 84 | dist_created = os.listdir(os.path.join(pkg_dir, 'dist')) |
Serhiy Storchaka | 25a23ef | 2013-11-17 00:29:27 +0200 | [diff] [blame] | 85 | self.assertIn('foo-0.1-1.noarch.rpm', dist_created) |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 86 | |
Éric Araujo | d673b62 | 2012-02-26 01:16:47 +0100 | [diff] [blame] | 87 | # bug #2945: upload ignores bdist_rpm files |
| 88 | self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files) |
| 89 | self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files) |
| 90 | |
Serhiy Storchaka | 57bc6da | 2013-12-18 16:45:37 +0200 | [diff] [blame] | 91 | # XXX I am unable yet to make this test work without |
| 92 | # spurious sdtout/stderr output under Mac OS X |
| 93 | @unittest.skipUnless(sys.platform.startswith('linux'), |
| 94 | 'spurious sdtout/stderr output under Mac OS X') |
Serhiy Storchaka | 59addd6 | 2016-10-23 22:54:43 +0300 | [diff] [blame] | 95 | @unittest.skipUnless(zlib, "requires zlib") |
Serhiy Storchaka | 57bc6da | 2013-12-18 16:45:37 +0200 | [diff] [blame] | 96 | # http://bugs.python.org/issue1533164 |
| 97 | @unittest.skipIf(find_executable('rpm') is None, |
| 98 | 'the rpm command is not found') |
| 99 | @unittest.skipIf(find_executable('rpmbuild') is None, |
| 100 | 'the rpmbuild command is not found') |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 101 | def test_no_optimize_flag(self): |
Martin Panter | 88e4206 | 2016-12-18 05:27:49 +0000 | [diff] [blame] | 102 | # let's create a package that breaks bdist_rpm |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 103 | tmp_dir = self.mkdtemp() |
R David Murray | ece9d5a | 2014-09-30 20:57:24 -0400 | [diff] [blame] | 104 | os.environ['HOME'] = tmp_dir # to confine dir '.rpmdb' creation |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 105 | pkg_dir = os.path.join(tmp_dir, 'foo') |
| 106 | os.mkdir(pkg_dir) |
| 107 | self.write_file((pkg_dir, 'setup.py'), SETUP_PY) |
| 108 | self.write_file((pkg_dir, 'foo.py'), '#') |
| 109 | self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py') |
| 110 | self.write_file((pkg_dir, 'README'), '') |
| 111 | |
| 112 | dist = Distribution({'name': 'foo', 'version': '0.1', |
| 113 | 'py_modules': ['foo'], |
| 114 | 'url': 'xxx', 'author': 'xxx', |
| 115 | 'author_email': 'xxx'}) |
| 116 | dist.script_name = 'setup.py' |
| 117 | os.chdir(pkg_dir) |
| 118 | |
| 119 | sys.argv = ['setup.py'] |
| 120 | cmd = bdist_rpm(dist) |
| 121 | cmd.fix_python = True |
| 122 | |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 123 | cmd.quiet = 1 |
| 124 | cmd.ensure_finalized() |
| 125 | cmd.run() |
| 126 | |
| 127 | dist_created = os.listdir(os.path.join(pkg_dir, 'dist')) |
Serhiy Storchaka | 25a23ef | 2013-11-17 00:29:27 +0200 | [diff] [blame] | 128 | self.assertIn('foo-0.1-1.noarch.rpm', dist_created) |
Éric Araujo | d673b62 | 2012-02-26 01:16:47 +0100 | [diff] [blame] | 129 | |
| 130 | # bug #2945: upload ignores bdist_rpm files |
| 131 | self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files) |
| 132 | self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files) |
| 133 | |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 134 | os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm')) |
| 135 | |
Tarek Ziadé | 7334735 | 2009-02-28 10:08:02 +0000 | [diff] [blame] | 136 | def test_suite(): |
| 137 | return unittest.makeSuite(BuildRpmTestCase) |
| 138 | |
| 139 | if __name__ == '__main__': |
Georg Brandl | 28aeb0d | 2010-02-06 23:53:52 +0000 | [diff] [blame] | 140 | run_unittest(test_suite()) |