| 
									
										
										
										
											2009-02-28 10:16:43 +00:00
										 |  |  | """Tests for distutils.command.bdist_rpm.""" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import unittest | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import os | 
					
						
							| 
									
										
										
										
											2016-10-23 22:56:14 +03:00
										 |  |  | from test.support import run_unittest, requires_zlib | 
					
						
							| 
									
										
										
										
											2009-02-28 10:16:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | from distutils.core import Distribution | 
					
						
							|  |  |  | from distutils.command.bdist_rpm import bdist_rpm | 
					
						
							|  |  |  | from distutils.tests import support | 
					
						
							|  |  |  | from distutils.spawn import find_executable | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SETUP_PY = """\
 | 
					
						
							|  |  |  | from distutils.core import setup | 
					
						
							|  |  |  | import foo | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | setup(name='foo', version='0.1', py_modules=['foo'], | 
					
						
							|  |  |  |       url='xxx', author='xxx', author_email='xxx') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BuildRpmTestCase(support.TempdirManager, | 
					
						
							| 
									
										
										
										
											2014-09-30 20:53:21 -04:00
										 |  |  |                        support.EnvironGuard, | 
					
						
							| 
									
										
										
										
											2009-02-28 10:16:43 +00:00
										 |  |  |                        support.LoggingSilencer, | 
					
						
							|  |  |  |                        unittest.TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							| 
									
										
										
										
											2011-03-14 20:03:36 -04:00
										 |  |  |         try: | 
					
						
							|  |  |  |             sys.executable.encode("UTF-8") | 
					
						
							|  |  |  |         except UnicodeEncodeError: | 
					
						
							|  |  |  |             raise unittest.SkipTest("sys.executable is not encodable to UTF-8") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-28 10:16:43 +00:00
										 |  |  |         super(BuildRpmTestCase, self).setUp() | 
					
						
							|  |  |  |         self.old_location = os.getcwd() | 
					
						
							| 
									
										
										
										
											2009-10-18 11:34:51 +00:00
										 |  |  |         self.old_sys_argv = sys.argv, sys.argv[:] | 
					
						
							| 
									
										
										
										
											2009-02-28 10:16:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def tearDown(self): | 
					
						
							|  |  |  |         os.chdir(self.old_location) | 
					
						
							| 
									
										
										
										
											2009-10-18 11:34:51 +00:00
										 |  |  |         sys.argv = self.old_sys_argv[0] | 
					
						
							|  |  |  |         sys.argv[:] = self.old_sys_argv[1] | 
					
						
							| 
									
										
										
										
											2009-02-28 10:16:43 +00:00
										 |  |  |         super(BuildRpmTestCase, self).tearDown() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-18 16:41:01 +02:00
										 |  |  |     # XXX I am unable yet to make this test work without | 
					
						
							|  |  |  |     # spurious sdtout/stderr output under Mac OS X | 
					
						
							|  |  |  |     @unittest.skipUnless(sys.platform.startswith('linux'), | 
					
						
							|  |  |  |                          'spurious sdtout/stderr output under Mac OS X') | 
					
						
							| 
									
										
										
										
											2021-09-13 10:08:35 -07:00
										 |  |  |     @requires_zlib() | 
					
						
							| 
									
										
										
										
											2013-12-18 16:41:01 +02:00
										 |  |  |     @unittest.skipIf(find_executable('rpm') is None, | 
					
						
							|  |  |  |                      'the rpm command is not found') | 
					
						
							|  |  |  |     @unittest.skipIf(find_executable('rpmbuild') is None, | 
					
						
							|  |  |  |                      'the rpmbuild command is not found') | 
					
						
							| 
									
										
										
										
											2009-02-28 10:16:43 +00:00
										 |  |  |     def test_quiet(self): | 
					
						
							|  |  |  |         # let's create a package | 
					
						
							|  |  |  |         tmp_dir = self.mkdtemp() | 
					
						
							| 
									
										
										
										
											2014-09-30 20:53:21 -04:00
										 |  |  |         os.environ['HOME'] = tmp_dir   # to confine dir '.rpmdb' creation | 
					
						
							| 
									
										
										
										
											2009-02-28 10:16:43 +00:00
										 |  |  |         pkg_dir = os.path.join(tmp_dir, 'foo') | 
					
						
							|  |  |  |         os.mkdir(pkg_dir) | 
					
						
							|  |  |  |         self.write_file((pkg_dir, 'setup.py'), SETUP_PY) | 
					
						
							|  |  |  |         self.write_file((pkg_dir, 'foo.py'), '#') | 
					
						
							|  |  |  |         self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py') | 
					
						
							|  |  |  |         self.write_file((pkg_dir, 'README'), '') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dist = Distribution({'name': 'foo', 'version': '0.1', | 
					
						
							|  |  |  |                              'py_modules': ['foo'], | 
					
						
							|  |  |  |                              'url': 'xxx', 'author': 'xxx', | 
					
						
							|  |  |  |                              'author_email': 'xxx'}) | 
					
						
							|  |  |  |         dist.script_name = 'setup.py' | 
					
						
							|  |  |  |         os.chdir(pkg_dir) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         sys.argv = ['setup.py'] | 
					
						
							|  |  |  |         cmd = bdist_rpm(dist) | 
					
						
							|  |  |  |         cmd.fix_python = True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # running in quiet mode | 
					
						
							|  |  |  |         cmd.quiet = 1 | 
					
						
							|  |  |  |         cmd.ensure_finalized() | 
					
						
							|  |  |  |         cmd.run() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dist_created = os.listdir(os.path.join(pkg_dir, 'dist')) | 
					
						
							| 
									
										
										
										
											2013-11-17 00:17:46 +02:00
										 |  |  |         self.assertIn('foo-0.1-1.noarch.rpm', dist_created) | 
					
						
							| 
									
										
										
										
											2009-02-28 10:16:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-15 02:48:55 +01:00
										 |  |  |         # bug #2945: upload ignores bdist_rpm files | 
					
						
							|  |  |  |         self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files) | 
					
						
							|  |  |  |         self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-18 16:41:01 +02:00
										 |  |  |     # XXX I am unable yet to make this test work without | 
					
						
							|  |  |  |     # spurious sdtout/stderr output under Mac OS X | 
					
						
							|  |  |  |     @unittest.skipUnless(sys.platform.startswith('linux'), | 
					
						
							|  |  |  |                          'spurious sdtout/stderr output under Mac OS X') | 
					
						
							| 
									
										
										
										
											2021-09-13 10:08:35 -07:00
										 |  |  |     @requires_zlib() | 
					
						
							| 
									
										
										
										
											2013-12-18 16:41:01 +02:00
										 |  |  |     # http://bugs.python.org/issue1533164 | 
					
						
							|  |  |  |     @unittest.skipIf(find_executable('rpm') is None, | 
					
						
							|  |  |  |                      'the rpm command is not found') | 
					
						
							|  |  |  |     @unittest.skipIf(find_executable('rpmbuild') is None, | 
					
						
							|  |  |  |                      'the rpmbuild command is not found') | 
					
						
							| 
									
										
										
										
											2009-02-28 10:16:43 +00:00
										 |  |  |     def test_no_optimize_flag(self): | 
					
						
							| 
									
										
										
										
											2016-12-18 01:23:09 +00:00
										 |  |  |         # let's create a package that breaks bdist_rpm | 
					
						
							| 
									
										
										
										
											2009-02-28 10:16:43 +00:00
										 |  |  |         tmp_dir = self.mkdtemp() | 
					
						
							| 
									
										
										
										
											2014-09-30 20:53:21 -04:00
										 |  |  |         os.environ['HOME'] = tmp_dir   # to confine dir '.rpmdb' creation | 
					
						
							| 
									
										
										
										
											2009-02-28 10:16:43 +00:00
										 |  |  |         pkg_dir = os.path.join(tmp_dir, 'foo') | 
					
						
							|  |  |  |         os.mkdir(pkg_dir) | 
					
						
							|  |  |  |         self.write_file((pkg_dir, 'setup.py'), SETUP_PY) | 
					
						
							|  |  |  |         self.write_file((pkg_dir, 'foo.py'), '#') | 
					
						
							|  |  |  |         self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py') | 
					
						
							|  |  |  |         self.write_file((pkg_dir, 'README'), '') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dist = Distribution({'name': 'foo', 'version': '0.1', | 
					
						
							|  |  |  |                              'py_modules': ['foo'], | 
					
						
							|  |  |  |                              'url': 'xxx', 'author': 'xxx', | 
					
						
							|  |  |  |                              'author_email': 'xxx'}) | 
					
						
							|  |  |  |         dist.script_name = 'setup.py' | 
					
						
							|  |  |  |         os.chdir(pkg_dir) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         sys.argv = ['setup.py'] | 
					
						
							|  |  |  |         cmd = bdist_rpm(dist) | 
					
						
							|  |  |  |         cmd.fix_python = True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cmd.quiet = 1 | 
					
						
							|  |  |  |         cmd.ensure_finalized() | 
					
						
							|  |  |  |         cmd.run() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dist_created = os.listdir(os.path.join(pkg_dir, 'dist')) | 
					
						
							| 
									
										
										
										
											2013-11-17 00:17:46 +02:00
										 |  |  |         self.assertIn('foo-0.1-1.noarch.rpm', dist_created) | 
					
						
							| 
									
										
										
										
											2012-01-15 02:48:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # bug #2945: upload ignores bdist_rpm files | 
					
						
							|  |  |  |         self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files) | 
					
						
							|  |  |  |         self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-28 10:16:43 +00:00
										 |  |  |         os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm')) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_suite(): | 
					
						
							|  |  |  |     return unittest.makeSuite(BuildRpmTestCase) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							| 
									
										
										
										
											2010-11-06 02:44:43 +00:00
										 |  |  |     run_unittest(test_suite()) |