]> granicus.if.org Git - python/commitdiff
add a test that actually installs some scripts
authorFred Drake <fdrake@acm.org>
Tue, 15 Jun 2004 16:55:46 +0000 (16:55 +0000)
committerFred Drake <fdrake@acm.org>
Tue, 15 Jun 2004 16:55:46 +0000 (16:55 +0000)
Lib/distutils/tests/test_install_scripts.py

index f9a95ea504d3352a19837789965c91cac4b37cec..824f7336016318f0aaf0e685d3c4b2cecfc1b173 100644 (file)
@@ -1,6 +1,8 @@
 """Tests for distutils.command.install_scripts."""
 
 import os
+import shutil
+import tempfile
 import unittest
 
 from distutils.command.install_scripts import install_scripts
@@ -9,6 +11,23 @@ from distutils.core import Distribution
 
 class InstallScriptsTestCase(unittest.TestCase):
 
+    def setUp(self):
+        self.tempdirs = []
+
+    def tearDown(self):
+        while self.tempdirs:
+            d = self.tempdirs.pop()
+            shutil.rmtree(d)
+
+    def mkdtemp(self):
+        """Create a temporary directory that will be cleaned up.
+
+        Returns the path of the directory.
+        """
+        d = tempfile.mkdtemp()
+        self.tempdirs.append(d)
+        return d
+
     def test_default_settings(self):
         dist = Distribution()
         dist.command_obj["build"] = DummyCommand(build_scripts="/foo/bar")
@@ -30,8 +49,45 @@ class InstallScriptsTestCase(unittest.TestCase):
         self.assertEqual(cmd.build_dir, "/foo/bar")
         self.assertEqual(cmd.install_dir, "/splat/funk")
 
+    def test_installation(self):
+        source = self.mkdtemp()
+        expected = []
+
+        def write_script(name, text):
+            expected.append(name)
+            f = open(os.path.join(source, name), "w")
+            f.write(text)
+            f.close()
+
+        write_script("script1.py", ("#! /usr/bin/env python2.3\n"
+                                    "# bogus script w/ Python sh-bang\n"
+                                    "pass\n"))
+        write_script("script2.py", ("#!/usr/bin/python\n"
+                                    "# bogus script w/ Python sh-bang\n"
+                                    "pass\n"))
+        write_script("shell.sh", ("#!/bin/sh\n"
+                                  "# bogus shell script w/ sh-bang\n"
+                                  "exit 0\n"))
+
+        target = self.mkdtemp()
+        dist = Distribution()
+        dist.command_obj["build"] = DummyCommand(build_scripts=source)
+        dist.command_obj["install"] = DummyCommand(
+            install_scripts=target,
+            force=1,
+            skip_build=1,
+            )
+        cmd = install_scripts(dist)
+        cmd.finalize_options()
+        cmd.run()
+
+        installed = os.listdir(target)
+        for name in expected:
+            self.assert_(name in installed)
+
 
 class DummyCommand:
+    """Class to store options for retrieval via set_undefined_options()."""
 
     def __init__(self, **kwargs):
         for kw, val in kwargs.items():