Tarek Ziade | 1231a4e | 2011-05-19 13:07:25 +0200 | [diff] [blame] | 1 | """Tests for distutils.command.bdist.""" |
| 2 | |
| 3 | from packaging import util |
| 4 | from packaging.command.bdist import bdist, show_formats |
| 5 | |
| 6 | from packaging.tests import unittest, support, captured_stdout |
| 7 | |
| 8 | |
| 9 | class BuildTestCase(support.TempdirManager, |
| 10 | support.LoggingCatcher, |
| 11 | unittest.TestCase): |
| 12 | |
| 13 | def _mock_get_platform(self): |
| 14 | self._get_platform_called = True |
| 15 | return self._get_platform() |
| 16 | |
| 17 | def setUp(self): |
| 18 | super(BuildTestCase, self).setUp() |
| 19 | |
| 20 | # mock util.get_platform |
| 21 | self._get_platform_called = False |
| 22 | self._get_platform = util.get_platform |
| 23 | util.get_platform = self._mock_get_platform |
| 24 | |
| 25 | def tearDown(self): |
| 26 | super(BuildTestCase, self).tearDown() |
| 27 | util.get_platform = self._get_platform |
| 28 | |
| 29 | def test_formats(self): |
Tarek Ziade | 1231a4e | 2011-05-19 13:07:25 +0200 | [diff] [blame] | 30 | # let's create a command and make sure |
Éric Araujo | 83ab3f3 | 2011-08-30 01:19:02 +0200 | [diff] [blame^] | 31 | # we can set the format |
| 32 | dist = self.create_dist()[1] |
Tarek Ziade | 1231a4e | 2011-05-19 13:07:25 +0200 | [diff] [blame] | 33 | cmd = bdist(dist) |
| 34 | cmd.formats = ['msi'] |
| 35 | cmd.ensure_finalized() |
| 36 | self.assertEqual(cmd.formats, ['msi']) |
| 37 | |
Éric Araujo | 83ab3f3 | 2011-08-30 01:19:02 +0200 | [diff] [blame^] | 38 | # what format does bdist offer? |
| 39 | # XXX hard-coded lists are not the best way to find available bdist_* |
| 40 | # commands; we should add a registry |
| 41 | formats = ['bztar', 'gztar', 'msi', 'tar', 'wininst', 'zip'] |
Tarek Ziade | 1231a4e | 2011-05-19 13:07:25 +0200 | [diff] [blame] | 42 | found = sorted(cmd.format_command) |
| 43 | self.assertEqual(found, formats) |
| 44 | |
| 45 | def test_skip_build(self): |
Éric Araujo | 83ab3f3 | 2011-08-30 01:19:02 +0200 | [diff] [blame^] | 46 | dist = self.create_dist()[1] |
Tarek Ziade | 1231a4e | 2011-05-19 13:07:25 +0200 | [diff] [blame] | 47 | cmd = bdist(dist) |
| 48 | cmd.skip_build = False |
| 49 | cmd.formats = ['ztar'] |
| 50 | cmd.ensure_finalized() |
| 51 | self.assertFalse(self._get_platform_called) |
| 52 | |
Éric Araujo | 83ab3f3 | 2011-08-30 01:19:02 +0200 | [diff] [blame^] | 53 | dist = self.create_dist()[1] |
Tarek Ziade | 1231a4e | 2011-05-19 13:07:25 +0200 | [diff] [blame] | 54 | cmd = bdist(dist) |
| 55 | cmd.skip_build = True |
| 56 | cmd.formats = ['ztar'] |
| 57 | cmd.ensure_finalized() |
| 58 | self.assertTrue(self._get_platform_called) |
| 59 | |
| 60 | def test_show_formats(self): |
| 61 | __, stdout = captured_stdout(show_formats) |
| 62 | |
| 63 | # the output should be a header line + one line per format |
| 64 | num_formats = len(bdist.format_commands) |
| 65 | output = [line for line in stdout.split('\n') |
| 66 | if line.strip().startswith('--formats=')] |
| 67 | self.assertEqual(len(output), num_formats) |
| 68 | |
| 69 | |
| 70 | def test_suite(): |
| 71 | return unittest.makeSuite(BuildTestCase) |
| 72 | |
| 73 | if __name__ == '__main__': |
| 74 | unittest.main(defaultTest='test_suite') |