Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0620dc

Browse files
committed
add a test that actually installs some scripts
1 parent bb7c144 commit d0620dc

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

Lib/distutils/tests/test_install_scripts.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Tests for distutils.command.install_scripts."""
22

33
import os
4+
import shutil
5+
import tempfile
46
import unittest
57

68
from distutils.command.install_scripts import install_scripts
@@ -9,6 +11,23 @@
911

1012
class InstallScriptsTestCase(unittest.TestCase):
1113

14+
def setUp(self):
15+
self.tempdirs = []
16+
17+
def tearDown(self):
18+
while self.tempdirs:
19+
d = self.tempdirs.pop()
20+
shutil.rmtree(d)
21+
22+
def mkdtemp(self):
23+
"""Create a temporary directory that will be cleaned up.
24+
25+
Returns the path of the directory.
26+
"""
27+
d = tempfile.mkdtemp()
28+
self.tempdirs.append(d)
29+
return d
30+
1231
def test_default_settings(self):
1332
dist = Distribution()
1433
dist.command_obj["build"] = DummyCommand(build_scripts="/foo/bar")
@@ -30,8 +49,45 @@ def test_default_settings(self):
3049
self.assertEqual(cmd.build_dir, "/foo/bar")
3150
self.assertEqual(cmd.install_dir, "/splat/funk")
3251

52+
def test_installation(self):
53+
source = self.mkdtemp()
54+
expected = []
55+
56+
def write_script(name, text):
57+
expected.append(name)
58+
f = open(os.path.join(source, name), "w")
59+
f.write(text)
60+
f.close()
61+
62+
write_script("script1.py", ("#! /usr/bin/env python2.3\n"
63+
"# bogus script w/ Python sh-bang\n"
64+
"pass\n"))
65+
write_script("script2.py", ("#!/usr/bin/python\n"
66+
"# bogus script w/ Python sh-bang\n"
67+
"pass\n"))
68+
write_script("shell.sh", ("#!/bin/sh\n"
69+
"# bogus shell script w/ sh-bang\n"
70+
"exit 0\n"))
71+
72+
target = self.mkdtemp()
73+
dist = Distribution()
74+
dist.command_obj["build"] = DummyCommand(build_scripts=source)
75+
dist.command_obj["install"] = DummyCommand(
76+
install_scripts=target,
77+
force=1,
78+
skip_build=1,
79+
)
80+
cmd = install_scripts(dist)
81+
cmd.finalize_options()
82+
cmd.run()
83+
84+
installed = os.listdir(target)
85+
for name in expected:
86+
self.assert_(name in installed)
87+
3388

3489
class DummyCommand:
90+
"""Class to store options for retrieval via set_undefined_options()."""
3591

3692
def __init__(self, **kwargs):
3793
for kw, val in kwargs.items():

0 commit comments

Comments
 (0)