| 1 |
"""Tests for distutils.command.bdist_rpm.""" |
| 2 |
|
| 3 |
import unittest |
| 4 |
import sys |
| 5 |
import os |
| 6 |
from test.support import requires_zlib |
| 7 |
|
| 8 |
from distutils.core import Distribution |
| 9 |
from distutils.command.bdist_rpm import bdist_rpm |
| 10 |
from distutils.tests import support |
| 11 |
from distutils.spawn import find_executable |
| 12 |
|
| 13 |
SETUP_PY = """\ |
| 14 |
from distutils.core import setup |
| 15 |
import foo |
| 16 |
|
| 17 |
setup(name='foo', version='0.1', py_modules=['foo'], |
| 18 |
url='xxx', author='xxx', author_email='xxx') |
| 19 |
|
| 20 |
""" |
| 21 |
|
| 22 |
class BuildRpmTestCase(support.TempdirManager, |
| 23 |
support.EnvironGuard, |
| 24 |
support.LoggingSilencer, |
| 25 |
unittest.TestCase): |
| 26 |
|
| 27 |
def setUp(self): |
| 28 |
try: |
| 29 |
sys.executable.encode("UTF-8") |
| 30 |
except UnicodeEncodeError: |
| 31 |
raise unittest.SkipTest("sys.executable is not encodable to UTF-8") |
| 32 |
|
| 33 |
super(BuildRpmTestCase, self).setUp() |
| 34 |
self.old_location = os.getcwd() |
| 35 |
self.old_sys_argv = sys.argv, sys.argv[:] |
| 36 |
|
| 37 |
def tearDown(self): |
| 38 |
os.chdir(self.old_location) |
| 39 |
sys.argv = self.old_sys_argv[0] |
| 40 |
sys.argv[:] = self.old_sys_argv[1] |
| 41 |
super(BuildRpmTestCase, self).tearDown() |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
@unittest.skipUnless(sys.platform.startswith('linux'), |
| 46 |
'spurious sdtout/stderr output under Mac OS X') |
| 47 |
@requires_zlib() |
| 48 |
@unittest.skipIf(find_executable('rpm') is None, |
| 49 |
'the rpm command is not found') |
| 50 |
@unittest.skipIf(find_executable('rpmbuild') is None, |
| 51 |
'the rpmbuild command is not found') |
| 52 |
|
| 53 |
@unittest.skipIf(sys.flags.safe_path, |
| 54 |
'PYTHONSAFEPATH changes default sys.path') |
| 55 |
def test_quiet(self): |
| 56 |
|
| 57 |
tmp_dir = self.mkdtemp() |
| 58 |
os.environ['HOME'] = tmp_dir |
| 59 |
pkg_dir = os.path.join(tmp_dir, 'foo') |
| 60 |
os.mkdir(pkg_dir) |
| 61 |
self.write_file((pkg_dir, 'setup.py'), SETUP_PY) |
| 62 |
self.write_file((pkg_dir, 'foo.py'), '#') |
| 63 |
self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py') |
| 64 |
self.write_file((pkg_dir, 'README'), '') |
| 65 |
|
| 66 |
dist = Distribution({'name': 'foo', 'version': '0.1', |
| 67 |
'py_modules': ['foo'], |
| 68 |
'url': 'xxx', 'author': 'xxx', |
| 69 |
'author_email': 'xxx'}) |
| 70 |
dist.script_name = 'setup.py' |
| 71 |
os.chdir(pkg_dir) |
| 72 |
|
| 73 |
sys.argv = ['setup.py'] |
| 74 |
cmd = bdist_rpm(dist) |
| 75 |
cmd.fix_python = True |
| 76 |
|
| 77 |
|
| 78 |
cmd.quiet = 1 |
| 79 |
cmd.ensure_finalized() |
| 80 |
cmd.run() |
| 81 |
|
| 82 |
dist_created = os.listdir(os.path.join(pkg_dir, 'dist')) |
| 83 |
self.assertIn('foo-0.1-1.noarch.rpm', dist_created) |
| 84 |
|
| 85 |
|
| 86 |
self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files) |
| 87 |
self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files) |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
@unittest.skipUnless(sys.platform.startswith('linux'), |
| 92 |
'spurious sdtout/stderr output under Mac OS X') |
| 93 |
@requires_zlib() |
| 94 |
|
| 95 |
@unittest.skipIf(find_executable('rpm') is None, |
| 96 |
'the rpm command is not found') |
| 97 |
@unittest.skipIf(find_executable('rpmbuild') is None, |
| 98 |
'the rpmbuild command is not found') |
| 99 |
|
| 100 |
@unittest.skipIf(sys.flags.safe_path, |
| 101 |
'PYTHONSAFEPATH changes default sys.path') |
| 102 |
def test_no_optimize_flag(self): |
| 103 |
|
| 104 |
tmp_dir = self.mkdtemp() |
| 105 |
os.environ['HOME'] = tmp_dir |
| 106 |
pkg_dir = os.path.join(tmp_dir, 'foo') |
| 107 |
os.mkdir(pkg_dir) |
| 108 |
self.write_file((pkg_dir, 'setup.py'), SETUP_PY) |
| 109 |
self.write_file((pkg_dir, 'foo.py'), '#') |
| 110 |
self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py') |
| 111 |
self.write_file((pkg_dir, 'README'), '') |
| 112 |
|
| 113 |
dist = Distribution({'name': 'foo', 'version': '0.1', |
| 114 |
'py_modules': ['foo'], |
| 115 |
'url': 'xxx', 'author': 'xxx', |
| 116 |
'author_email': 'xxx'}) |
| 117 |
dist.script_name = 'setup.py' |
| 118 |
os.chdir(pkg_dir) |
| 119 |
|
| 120 |
sys.argv = ['setup.py'] |
| 121 |
cmd = bdist_rpm(dist) |
| 122 |
cmd.fix_python = True |
| 123 |
|
| 124 |
cmd.quiet = 1 |
| 125 |
cmd.ensure_finalized() |
| 126 |
cmd.run() |
| 127 |
|
| 128 |
dist_created = os.listdir(os.path.join(pkg_dir, 'dist')) |
| 129 |
self.assertIn('foo-0.1-1.noarch.rpm', dist_created) |
| 130 |
|
| 131 |
|
| 132 |
self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files) |
| 133 |
self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files) |
| 134 |
|
| 135 |
os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm')) |
| 136 |
|
| 137 |
if __name__ == '__main__': |
| 138 |
unittest.main() |