1"""Tests for distutils.command.build."""
2import unittest
3import os
4import sys
5from test.test_support import run_unittest
6
7from distutils.command.build import build
8from distutils.tests import support
9from sysconfig import get_platform
10
11class BuildTestCase(support.TempdirManager,
12                    support.LoggingSilencer,
13                    unittest.TestCase):
14
15    def test_finalize_options(self):
16        pkg_dir, dist = self.create_dist()
17        cmd = build(dist)
18        cmd.finalize_options()
19
20        # if not specified, plat_name gets the current platform
21        self.assertEqual(cmd.plat_name, get_platform())
22
23        # build_purelib is build + lib
24        wanted = os.path.join(cmd.build_base, 'lib')
25        self.assertEqual(cmd.build_purelib, wanted)
26
27        # build_platlib is 'build/lib.platform-x.x[-pydebug]'
28        # examples:
29        #   build/lib.macosx-10.3-i386-2.7
30        plat_spec = '.%s-%s' % (cmd.plat_name, sys.version[0:3])
31        if hasattr(sys, 'gettotalrefcount'):
32            self.assertTrue(cmd.build_platlib.endswith('-pydebug'))
33            plat_spec += '-pydebug'
34        wanted = os.path.join(cmd.build_base, 'lib' + plat_spec)
35        self.assertEqual(cmd.build_platlib, wanted)
36
37        # by default, build_lib = build_purelib
38        self.assertEqual(cmd.build_lib, cmd.build_purelib)
39
40        # build_temp is build/temp.<plat>
41        wanted = os.path.join(cmd.build_base, 'temp' + plat_spec)
42        self.assertEqual(cmd.build_temp, wanted)
43
44        # build_scripts is build/scripts-x.x
45        wanted = os.path.join(cmd.build_base, 'scripts-' +  sys.version[0:3])
46        self.assertEqual(cmd.build_scripts, wanted)
47
48        # executable is os.path.normpath(sys.executable)
49        self.assertEqual(cmd.executable, os.path.normpath(sys.executable))
50
51def test_suite():
52    return unittest.makeSuite(BuildTestCase)
53
54if __name__ == "__main__":
55    run_unittest(test_suite())
56