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