Issue #7575: An overflow test for math.expm1 was failing on OS X 10.4/Intel,
[python.git] / Lib / distutils / tests / test_bdist_dumb.py
blob5eaef2a9d70229aacf253a1d9727dd0c889aac96
1 """Tests for distutils.command.bdist_dumb."""
3 import unittest
4 import sys
5 import os
7 # zlib is not used here, but if it's not available
8 # test_simple_built will fail
9 try:
10 import zlib
11 except ImportError:
12 zlib = None
14 from distutils.core import Distribution
15 from distutils.command.bdist_dumb import bdist_dumb
16 from distutils.tests import support
18 SETUP_PY = """\
19 from distutils.core import setup
20 import foo
22 setup(name='foo', version='0.1', py_modules=['foo'],
23 url='xxx', author='xxx', author_email='xxx')
25 """
27 class BuildDumbTestCase(support.TempdirManager,
28 support.LoggingSilencer,
29 support.EnvironGuard,
30 unittest.TestCase):
32 def setUp(self):
33 super(BuildDumbTestCase, self).setUp()
34 self.old_location = os.getcwd()
35 self.old_sys_argv = sys.argv, sys.argv[:]
37 def tearDown(self):
38 os.chdir(self.old_location)
39 sys.argv = self.old_sys_argv[0]
40 sys.argv[:] = self.old_sys_argv[1]
41 super(BuildDumbTestCase, self).tearDown()
43 @unittest.skipUnless(zlib, "requires zlib")
44 def test_simple_built(self):
46 # let's create a simple package
47 tmp_dir = self.mkdtemp()
48 pkg_dir = os.path.join(tmp_dir, 'foo')
49 os.mkdir(pkg_dir)
50 self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
51 self.write_file((pkg_dir, 'foo.py'), '#')
52 self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
53 self.write_file((pkg_dir, 'README'), '')
55 dist = Distribution({'name': 'foo', 'version': '0.1',
56 'py_modules': ['foo'],
57 'url': 'xxx', 'author': 'xxx',
58 'author_email': 'xxx'})
59 dist.script_name = 'setup.py'
60 os.chdir(pkg_dir)
62 sys.argv = ['setup.py']
63 cmd = bdist_dumb(dist)
65 # so the output is the same no matter
66 # what is the platform
67 cmd.format = 'zip'
69 cmd.ensure_finalized()
70 cmd.run()
72 # see what we have
73 dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
74 base = "%s.%s" % (dist.get_fullname(), cmd.plat_name)
75 if os.name == 'os2':
76 base = base.replace(':', '-')
78 wanted = ['%s.zip' % base]
79 self.assertEquals(dist_created, wanted)
81 # now let's check what we have in the zip file
82 # XXX to be done
84 def test_finalize_options(self):
85 pkg_dir, dist = self.create_dist()
86 os.chdir(pkg_dir)
87 cmd = bdist_dumb(dist)
88 self.assertEquals(cmd.bdist_dir, None)
89 cmd.finalize_options()
91 # bdist_dir is initialized to bdist_base/dumb if not set
92 base = cmd.get_finalized_command('bdist').bdist_base
93 self.assertEquals(cmd.bdist_dir, os.path.join(base, 'dumb'))
95 # the format is set to a default value depending on the os.name
96 default = cmd.default_format[os.name]
97 self.assertEquals(cmd.format, default)
99 def test_suite():
100 return unittest.makeSuite(BuildDumbTestCase)
102 if __name__ == '__main__':
103 test_support.run_unittest(test_suite())