blob: 1522b7e2142b7242bd6e95e9d2c2cbeb4e68aec5 [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):
30
31 # let's create a command and make sure
32 # we can fix the format
33 pkg_pth, dist = self.create_dist()
34 cmd = bdist(dist)
35 cmd.formats = ['msi']
36 cmd.ensure_finalized()
37 self.assertEqual(cmd.formats, ['msi'])
38
39 # what format bdist offers ?
40 # XXX an explicit list in bdist is
41 # not the best way to bdist_* commands
42 # we should add a registry
43 formats = sorted(('zip', 'gztar', 'bztar', 'ztar',
44 'tar', 'wininst', 'msi'))
45 found = sorted(cmd.format_command)
46 self.assertEqual(found, formats)
47
48 def test_skip_build(self):
49 pkg_pth, dist = self.create_dist()
50 cmd = bdist(dist)
51 cmd.skip_build = False
52 cmd.formats = ['ztar']
53 cmd.ensure_finalized()
54 self.assertFalse(self._get_platform_called)
55
56 pkg_pth, dist = self.create_dist()
57 cmd = bdist(dist)
58 cmd.skip_build = True
59 cmd.formats = ['ztar']
60 cmd.ensure_finalized()
61 self.assertTrue(self._get_platform_called)
62
63 def test_show_formats(self):
64 __, stdout = captured_stdout(show_formats)
65
66 # the output should be a header line + one line per format
67 num_formats = len(bdist.format_commands)
68 output = [line for line in stdout.split('\n')
69 if line.strip().startswith('--formats=')]
70 self.assertEqual(len(output), num_formats)
71
72
73def test_suite():
74 return unittest.makeSuite(BuildTestCase)
75
76if __name__ == '__main__':
77 unittest.main(defaultTest='test_suite')