1"""Tests for distutils.command.bdist."""
2import os
3import unittest
4from test.support import run_unittest
5import warnings
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', 'xztar', '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']  # bdist_rpm does not support --skip-build
38        if os.name == 'nt':
39            names.append('bdist_msi')
40
41        for name in names:
42            with warnings.catch_warnings():
43                warnings.filterwarnings('ignore', 'bdist_wininst command is deprecated',
44                                        DeprecationWarning)
45                subcmd = cmd.get_finalized_command(name)
46            if getattr(subcmd, '_unsupported', False):
47                # command is not supported on this build
48                continue
49            self.assertTrue(subcmd.skip_build,
50                            '%s should take --skip-build from bdist' % name)
51
52
53def test_suite():
54    return unittest.makeSuite(BuildTestCase)
55
56if __name__ == '__main__':
57    run_unittest(test_suite())
58