annotate Lib/distutils/tests/test_install_scripts.py @ 65035:87f4b32905df 2.7

Cosmetic fix to use print function.
author Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
date Fri, 01 Oct 2010 10:48:47 +0000
parents 0bb232078b8c
children a17b21c27a33
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)
55593
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 32943
diff changeset
26 self.assertTrue(not cmd.force)
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 32943
diff changeset
27 self.assertTrue(not cmd.skip_build)
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 32943
diff changeset
28 self.assertTrue(cmd.build_dir is None)
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 32943
diff changeset
29 self.assertTrue(cmd.install_dir is None)
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
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
55593
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 32943
diff changeset
33 self.assertTrue(cmd.force)
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 32943
diff changeset
34 self.assertTrue(cmd.skip_build)
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
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:
55593
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 32943
diff changeset
72 self.assertTrue(name in installed)
32354
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")