annotate Lib/distutils/tests/test_build_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 1837e8e22927
children 0bb232078b8c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32394
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 """Tests for distutils.command.build_scripts."""
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
2
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
3 import os
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
4 import unittest
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
5
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
6 from distutils.command.build_scripts import build_scripts
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7 from distutils.core import Distribution
51619
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
8 from distutils import sysconfig
32394
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
9
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10 from distutils.tests import support
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12
32943
9fb5138f58dd make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents: 32403
diff changeset
13 class BuildScriptsTestCase(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
14 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
15 unittest.TestCase):
32394
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
16
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
17 def test_default_settings(self):
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
18 cmd = self.get_build_scripts_cmd("/foo/bar", [])
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
19 self.assert_(not cmd.force)
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
20 self.assert_(cmd.build_dir is None)
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
21
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
22 cmd.finalize_options()
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
23
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24 self.assert_(cmd.force)
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25 self.assertEqual(cmd.build_dir, "/foo/bar")
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
26
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27 def test_build(self):
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28 source = self.mkdtemp()
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
29 target = self.mkdtemp()
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
30 expected = self.write_sample_scripts(source)
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
31
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
32 cmd = self.get_build_scripts_cmd(target,
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
33 [os.path.join(source, fn)
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
34 for fn in expected])
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
35 cmd.finalize_options()
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
36 cmd.run()
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
37
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
38 built = os.listdir(target)
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
39 for name in expected:
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
40 self.assert_(name in built)
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
41
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42 def get_build_scripts_cmd(self, target, scripts):
33295
e07a6234b73b Add missing executable option to DummyCommand.
Martin v. Löwis <martin@v.loewis.de>
parents: 32943
diff changeset
43 import sys
32394
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
44 dist = Distribution()
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
45 dist.scripts = scripts
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46 dist.command_obj["build"] = support.DummyCommand(
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
47 build_scripts=target,
33295
e07a6234b73b Add missing executable option to DummyCommand.
Martin v. Löwis <martin@v.loewis.de>
parents: 32943
diff changeset
48 force=1,
e07a6234b73b Add missing executable option to DummyCommand.
Martin v. Löwis <martin@v.loewis.de>
parents: 32943
diff changeset
49 executable=sys.executable
32394
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
50 )
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
51 return build_scripts(dist)
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
52
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
53 def write_sample_scripts(self, dir):
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
54 expected = []
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
55 expected.append("script1.py")
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
56 self.write_script(dir, "script1.py",
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
57 ("#! /usr/bin/env python2.3\n"
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
58 "# bogus script w/ Python sh-bang\n"
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
59 "pass\n"))
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
60 expected.append("script2.py")
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
61 self.write_script(dir, "script2.py",
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
62 ("#!/usr/bin/python\n"
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
63 "# bogus script w/ Python sh-bang\n"
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
64 "pass\n"))
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
65 expected.append("shell.sh")
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
66 self.write_script(dir, "shell.sh",
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
67 ("#!/bin/sh\n"
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
68 "# bogus shell script w/ sh-bang\n"
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
69 "exit 0\n"))
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
70 return expected
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
71
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
72 def write_script(self, dir, name, text):
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
73 f = open(os.path.join(dir, name), "w")
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
74 f.write(text)
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
75 f.close()
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
76
51619
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
77 def test_version_int(self):
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
78 source = self.mkdtemp()
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
79 target = self.mkdtemp()
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
80 expected = self.write_sample_scripts(source)
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
81
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
82
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
83 cmd = self.get_build_scripts_cmd(target,
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
84 [os.path.join(source, fn)
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
85 for fn in expected])
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
86 cmd.finalize_options()
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
87
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
88 # http://bugs.python.org/issue4524
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
89 #
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
90 # On linux-g++-32 with command line `./configure --enable-ipv6
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
91 # --with-suffix=3`, python is compiled okay but the build scripts
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
92 # failed when writing the name of the executable
53394
1837e8e22927 Merged revisions 71886 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51619
diff changeset
93 old = sysconfig.get_config_vars().get('VERSION')
51619
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
94 sysconfig._config_vars['VERSION'] = 4
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
95 try:
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
96 cmd.run()
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
97 finally:
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
98 if old is not None:
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
99 sysconfig._config_vars['VERSION'] = old
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
100
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
101 built = os.listdir(target)
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
102 for name in expected:
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
103 self.assert_(name in built)
32394
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
104
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
105 def test_suite():
1d584ca56b30 add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff changeset
106 return unittest.makeSuite(BuildScriptsTestCase)
32403
8ccd8ec63cc2 add boilerplate so the test modules can be run as scripts
Fred Drake <fdrake@acm.org>
parents: 32394
diff changeset
107
8ccd8ec63cc2 add boilerplate so the test modules can be run as scripts
Fred Drake <fdrake@acm.org>
parents: 32394
diff changeset
108 if __name__ == "__main__":
8ccd8ec63cc2 add boilerplate so the test modules can be run as scripts
Fred Drake <fdrake@acm.org>
parents: 32394
diff changeset
109 unittest.main(defaultTest="test_suite")