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