1 | n/a | """Tests for distutils.command.build_scripts.""" |
---|
2 | n/a | |
---|
3 | n/a | import os |
---|
4 | n/a | import unittest |
---|
5 | n/a | |
---|
6 | n/a | from distutils.command.build_scripts import build_scripts |
---|
7 | n/a | from distutils.core import Distribution |
---|
8 | n/a | from distutils import sysconfig |
---|
9 | n/a | |
---|
10 | n/a | from distutils.tests import support |
---|
11 | n/a | from test.support import run_unittest |
---|
12 | n/a | |
---|
13 | n/a | |
---|
14 | n/a | class BuildScriptsTestCase(support.TempdirManager, |
---|
15 | n/a | support.LoggingSilencer, |
---|
16 | n/a | unittest.TestCase): |
---|
17 | n/a | |
---|
18 | n/a | def test_default_settings(self): |
---|
19 | n/a | cmd = self.get_build_scripts_cmd("/foo/bar", []) |
---|
20 | n/a | self.assertFalse(cmd.force) |
---|
21 | n/a | self.assertIsNone(cmd.build_dir) |
---|
22 | n/a | |
---|
23 | n/a | cmd.finalize_options() |
---|
24 | n/a | |
---|
25 | n/a | self.assertTrue(cmd.force) |
---|
26 | n/a | self.assertEqual(cmd.build_dir, "/foo/bar") |
---|
27 | n/a | |
---|
28 | n/a | def test_build(self): |
---|
29 | n/a | source = self.mkdtemp() |
---|
30 | n/a | target = self.mkdtemp() |
---|
31 | n/a | expected = self.write_sample_scripts(source) |
---|
32 | n/a | |
---|
33 | n/a | cmd = self.get_build_scripts_cmd(target, |
---|
34 | n/a | [os.path.join(source, fn) |
---|
35 | n/a | for fn in expected]) |
---|
36 | n/a | cmd.finalize_options() |
---|
37 | n/a | cmd.run() |
---|
38 | n/a | |
---|
39 | n/a | built = os.listdir(target) |
---|
40 | n/a | for name in expected: |
---|
41 | n/a | self.assertIn(name, built) |
---|
42 | n/a | |
---|
43 | n/a | def get_build_scripts_cmd(self, target, scripts): |
---|
44 | n/a | import sys |
---|
45 | n/a | dist = Distribution() |
---|
46 | n/a | dist.scripts = scripts |
---|
47 | n/a | dist.command_obj["build"] = support.DummyCommand( |
---|
48 | n/a | build_scripts=target, |
---|
49 | n/a | force=1, |
---|
50 | n/a | executable=sys.executable |
---|
51 | n/a | ) |
---|
52 | n/a | return build_scripts(dist) |
---|
53 | n/a | |
---|
54 | n/a | def write_sample_scripts(self, dir): |
---|
55 | n/a | expected = [] |
---|
56 | n/a | expected.append("script1.py") |
---|
57 | n/a | self.write_script(dir, "script1.py", |
---|
58 | n/a | ("#! /usr/bin/env python2.3\n" |
---|
59 | n/a | "# bogus script w/ Python sh-bang\n" |
---|
60 | n/a | "pass\n")) |
---|
61 | n/a | expected.append("script2.py") |
---|
62 | n/a | self.write_script(dir, "script2.py", |
---|
63 | n/a | ("#!/usr/bin/python\n" |
---|
64 | n/a | "# bogus script w/ Python sh-bang\n" |
---|
65 | n/a | "pass\n")) |
---|
66 | n/a | expected.append("shell.sh") |
---|
67 | n/a | self.write_script(dir, "shell.sh", |
---|
68 | n/a | ("#!/bin/sh\n" |
---|
69 | n/a | "# bogus shell script w/ sh-bang\n" |
---|
70 | n/a | "exit 0\n")) |
---|
71 | n/a | return expected |
---|
72 | n/a | |
---|
73 | n/a | def write_script(self, dir, name, text): |
---|
74 | n/a | f = open(os.path.join(dir, name), "w") |
---|
75 | n/a | try: |
---|
76 | n/a | f.write(text) |
---|
77 | n/a | finally: |
---|
78 | n/a | f.close() |
---|
79 | n/a | |
---|
80 | n/a | def test_version_int(self): |
---|
81 | n/a | source = self.mkdtemp() |
---|
82 | n/a | target = self.mkdtemp() |
---|
83 | n/a | expected = self.write_sample_scripts(source) |
---|
84 | n/a | |
---|
85 | n/a | |
---|
86 | n/a | cmd = self.get_build_scripts_cmd(target, |
---|
87 | n/a | [os.path.join(source, fn) |
---|
88 | n/a | for fn in expected]) |
---|
89 | n/a | cmd.finalize_options() |
---|
90 | n/a | |
---|
91 | n/a | # http://bugs.python.org/issue4524 |
---|
92 | n/a | # |
---|
93 | n/a | # On linux-g++-32 with command line `./configure --enable-ipv6 |
---|
94 | n/a | # --with-suffix=3`, python is compiled okay but the build scripts |
---|
95 | n/a | # failed when writing the name of the executable |
---|
96 | n/a | old = sysconfig.get_config_vars().get('VERSION') |
---|
97 | n/a | sysconfig._config_vars['VERSION'] = 4 |
---|
98 | n/a | try: |
---|
99 | n/a | cmd.run() |
---|
100 | n/a | finally: |
---|
101 | n/a | if old is not None: |
---|
102 | n/a | sysconfig._config_vars['VERSION'] = old |
---|
103 | n/a | |
---|
104 | n/a | built = os.listdir(target) |
---|
105 | n/a | for name in expected: |
---|
106 | n/a | self.assertIn(name, built) |
---|
107 | n/a | |
---|
108 | n/a | def test_suite(): |
---|
109 | n/a | return unittest.makeSuite(BuildScriptsTestCase) |
---|
110 | n/a | |
---|
111 | n/a | if __name__ == "__main__": |
---|
112 | n/a | run_unittest(test_suite()) |
---|