]> git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.2/Lib/distutils/tests/test_bdist_rpm.py
a85f22471689df78c5bba482c4e37ef4e2d603e0
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / distutils / tests / test_bdist_rpm.py
1 """Tests for distutils.command.bdist_rpm."""
2
3 import unittest
4 import sys
5 import os
6 import tempfile
7 import shutil
8
9 from test.test_support import run_unittest
10
11 from distutils.core import Distribution
12 from distutils.command.bdist_rpm import bdist_rpm
13 from distutils.tests import support
14 from distutils.spawn import find_executable
15 from distutils import spawn
16 from distutils.errors import DistutilsExecError
17
18 SETUP_PY = """\
19 from distutils.core import setup
20 import foo
21
22 setup(name='foo', version='0.1', py_modules=['foo'],
23 url='xxx', author='xxx', author_email='xxx')
24
25 """
26
27 class BuildRpmTestCase(support.TempdirManager,
28 support.LoggingSilencer,
29 unittest.TestCase):
30
31 def setUp(self):
32 super(BuildRpmTestCase, self).setUp()
33 self.old_location = os.getcwd()
34 self.old_sys_argv = sys.argv, sys.argv[:]
35
36 def tearDown(self):
37 os.chdir(self.old_location)
38 sys.argv = self.old_sys_argv[0]
39 sys.argv[:] = self.old_sys_argv[1]
40 super(BuildRpmTestCase, self).tearDown()
41
42 def test_quiet(self):
43
44 # XXX I am unable yet to make this test work without
45 # spurious sdtout/stderr output under Mac OS X
46 if sys.platform != 'linux2':
47 return
48
49 # this test will run only if the rpm commands are found
50 if (find_executable('rpm') is None or
51 find_executable('rpmbuild') is None):
52 return
53
54 # let's create a package
55 tmp_dir = self.mkdtemp()
56 pkg_dir = os.path.join(tmp_dir, 'foo')
57 os.mkdir(pkg_dir)
58 self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
59 self.write_file((pkg_dir, 'foo.py'), '#')
60 self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
61 self.write_file((pkg_dir, 'README'), '')
62
63 dist = Distribution({'name': 'foo', 'version': '0.1',
64 'py_modules': ['foo'],
65 'url': 'xxx', 'author': 'xxx',
66 'author_email': 'xxx'})
67 dist.script_name = 'setup.py'
68 os.chdir(pkg_dir)
69
70 sys.argv = ['setup.py']
71 cmd = bdist_rpm(dist)
72 cmd.fix_python = True
73
74 # running in quiet mode
75 cmd.quiet = 1
76 cmd.ensure_finalized()
77 cmd.run()
78
79 dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
80 self.assertTrue('foo-0.1-1.noarch.rpm' in dist_created)
81
82 def test_no_optimize_flag(self):
83
84 # XXX I am unable yet to make this test work without
85 # spurious sdtout/stderr output under Mac OS X
86 if sys.platform != 'linux2':
87 return
88
89 # http://bugs.python.org/issue1533164
90 # this test will run only if the rpm command is found
91 if (find_executable('rpm') is None or
92 find_executable('rpmbuild') is None):
93 return
94
95 # let's create a package that brakes bdist_rpm
96 tmp_dir = self.mkdtemp()
97 pkg_dir = os.path.join(tmp_dir, 'foo')
98 os.mkdir(pkg_dir)
99 self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
100 self.write_file((pkg_dir, 'foo.py'), '#')
101 self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
102 self.write_file((pkg_dir, 'README'), '')
103
104 dist = Distribution({'name': 'foo', 'version': '0.1',
105 'py_modules': ['foo'],
106 'url': 'xxx', 'author': 'xxx',
107 'author_email': 'xxx'})
108 dist.script_name = 'setup.py'
109 os.chdir(pkg_dir)
110
111 sys.argv = ['setup.py']
112 cmd = bdist_rpm(dist)
113 cmd.fix_python = True
114
115 cmd.quiet = 1
116 cmd.ensure_finalized()
117 cmd.run()
118
119 dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
120 self.assertTrue('foo-0.1-1.noarch.rpm' in dist_created)
121 os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm'))
122
123 def test_suite():
124 return unittest.makeSuite(BuildRpmTestCase)
125
126 if __name__ == '__main__':
127 run_unittest(test_suite())