PyXR

c:\python24\lib \ distutils \ tests \ test_install_scripts.py



0001 """Tests for distutils.command.install_scripts."""
0002 
0003 import os
0004 import unittest
0005 
0006 from distutils.command.install_scripts import install_scripts
0007 from distutils.core import Distribution
0008 
0009 from distutils.tests import support
0010 
0011 
0012 class InstallScriptsTestCase(support.TempdirManager,
0013                              support.LoggingSilencer,
0014                              unittest.TestCase):
0015 
0016     def test_default_settings(self):
0017         dist = Distribution()
0018         dist.command_obj["build"] = support.DummyCommand(
0019             build_scripts="/foo/bar")
0020         dist.command_obj["install"] = support.DummyCommand(
0021             install_scripts="/splat/funk",
0022             force=1,
0023             skip_build=1,
0024             )
0025         cmd = install_scripts(dist)
0026         self.assert_(not cmd.force)
0027         self.assert_(not cmd.skip_build)
0028         self.assert_(cmd.build_dir is None)
0029         self.assert_(cmd.install_dir is None)
0030 
0031         cmd.finalize_options()
0032 
0033         self.assert_(cmd.force)
0034         self.assert_(cmd.skip_build)
0035         self.assertEqual(cmd.build_dir, "/foo/bar")
0036         self.assertEqual(cmd.install_dir, "/splat/funk")
0037 
0038     def test_installation(self):
0039         source = self.mkdtemp()
0040         expected = []
0041 
0042         def write_script(name, text):
0043             expected.append(name)
0044             f = open(os.path.join(source, name), "w")
0045             f.write(text)
0046             f.close()
0047 
0048         write_script("script1.py", ("#! /usr/bin/env python2.3\n"
0049                                     "# bogus script w/ Python sh-bang\n"
0050                                     "pass\n"))
0051         write_script("script2.py", ("#!/usr/bin/python\n"
0052                                     "# bogus script w/ Python sh-bang\n"
0053                                     "pass\n"))
0054         write_script("shell.sh", ("#!/bin/sh\n"
0055                                   "# bogus shell script w/ sh-bang\n"
0056                                   "exit 0\n"))
0057 
0058         target = self.mkdtemp()
0059         dist = Distribution()
0060         dist.command_obj["build"] = support.DummyCommand(build_scripts=source)
0061         dist.command_obj["install"] = support.DummyCommand(
0062             install_scripts=target,
0063             force=1,
0064             skip_build=1,
0065             )
0066         cmd = install_scripts(dist)
0067         cmd.finalize_options()
0068         cmd.run()
0069 
0070         installed = os.listdir(target)
0071         for name in expected:
0072             self.assert_(name in installed)
0073 
0074 
0075 def test_suite():
0076     return unittest.makeSuite(InstallScriptsTestCase)
0077 
0078 if __name__ == "__main__":
0079     unittest.main(defaultTest="test_suite")
0080 

Generated by PyXR 0.9.4
SourceForge.net Logo