annotate Lib/distutils/tests/test_install_scripts.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 9fb5138f58dd
children 0bb232078b8c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32353
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 """Tests for distutils.command.install_scripts."""
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
2
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
3 import os
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
4 import unittest
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
5
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
6 from distutils.command.install_scripts import install_scripts
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7 from distutils.core import Distribution
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8
32365
331e5d8b296f move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents: 32354
diff changeset
9 from distutils.tests import support
32354
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
10
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
11
32943
9fb5138f58dd make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents: 32403
diff changeset
12 class InstallScriptsTestCase(support.TempdirManager,
9fb5138f58dd make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents: 32403
diff changeset
13 support.LoggingSilencer,
9fb5138f58dd make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents: 32403
diff changeset
14 unittest.TestCase):
32354
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
15
32353
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
16 def test_default_settings(self):
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
17 dist = Distribution()
32365
331e5d8b296f move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents: 32354
diff changeset
18 dist.command_obj["build"] = support.DummyCommand(
331e5d8b296f move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents: 32354
diff changeset
19 build_scripts="/foo/bar")
331e5d8b296f move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents: 32354
diff changeset
20 dist.command_obj["install"] = support.DummyCommand(
32353
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
21 install_scripts="/splat/funk",
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
22 force=1,
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
23 skip_build=1,
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24 )
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25 cmd = install_scripts(dist)
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
26 self.assert_(not cmd.force)
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27 self.assert_(not cmd.skip_build)
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28 self.assert_(cmd.build_dir is None)
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
29 self.assert_(cmd.install_dir is None)
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
30
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
31 cmd.finalize_options()
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
32
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
33 self.assert_(cmd.force)
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
34 self.assert_(cmd.skip_build)
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
35 self.assertEqual(cmd.build_dir, "/foo/bar")
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
36 self.assertEqual(cmd.install_dir, "/splat/funk")
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
37
32354
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
38 def test_installation(self):
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
39 source = self.mkdtemp()
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
40 expected = []
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
41
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
42 def write_script(name, text):
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
43 expected.append(name)
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
44 f = open(os.path.join(source, name), "w")
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
45 f.write(text)
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
46 f.close()
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
47
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
48 write_script("script1.py", ("#! /usr/bin/env python2.3\n"
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
49 "# bogus script w/ Python sh-bang\n"
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
50 "pass\n"))
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
51 write_script("script2.py", ("#!/usr/bin/python\n"
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
52 "# bogus script w/ Python sh-bang\n"
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
53 "pass\n"))
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
54 write_script("shell.sh", ("#!/bin/sh\n"
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
55 "# bogus shell script w/ sh-bang\n"
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
56 "exit 0\n"))
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
57
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
58 target = self.mkdtemp()
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
59 dist = Distribution()
32365
331e5d8b296f move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents: 32354
diff changeset
60 dist.command_obj["build"] = support.DummyCommand(build_scripts=source)
331e5d8b296f move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents: 32354
diff changeset
61 dist.command_obj["install"] = support.DummyCommand(
32354
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
62 install_scripts=target,
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
63 force=1,
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
64 skip_build=1,
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
65 )
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
66 cmd = install_scripts(dist)
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
67 cmd.finalize_options()
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
68 cmd.run()
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
69
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
70 installed = os.listdir(target)
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
71 for name in expected:
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
72 self.assert_(name in installed)
581a8a128e11 add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents: 32353
diff changeset
73
32353
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
74
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
75 def test_suite():
40acb68ad224 One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
76 return unittest.makeSuite(InstallScriptsTestCase)
32403
8ccd8ec63cc2 add boilerplate so the test modules can be run as scripts
Fred Drake <fdrake@acm.org>
parents: 32365
diff changeset
77
8ccd8ec63cc2 add boilerplate so the test modules can be run as scripts
Fred Drake <fdrake@acm.org>
parents: 32365
diff changeset
78 if __name__ == "__main__":
8ccd8ec63cc2 add boilerplate so the test modules can be run as scripts
Fred Drake <fdrake@acm.org>
parents: 32365
diff changeset
79 unittest.main(defaultTest="test_suite")