mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
add a test that actually installs some scripts
This commit is contained in:
parent
bb7c14461d
commit
d0620dcf00
1 changed files with 56 additions and 0 deletions
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue