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