]>
Commit | Line | Data |
---|---|---|
4710c53d | 1 | """Tests for distutils.spawn."""\r |
2 | import unittest\r | |
3 | import os\r | |
4 | import time\r | |
5 | from test.test_support import captured_stdout, run_unittest\r | |
6 | \r | |
7 | from distutils.spawn import _nt_quote_args\r | |
8 | from distutils.spawn import spawn, find_executable\r | |
9 | from distutils.errors import DistutilsExecError\r | |
10 | from distutils.tests import support\r | |
11 | \r | |
12 | class SpawnTestCase(support.TempdirManager,\r | |
13 | support.LoggingSilencer,\r | |
14 | unittest.TestCase):\r | |
15 | \r | |
16 | def test_nt_quote_args(self):\r | |
17 | \r | |
18 | for (args, wanted) in ((['with space', 'nospace'],\r | |
19 | ['"with space"', 'nospace']),\r | |
20 | (['nochange', 'nospace'],\r | |
21 | ['nochange', 'nospace'])):\r | |
22 | res = _nt_quote_args(args)\r | |
23 | self.assertEqual(res, wanted)\r | |
24 | \r | |
25 | \r | |
26 | @unittest.skipUnless(os.name in ('nt', 'posix'),\r | |
27 | 'Runs only under posix or nt')\r | |
28 | def test_spawn(self):\r | |
29 | tmpdir = self.mkdtemp()\r | |
30 | \r | |
31 | # creating something executable\r | |
32 | # through the shell that returns 1\r | |
33 | if os.name == 'posix':\r | |
34 | exe = os.path.join(tmpdir, 'foo.sh')\r | |
35 | self.write_file(exe, '#!/bin/sh\nexit 1')\r | |
36 | os.chmod(exe, 0777)\r | |
37 | else:\r | |
38 | exe = os.path.join(tmpdir, 'foo.bat')\r | |
39 | self.write_file(exe, 'exit 1')\r | |
40 | \r | |
41 | os.chmod(exe, 0777)\r | |
42 | self.assertRaises(DistutilsExecError, spawn, [exe])\r | |
43 | \r | |
44 | # now something that works\r | |
45 | if os.name == 'posix':\r | |
46 | exe = os.path.join(tmpdir, 'foo.sh')\r | |
47 | self.write_file(exe, '#!/bin/sh\nexit 0')\r | |
48 | os.chmod(exe, 0777)\r | |
49 | else:\r | |
50 | exe = os.path.join(tmpdir, 'foo.bat')\r | |
51 | self.write_file(exe, 'exit 0')\r | |
52 | \r | |
53 | os.chmod(exe, 0777)\r | |
54 | spawn([exe]) # should work without any error\r | |
55 | \r | |
56 | def test_suite():\r | |
57 | return unittest.makeSuite(SpawnTestCase)\r | |
58 | \r | |
59 | if __name__ == "__main__":\r | |
60 | run_unittest(test_suite())\r |