test_build.py 1.9 KB

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