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

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

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