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 from test.test_support import run_unittest 11 12 13 class InstallScriptsTestCase(support.TempdirManager, 14 support.LoggingSilencer, 15 unittest.TestCase): 16 17 def test_default_settings(self): 18 dist = Distribution() 19 dist.command_obj["build"] = support.DummyCommand( 20 build_scripts="/foo/bar") 21 dist.command_obj["install"] = support.DummyCommand( 22 install_scripts="/splat/funk", 23 force=1, 24 skip_build=1, 25 ) 26 cmd = install_scripts(dist) 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) 31 32 cmd.finalize_options() 33 34 self.assertTrue(cmd.force) 35 self.assertTrue(cmd.skip_build) 36 self.assertEqual(cmd.build_dir, "/foo/bar") 37 self.assertEqual(cmd.install_dir, "/splat/funk") 38 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") 46 try: 47 f.write(text) 48 finally: 49 f.close() 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() 63 dist.command_obj["build"] = support.DummyCommand(build_scripts=source) 64 dist.command_obj["install"] = support.DummyCommand( 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: 75 self.assertTrue(name in installed) 76 77 78 def test_suite(): 79 return unittest.makeSuite(InstallScriptsTestCase) 80 81 if __name__ == "__main__": 82 run_unittest(test_suite()) 83