NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

test_spawn.py (1695B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\stdlib\distutils\tests\test_spawn.py
      2 import unittest
      3 import os
      4 import time
      5 from test.test_support import captured_stdout
      6 from distutils.spawn import _nt_quote_args
      7 from distutils.spawn import spawn, find_executable
      8 from distutils.errors import DistutilsExecError
      9 from distutils.tests import support
     10 
     11 class SpawnTestCase(support.TempdirManager, support.LoggingSilencer, unittest.TestCase):
     12 
     13     def test_nt_quote_args(self):
     14         for args, wanted in ((['with space', 'nospace'], ['"with space"', 'nospace']), (['nochange', 'nospace'], ['nochange', 'nospace'])):
     15             res = _nt_quote_args(args)
     16             self.assertEqual(res, wanted)
     17 
     18     @unittest.skipUnless(os.name in ('nt', 'posix'), 'Runs only under posix or nt')
     19     def test_spawn(self):
     20         tmpdir = self.mkdtemp()
     21         if os.name == 'posix':
     22             exe = os.path.join(tmpdir, 'foo.sh')
     23             self.write_file(exe, '#!/bin/sh\nexit 1')
     24             os.chmod(exe, 511)
     25         else:
     26             exe = os.path.join(tmpdir, 'foo.bat')
     27             self.write_file(exe, 'exit 1')
     28         os.chmod(exe, 511)
     29         self.assertRaises(DistutilsExecError, spawn, [exe])
     30         if os.name == 'posix':
     31             exe = os.path.join(tmpdir, 'foo.sh')
     32             self.write_file(exe, '#!/bin/sh\nexit 0')
     33             os.chmod(exe, 511)
     34         else:
     35             exe = os.path.join(tmpdir, 'foo.bat')
     36             self.write_file(exe, 'exit 0')
     37         os.chmod(exe, 511)
     38         spawn([exe])
     39 
     40 
     41 def test_suite():
     42     return unittest.makeSuite(SpawnTestCase)
     43 
     44 
     45 if __name__ == '__main__':
     46     unittest.main(defaultTest='test_suite')