blob: fa4093cf3ca7531d80645095cf9d524e768453e6 [file] [log] [blame]
Tarek Ziade1231a4e2011-05-19 13:07:25 +02001"""Tests for distutils.command.bdist."""
2
3from packaging import util
4from packaging.command.bdist import bdist, show_formats
5
6from packaging.tests import unittest, support, captured_stdout
7
8
9class 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 Ziade1231a4e2011-05-19 13:07:25 +020030 # let's create a command and make sure
Éric Araujo83ab3f32011-08-30 01:19:02 +020031 # we can set the format
32 dist = self.create_dist()[1]
Tarek Ziade1231a4e2011-05-19 13:07:25 +020033 cmd = bdist(dist)
34 cmd.formats = ['msi']
35 cmd.ensure_finalized()
36 self.assertEqual(cmd.formats, ['msi'])
37
Éric Araujo83ab3f32011-08-30 01:19:02 +020038 # 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 Ziade1231a4e2011-05-19 13:07:25 +020042 found = sorted(cmd.format_command)
43 self.assertEqual(found, formats)
44
45 def test_skip_build(self):
Éric Araujo83ab3f32011-08-30 01:19:02 +020046 dist = self.create_dist()[1]
Tarek Ziade1231a4e2011-05-19 13:07:25 +020047 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 Araujo83ab3f32011-08-30 01:19:02 +020053 dist = self.create_dist()[1]
Tarek Ziade1231a4e2011-05-19 13:07:25 +020054 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
70def test_suite():
71 return unittest.makeSuite(BuildTestCase)
72
73if __name__ == '__main__':
74 unittest.main(defaultTest='test_suite')