summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/tests/test_bdist_rpm.py
diff options
context:
space:
mode:
authorTarek Ziadé <ziade.tarek@gmail.com>2009-02-28 10:16:43 (GMT)
committerTarek Ziadé <ziade.tarek@gmail.com>2009-02-28 10:16:43 (GMT)
commitf072122c79955e0e7695eb3f104bbd5d32132159 (patch)
tree77ef96790f7e437272f14a450b8e8efe9098a570 /Lib/distutils/tests/test_bdist_rpm.py
parente9a950e3c2d0f3cd3544bec881c94d121859043e (diff)
downloadcpython-f072122c79955e0e7695eb3f104bbd5d32132159.zip
cpython-f072122c79955e0e7695eb3f104bbd5d32132159.tar.gz
cpython-f072122c79955e0e7695eb3f104bbd5d32132159.tar.bz2
Merged revisions 70049 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r70049 | tarek.ziade | 2009-02-28 11:08:02 +0100 (Sat, 28 Feb 2009) | 1 line Issues #1533164 and #5378: Added quiet and force-optimize options to Distutils bdist_rpm command ........
Diffstat (limited to 'Lib/distutils/tests/test_bdist_rpm.py')
-rw-r--r--Lib/distutils/tests/test_bdist_rpm.py149
1 files changed, 149 insertions, 0 deletions
diff --git a/Lib/distutils/tests/test_bdist_rpm.py b/Lib/distutils/tests/test_bdist_rpm.py
new file mode 100644
index 0000000..ff40628
--- /dev/null
+++ b/Lib/distutils/tests/test_bdist_rpm.py
@@ -0,0 +1,149 @@
+"""Tests for distutils.command.bdist_rpm."""
+
+import unittest
+import sys
+import os
+import tempfile
+import shutil
+
+from distutils.core import Distribution
+from distutils.command.bdist_rpm import bdist_rpm
+from distutils.tests import support
+from distutils.spawn import find_executable
+from distutils import spawn
+from distutils.errors import DistutilsExecError
+
+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,
+ support.LoggingSilencer,
+ unittest.TestCase):
+
+ def setUp(self):
+ super(BuildRpmTestCase, self).setUp()
+ self.old_location = os.getcwd()
+ self.old_sys_argv = sys.argv[:]
+
+ def tearDown(self):
+ os.chdir(self.old_location)
+ sys.argv = self.old_sys_argv[:]
+ super(BuildRpmTestCase, self).tearDown()
+
+ def test_quiet(self):
+
+ # XXX I am unable yet to make this test work without
+ # spurious sdtout/stderr output under Mac OS X
+ if sys.platform != 'linux2':
+ return
+
+ # this test will run only if the rpm commands are found
+ if (find_executable('rpm') is None or
+ find_executable('rpmbuild') is None):
+ return
+
+ # let's create a package
+ tmp_dir = self.mkdtemp()
+ 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'))
+ self.assert_('foo-0.1-1.noarch.rpm' in dist_created)
+
+ def test_no_optimize_flag(self):
+
+ # XXX I am unable yet to make this test work without
+ # spurious sdtout/stderr output under Mac OS X
+ if sys.platform != 'linux2':
+ return
+
+ # http://bugs.python.org/issue1533164
+ # this test will run only if the rpm command is found
+ if (find_executable('rpm') is None or
+ find_executable('rpmbuild') is None):
+ return
+
+ # let's create a package that brakes bdist_rpm
+ tmp_dir = self.mkdtemp()
+ 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 with force-optimize = 1
+ # and quiet = 1
+ cmd.quiet = 1
+ cmd.ensure_finalized()
+ cmd.run()
+
+ dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
+ self.assert_('foo-0.1-1.noarch.rpm' in dist_created)
+ os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm'))
+
+ # XXX I am unable yet to make this test work without
+ # spurious stderr output
+ # so returning until distutils.spawn acts better
+ return
+
+ # running with force-optimize = 0
+ cmd.force_optimize = 0
+ try:
+ # XXX How to prevent the spawned
+ # rpmbuild command to display errors ?
+ # this can be a problem for buildbots
+ cmd.ensure_finalized()
+ cmd.run()
+ except DistutilsExecError:
+ # happens only under Fedora/RedHat
+ # and some flavors of Linux
+ # otherwise it's a bug
+ if sys.platform == 'linux2':
+ return
+
+ dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
+ self.assert_('foo-0.1-1.noarch.rpm' in dist_created)
+
+def test_suite():
+ return unittest.makeSuite(BuildRpmTestCase)
+
+if __name__ == '__main__':
+ test_support.run_unittest(test_suite())