annotate Lib/distutils/tests/test_build_scripts.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 5a0236f3f972
children
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
67850
b21786419bb8 Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66007
diff changeset
11 from 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", [])
87160
5a0236f3f972 Issue #19600: Use specific asserts in distutils tests.
Serhiy Storchaka <storchaka@gmail.com>
parents: 68257
diff changeset
20 self.assertFalse(cmd.force)
5a0236f3f972 Issue #19600: Use specific asserts in distutils tests.
Serhiy Storchaka <storchaka@gmail.com>
parents: 68257
diff changeset
21 self.assertIsNone(cmd.build_dir)
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:
87160
5a0236f3f972 Issue #19600: Use specific asserts in distutils tests.
Serhiy Storchaka <storchaka@gmail.com>
parents: 68257
diff changeset
41 self.assertIn(name, 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")
66007
f5dd4a54d79b Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 55593
diff changeset
75 try:
f5dd4a54d79b Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 55593
diff changeset
76 f.write(text)
f5dd4a54d79b Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 55593
diff changeset
77 finally:
f5dd4a54d79b Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 55593
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')
51619
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
97 sysconfig._config_vars['VERSION'] = 4
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:
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33295
diff changeset
102 sysconfig._config_vars['VERSION'] = old
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:
87160
5a0236f3f972 Issue #19600: Use specific asserts in distutils tests.
Serhiy Storchaka <storchaka@gmail.com>
parents: 68257
diff changeset
106 self.assertIn(name, 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__":
67850
b21786419bb8 Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66007
diff changeset
112 run_unittest(test_suite())