Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/tests/test_install_scripts.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | 6270946115d0 |
| children | 097389413dd3 |
| 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 |
|
67854
6270946115d0
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
66008
diff
changeset
|
10 from test.test_support import run_unittest |
|
32354
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
11 |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
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 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
|
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): |
|
32354
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
16 |
|
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
|
17 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
|
18 dist = Distribution() |
|
32365
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
32354
diff
changeset
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 ) |
|
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 cmd = install_scripts(dist) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
32943
diff
changeset
|
27 self.assertTrue(not cmd.force) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
32943
diff
changeset
|
28 self.assertTrue(not cmd.skip_build) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
32943
diff
changeset
|
29 self.assertTrue(cmd.build_dir is None) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
32943
diff
changeset
|
30 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
|
31 |
|
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 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
|
33 |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
32943
diff
changeset
|
34 self.assertTrue(cmd.force) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
32943
diff
changeset
|
35 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
|
36 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
|
37 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
|
38 |
|
32354
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
39 def test_installation(self): |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
40 source = self.mkdtemp() |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
41 expected = [] |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
42 |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
43 def write_script(name, text): |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
44 expected.append(name) |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
45 f = open(os.path.join(source, name), "w") |
|
66008
a17b21c27a33
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
55593
diff
changeset
|
46 try: |
|
a17b21c27a33
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
55593
diff
changeset
|
47 f.write(text) |
|
a17b21c27a33
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
55593
diff
changeset
|
48 finally: |
|
a17b21c27a33
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
55593
diff
changeset
|
49 f.close() |
|
32354
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
50 |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
51 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
|
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("script2.py", ("#!/usr/bin/python\n" |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
55 "# 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
|
56 "pass\n")) |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
57 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
|
58 "# 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
|
59 "exit 0\n")) |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
60 |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
61 target = self.mkdtemp() |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
62 dist = Distribution() |
|
32365
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
32354
diff
changeset
|
63 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
|
64 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
|
65 install_scripts=target, |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
66 force=1, |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
67 skip_build=1, |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
68 ) |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
69 cmd = install_scripts(dist) |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
70 cmd.finalize_options() |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
71 cmd.run() |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
72 |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
73 installed = os.listdir(target) |
|
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
74 for name in expected: |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
32943
diff
changeset
|
75 self.assertTrue(name in installed) |
|
32354
581a8a128e11
add a test that actually installs some scripts
Fred Drake <fdrake@acm.org>
parents:
32353
diff
changeset
|
76 |
|
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
|
77 |
|
40acb68ad224
One unit test for distutils is not much, but is more than we had yesterday.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
78 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
|
79 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
|
80 |
|
8ccd8ec63cc2
add boilerplate so the test modules can be run as scripts
Fred Drake <fdrake@acm.org>
parents:
32365
diff
changeset
|
81 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
|
82 run_unittest(test_suite()) |
