Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/tests/test_build_scripts.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 6270946115d0 |
| children | 097389413dd3 |
| 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 |
|
58450
fa69e891edf4
taking sysconfig out of distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55593
diff
changeset
|
8 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 |
|
67854
6270946115d0
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
66008
diff
changeset
|
11 from test.test_support import run_unittest |
|
32394
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
12 |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
13 |
|
32943
9fb5138f58dd
make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents:
32403
diff
changeset
|
14 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
|
15 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
|
16 unittest.TestCase): |
|
32394
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
17 |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
18 def test_default_settings(self): |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
19 cmd = self.get_build_scripts_cmd("/foo/bar", []) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53394
diff
changeset
|
20 self.assertTrue(not cmd.force) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53394
diff
changeset
|
21 self.assertTrue(cmd.build_dir is None) |
|
32394
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
22 |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
23 cmd.finalize_options() |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
24 |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53394
diff
changeset
|
25 self.assertTrue(cmd.force) |
|
32394
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
26 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
|
27 |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
28 def test_build(self): |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
29 source = self.mkdtemp() |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
30 target = self.mkdtemp() |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
31 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
|
32 |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
33 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
|
34 [os.path.join(source, fn) |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
35 for fn in expected]) |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
36 cmd.finalize_options() |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
37 cmd.run() |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
38 |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
39 built = os.listdir(target) |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
40 for name in expected: |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53394
diff
changeset
|
41 self.assertTrue(name in built) |
|
32394
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
42 |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
43 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
|
44 import sys |
|
32394
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
45 dist = Distribution() |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
46 dist.scripts = scripts |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
47 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
|
48 build_scripts=target, |
|
33295
e07a6234b73b
Add missing executable option to DummyCommand.
Martin v. Löwis <martin@v.loewis.de>
parents:
32943
diff
changeset
|
49 force=1, |
|
e07a6234b73b
Add missing executable option to DummyCommand.
Martin v. Löwis <martin@v.loewis.de>
parents:
32943
diff
changeset
|
50 executable=sys.executable |
|
32394
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
51 ) |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
52 return build_scripts(dist) |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
53 |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
54 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
|
55 expected = [] |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
56 expected.append("script1.py") |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
57 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
|
58 ("#! /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
|
59 "# 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
|
60 "pass\n")) |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
61 expected.append("script2.py") |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
62 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
|
63 ("#!/usr/bin/python\n" |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
64 "# 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
|
65 "pass\n")) |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
66 expected.append("shell.sh") |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
67 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
|
68 ("#!/bin/sh\n" |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
69 "# 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
|
70 "exit 0\n")) |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
71 return expected |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
72 |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
73 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
|
74 f = open(os.path.join(dir, name), "w") |
|
66008
a17b21c27a33
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
58450
diff
changeset
|
75 try: |
|
a17b21c27a33
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
58450
diff
changeset
|
76 f.write(text) |
|
a17b21c27a33
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
58450
diff
changeset
|
77 finally: |
|
a17b21c27a33
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
58450
diff
changeset
|
78 f.close() |
|
32394
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
79 |
|
51619
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
80 def test_version_int(self): |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
81 source = self.mkdtemp() |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
82 target = self.mkdtemp() |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
83 expected = self.write_sample_scripts(source) |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
84 |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
85 |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
86 cmd = self.get_build_scripts_cmd(target, |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
87 [os.path.join(source, fn) |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
88 for fn in expected]) |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
89 cmd.finalize_options() |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
90 |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
91 # http://bugs.python.org/issue4524 |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
92 # |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
93 # 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
|
94 # --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
|
95 # 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
|
96 old = sysconfig.get_config_vars().get('VERSION') |
|
58450
fa69e891edf4
taking sysconfig out of distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55593
diff
changeset
|
97 sysconfig._CONFIG_VARS['VERSION'] = 4 |
|
51619
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
98 try: |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
99 cmd.run() |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
100 finally: |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
101 if old is not None: |
|
58450
fa69e891edf4
taking sysconfig out of distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55593
diff
changeset
|
102 sysconfig._CONFIG_VARS['VERSION'] = old |
|
51619
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
103 |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
104 built = os.listdir(target) |
|
616138eef224
Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
33295
diff
changeset
|
105 for name in expected: |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53394
diff
changeset
|
106 self.assertTrue(name in built) |
|
32394
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
107 |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
108 def test_suite(): |
|
1d584ca56b30
add a couple of tests for the build_scripts command
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
109 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
|
110 |
|
8ccd8ec63cc2
add boilerplate so the test modules can be run as scripts
Fred Drake <fdrake@acm.org>
parents:
32394
diff
changeset
|
111 if __name__ == "__main__": |
|
67854
6270946115d0
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
66008
diff
changeset
|
112 run_unittest(test_suite()) |
