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