Fred Drake | bb7c144 | 2004-06-15 15:49:46 +0000 | [diff] [blame] | 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 | |
Fred Drake | b8ab8b6 | 2004-06-17 20:14:50 +0000 | [diff] [blame] | 9 | from distutils.tests import support |
Éric Araujo | b344dd0 | 2011-02-02 21:38:37 +0000 | [diff] [blame^] | 10 | from test.support import run_unittest |
Fred Drake | bb7c144 | 2004-06-15 15:49:46 +0000 | [diff] [blame] | 11 | |
Fred Drake | bb7c144 | 2004-06-15 15:49:46 +0000 | [diff] [blame] | 12 | |
Fred Drake | edcac8f | 2004-08-03 18:53:07 +0000 | [diff] [blame] | 13 | class InstallScriptsTestCase(support.TempdirManager, |
| 14 | support.LoggingSilencer, |
| 15 | unittest.TestCase): |
Fred Drake | d0620dc | 2004-06-15 16:55:46 +0000 | [diff] [blame] | 16 | |
Fred Drake | bb7c144 | 2004-06-15 15:49:46 +0000 | [diff] [blame] | 17 | def test_default_settings(self): |
| 18 | dist = Distribution() |
Fred Drake | b8ab8b6 | 2004-06-17 20:14:50 +0000 | [diff] [blame] | 19 | dist.command_obj["build"] = support.DummyCommand( |
| 20 | build_scripts="/foo/bar") |
| 21 | dist.command_obj["install"] = support.DummyCommand( |
Fred Drake | bb7c144 | 2004-06-15 15:49:46 +0000 | [diff] [blame] | 22 | install_scripts="/splat/funk", |
| 23 | force=1, |
| 24 | skip_build=1, |
| 25 | ) |
| 26 | cmd = install_scripts(dist) |
Georg Brandl | ab91fde | 2009-08-13 08:51:18 +0000 | [diff] [blame] | 27 | self.assertTrue(not cmd.force) |
| 28 | self.assertTrue(not cmd.skip_build) |
| 29 | self.assertTrue(cmd.build_dir is None) |
| 30 | self.assertTrue(cmd.install_dir is None) |
Fred Drake | bb7c144 | 2004-06-15 15:49:46 +0000 | [diff] [blame] | 31 | |
| 32 | cmd.finalize_options() |
| 33 | |
Georg Brandl | ab91fde | 2009-08-13 08:51:18 +0000 | [diff] [blame] | 34 | self.assertTrue(cmd.force) |
| 35 | self.assertTrue(cmd.skip_build) |
Fred Drake | bb7c144 | 2004-06-15 15:49:46 +0000 | [diff] [blame] | 36 | self.assertEqual(cmd.build_dir, "/foo/bar") |
| 37 | self.assertEqual(cmd.install_dir, "/splat/funk") |
| 38 | |
Fred Drake | d0620dc | 2004-06-15 16:55:46 +0000 | [diff] [blame] | 39 | def test_installation(self): |
| 40 | source = self.mkdtemp() |
| 41 | expected = [] |
| 42 | |
| 43 | def write_script(name, text): |
| 44 | expected.append(name) |
| 45 | f = open(os.path.join(source, name), "w") |
Éric Araujo | c6d7ead | 2010-11-06 02:58:56 +0000 | [diff] [blame] | 46 | try: |
| 47 | f.write(text) |
| 48 | finally: |
| 49 | f.close() |
Fred Drake | d0620dc | 2004-06-15 16:55:46 +0000 | [diff] [blame] | 50 | |
| 51 | write_script("script1.py", ("#! /usr/bin/env python2.3\n" |
| 52 | "# bogus script w/ Python sh-bang\n" |
| 53 | "pass\n")) |
| 54 | write_script("script2.py", ("#!/usr/bin/python\n" |
| 55 | "# bogus script w/ Python sh-bang\n" |
| 56 | "pass\n")) |
| 57 | write_script("shell.sh", ("#!/bin/sh\n" |
| 58 | "# bogus shell script w/ sh-bang\n" |
| 59 | "exit 0\n")) |
| 60 | |
| 61 | target = self.mkdtemp() |
| 62 | dist = Distribution() |
Fred Drake | b8ab8b6 | 2004-06-17 20:14:50 +0000 | [diff] [blame] | 63 | dist.command_obj["build"] = support.DummyCommand(build_scripts=source) |
| 64 | dist.command_obj["install"] = support.DummyCommand( |
Fred Drake | d0620dc | 2004-06-15 16:55:46 +0000 | [diff] [blame] | 65 | install_scripts=target, |
| 66 | force=1, |
| 67 | skip_build=1, |
| 68 | ) |
| 69 | cmd = install_scripts(dist) |
| 70 | cmd.finalize_options() |
| 71 | cmd.run() |
| 72 | |
| 73 | installed = os.listdir(target) |
| 74 | for name in expected: |
Georg Brandl | ab91fde | 2009-08-13 08:51:18 +0000 | [diff] [blame] | 75 | self.assertTrue(name in installed) |
Fred Drake | d0620dc | 2004-06-15 16:55:46 +0000 | [diff] [blame] | 76 | |
Fred Drake | bb7c144 | 2004-06-15 15:49:46 +0000 | [diff] [blame] | 77 | |
Fred Drake | bb7c144 | 2004-06-15 15:49:46 +0000 | [diff] [blame] | 78 | def test_suite(): |
| 79 | return unittest.makeSuite(InstallScriptsTestCase) |
Fred Drake | 2202157 | 2004-06-25 19:04:21 +0000 | [diff] [blame] | 80 | |
| 81 | if __name__ == "__main__": |
Éric Araujo | b344dd0 | 2011-02-02 21:38:37 +0000 | [diff] [blame^] | 82 | run_unittest(test_suite()) |