test_install_scripts.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """Tests for distutils.command.install_scripts."""
  2. import os
  3. import unittest
  4. from distutils.command.install_scripts import install_scripts
  5. from distutils.core import Distribution
  6. from distutils.tests import support
  7. from test.support import run_unittest
  8. class InstallScriptsTestCase(support.TempdirManager,
  9. support.LoggingSilencer,
  10. unittest.TestCase):
  11. def test_default_settings(self):
  12. dist = Distribution()
  13. dist.command_obj["build"] = support.DummyCommand(
  14. build_scripts="/foo/bar")
  15. dist.command_obj["install"] = support.DummyCommand(
  16. install_scripts="/splat/funk",
  17. force=1,
  18. skip_build=1,
  19. )
  20. cmd = install_scripts(dist)
  21. self.assertFalse(cmd.force)
  22. self.assertFalse(cmd.skip_build)
  23. self.assertIsNone(cmd.build_dir)
  24. self.assertIsNone(cmd.install_dir)
  25. cmd.finalize_options()
  26. self.assertTrue(cmd.force)
  27. self.assertTrue(cmd.skip_build)
  28. self.assertEqual(cmd.build_dir, "/foo/bar")
  29. self.assertEqual(cmd.install_dir, "/splat/funk")
  30. def test_installation(self):
  31. source = self.mkdtemp()
  32. expected = []
  33. def write_script(name, text):
  34. expected.append(name)
  35. f = open(os.path.join(source, name), "w")
  36. try:
  37. f.write(text)
  38. finally:
  39. f.close()
  40. write_script("script1.py", ("#! /usr/bin/env python2.3\n"
  41. "# bogus script w/ Python sh-bang\n"
  42. "pass\n"))
  43. write_script("script2.py", ("#!/usr/bin/python\n"
  44. "# bogus script w/ Python sh-bang\n"
  45. "pass\n"))
  46. write_script("shell.sh", ("#!/bin/sh\n"
  47. "# bogus shell script w/ sh-bang\n"
  48. "exit 0\n"))
  49. target = self.mkdtemp()
  50. dist = Distribution()
  51. dist.command_obj["build"] = support.DummyCommand(build_scripts=source)
  52. dist.command_obj["install"] = support.DummyCommand(
  53. install_scripts=target,
  54. force=1,
  55. skip_build=1,
  56. )
  57. cmd = install_scripts(dist)
  58. cmd.finalize_options()
  59. cmd.run()
  60. installed = os.listdir(target)
  61. for name in expected:
  62. self.assertIn(name, installed)
  63. def test_suite():
  64. return unittest.makeSuite(InstallScriptsTestCase)
  65. if __name__ == "__main__":
  66. run_unittest(test_suite())