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