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

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

#countcontent
1n/a"""Tests for distutils.command.install_scripts."""
2n/a
3n/aimport os
4n/aimport unittest
5n/a
6n/afrom distutils.command.install_scripts import install_scripts
7n/afrom distutils.core import Distribution
8n/a
9n/afrom distutils.tests import support
10n/afrom test.support import run_unittest
11n/a
12n/a
13n/aclass InstallScriptsTestCase(support.TempdirManager,
14n/a support.LoggingSilencer,
15n/a unittest.TestCase):
16n/a
17n/a def test_default_settings(self):
18n/a dist = Distribution()
19n/a dist.command_obj["build"] = support.DummyCommand(
20n/a build_scripts="/foo/bar")
21n/a dist.command_obj["install"] = support.DummyCommand(
22n/a install_scripts="/splat/funk",
23n/a force=1,
24n/a skip_build=1,
25n/a )
26n/a cmd = install_scripts(dist)
27n/a self.assertFalse(cmd.force)
28n/a self.assertFalse(cmd.skip_build)
29n/a self.assertIsNone(cmd.build_dir)
30n/a self.assertIsNone(cmd.install_dir)
31n/a
32n/a cmd.finalize_options()
33n/a
34n/a self.assertTrue(cmd.force)
35n/a self.assertTrue(cmd.skip_build)
36n/a self.assertEqual(cmd.build_dir, "/foo/bar")
37n/a self.assertEqual(cmd.install_dir, "/splat/funk")
38n/a
39n/a def test_installation(self):
40n/a source = self.mkdtemp()
41n/a expected = []
42n/a
43n/a def write_script(name, text):
44n/a expected.append(name)
45n/a f = open(os.path.join(source, name), "w")
46n/a try:
47n/a f.write(text)
48n/a finally:
49n/a f.close()
50n/a
51n/a write_script("script1.py", ("#! /usr/bin/env python2.3\n"
52n/a "# bogus script w/ Python sh-bang\n"
53n/a "pass\n"))
54n/a write_script("script2.py", ("#!/usr/bin/python\n"
55n/a "# bogus script w/ Python sh-bang\n"
56n/a "pass\n"))
57n/a write_script("shell.sh", ("#!/bin/sh\n"
58n/a "# bogus shell script w/ sh-bang\n"
59n/a "exit 0\n"))
60n/a
61n/a target = self.mkdtemp()
62n/a dist = Distribution()
63n/a dist.command_obj["build"] = support.DummyCommand(build_scripts=source)
64n/a dist.command_obj["install"] = support.DummyCommand(
65n/a install_scripts=target,
66n/a force=1,
67n/a skip_build=1,
68n/a )
69n/a cmd = install_scripts(dist)
70n/a cmd.finalize_options()
71n/a cmd.run()
72n/a
73n/a installed = os.listdir(target)
74n/a for name in expected:
75n/a self.assertIn(name, installed)
76n/a
77n/a
78n/adef test_suite():
79n/a return unittest.makeSuite(InstallScriptsTestCase)
80n/a
81n/aif __name__ == "__main__":
82n/a run_unittest(test_suite())