ยปCore Development>Code coverage>Lib/distutils/tests/test_build_scripts.py

Python code coverage for Lib/distutils/tests/test_build_scripts.py

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