1"""Tests for distutils.command.bdist."""
2import os
3import unittest
4
5from test.test_support import run_unittest
6
7from distutils.command.bdist import bdist
8from distutils.tests import support
9
10
11class BuildTestCase(support.TempdirManager,
12                    unittest.TestCase):
13
14    def test_formats(self):
15        # let's create a command and make sure
16        # we can set the format
17        dist = self.create_dist()[1]
18        cmd = bdist(dist)
19        cmd.formats = ['msi']
20        cmd.ensure_finalized()
21        self.assertEqual(cmd.formats, ['msi'])
22
23        # what formats does bdist offer?
24        formats = ['bztar', 'gztar', 'msi', 'rpm', 'tar',
25                   'wininst', 'zip', 'ztar']
26        found = sorted(cmd.format_command)
27        self.assertEqual(found, formats)
28
29    def test_skip_build(self):
30        # bug #10946: bdist --skip-build should trickle down to subcommands
31        dist = self.create_dist()[1]
32        cmd = bdist(dist)
33        cmd.skip_build = 1
34        cmd.ensure_finalized()
35        dist.command_obj['bdist'] = cmd
36
37        names = ['bdist_dumb', 'bdist_wininst']
38        # bdist_rpm does not support --skip-build
39        if os.name == 'nt':
40            names.append('bdist_msi')
41
42        for name in names:
43            subcmd = cmd.get_finalized_command(name)
44            self.assertTrue(subcmd.skip_build,
45                            '%s should take --skip-build from bdist' % name)
46
47
48def test_suite():
49    return unittest.makeSuite(BuildTestCase)
50
51if __name__ == '__main__':
52    run_unittest(test_suite())
53