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