ยปCore Development>Code coverage>Lib/packaging/tests/test_command_bdist.py

Python code coverage for Lib/packaging/tests/test_command_bdist.py

#countcontent
1n/a"""Tests for distutils.command.bdist."""
2n/aimport os
3n/afrom test.support import captured_stdout
4n/afrom packaging.command.bdist import bdist, show_formats
5n/afrom packaging.tests import unittest, support
6n/a
7n/a
8n/aclass BuildTestCase(support.TempdirManager,
9n/a support.LoggingCatcher,
10n/a unittest.TestCase):
11n/a
12n/a def test_formats(self):
13n/a # let's create a command and make sure
14n/a # we can set the format
15n/a dist = self.create_dist()[1]
16n/a cmd = bdist(dist)
17n/a cmd.formats = ['msi']
18n/a cmd.ensure_finalized()
19n/a self.assertEqual(cmd.formats, ['msi'])
20n/a
21n/a # what formats does bdist offer?
22n/a # XXX hard-coded lists are not the best way to find available bdist_*
23n/a # commands; we should add a registry
24n/a formats = ['bztar', 'gztar', 'msi', 'tar', 'wininst', 'zip']
25n/a found = sorted(cmd.format_command)
26n/a self.assertEqual(found, formats)
27n/a
28n/a def test_skip_build(self):
29n/a # bug #10946: bdist --skip-build should trickle down to subcommands
30n/a dist = self.create_dist()[1]
31n/a cmd = bdist(dist)
32n/a cmd.skip_build = True
33n/a cmd.ensure_finalized()
34n/a dist.command_obj['bdist'] = cmd
35n/a
36n/a names = ['bdist_dumb', 'bdist_wininst']
37n/a if os.name == 'nt':
38n/a names.append('bdist_msi')
39n/a
40n/a for name in names:
41n/a subcmd = cmd.get_finalized_command(name)
42n/a self.assertTrue(subcmd.skip_build,
43n/a '%s should take --skip-build from bdist' % name)
44n/a
45n/a def test_show_formats(self):
46n/a with captured_stdout() as stdout:
47n/a show_formats()
48n/a stdout = stdout.getvalue()
49n/a
50n/a # the output should be a header line + one line per format
51n/a num_formats = len(bdist.format_commands)
52n/a output = [line for line in stdout.split('\n')
53n/a if line.strip().startswith('--formats=')]
54n/a self.assertEqual(len(output), num_formats)
55n/a
56n/a
57n/adef test_suite():
58n/a return unittest.makeSuite(BuildTestCase)
59n/a
60n/aif __name__ == '__main__':
61n/a unittest.main(defaultTest='test_suite')