ยปCore Development>Code coverage>Lib/distutils/tests/test_bdist_rpm.py

Python code coverage for Lib/distutils/tests/test_bdist_rpm.py

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