<s> import unittest <EOL> from test import test_support <EOL> import subprocess <EOL> import sys <EOL> import signal <EOL> import os <EOL> import tempfile <EOL> import time <EOL> import re <EOL> mswindows = ( sys . platform == "<STR_LIT:win32>" ) <EOL> def remove_stderr_debug_decorations ( stderr ) : <EOL> return re . sub ( r"<STR_LIT>" , "<STR_LIT>" , stderr ) <EOL> class ProcessTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> if hasattr ( test_support , "<STR_LIT>" ) : <EOL> test_support . reap_children ( ) <EOL> def tearDown ( self ) : <EOL> if hasattr ( test_support , "<STR_LIT>" ) : <EOL> test_support . reap_children ( ) <EOL> def mkstemp ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( tempfile , "<STR_LIT>" ) : <EOL> return tempfile . mkstemp ( ) <EOL> else : <EOL> fname = tempfile . mktemp ( ) <EOL> return os . open ( fname , os . O_RDWR | os . O_CREAT ) , fname <EOL> def test_call_seq ( self ) : <EOL> rc = subprocess . call ( [ sys . executable , "<STR_LIT:-c>" , <EOL> "<STR_LIT>" ] ) <EOL> self . assertEqual ( rc , <NUM_LIT> ) <EOL> def test_check_call_zero ( self ) : <EOL> rc = subprocess . check_call ( [ sys . executable , "<STR_LIT:-c>" , <EOL> "<STR_LIT>" ] ) <EOL> self . assertEqual ( rc , <NUM_LIT:0> ) <EOL> def test_check_call_nonzero ( self ) : <EOL> try : <EOL> subprocess . check_call ( [ sys . executable , "<STR_LIT:-c>" , <EOL> "<STR_LIT>" ] ) <EOL> except subprocess . CalledProcessError , e : <EOL> self . assertEqual ( e . returncode , <NUM_LIT> ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_call_kwargs ( self ) : <EOL> newenv = os . environ . copy ( ) <EOL> newenv [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> rc = subprocess . call ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' '<STR_LIT>' ] , <EOL> env = newenv ) <EOL> self . assertEqual ( rc , <NUM_LIT:1> ) <EOL> def test_stdin_none ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , '<STR_LIT>' ] , <EOL> stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> p . wait ( ) <EOL> self . assertEqual ( p . stdin , None ) <EOL> def test_stdout_none ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ] , <EOL> stdin = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> p . wait ( ) <EOL> self . assertEqual ( p . stdout , None ) <EOL> def test_stderr_none ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , '<STR_LIT>' ] , <EOL> stdin = subprocess . PIPE , stdout = subprocess . PIPE ) <EOL> p . wait ( ) <EOL> self . assertEqual ( p . stderr , None ) <EOL> def test_executable ( self ) : <EOL> p = subprocess . Popen ( [ "<STR_LIT>" , <EOL> "<STR_LIT:-c>" , "<STR_LIT>" ] , <EOL> executable = sys . executable ) <EOL> p . wait ( ) <EOL> self . assertEqual ( p . returncode , <NUM_LIT> ) <EOL> def test_stdin_pipe ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' ] , <EOL> stdin = subprocess . PIPE ) <EOL> p . stdin . write ( "<STR_LIT>" ) <EOL> p . stdin . close ( ) <EOL> p . wait ( ) <EOL> self . assertEqual ( p . returncode , <NUM_LIT:1> ) <EOL> def test_stdin_filedes ( self ) : <EOL> tf = tempfile . TemporaryFile ( ) <EOL> d = tf . fileno ( ) <EOL> os . write ( d , "<STR_LIT>" ) <EOL> os . lseek ( d , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' ] , <EOL> stdin = d ) <EOL> p . wait ( ) <EOL> self . assertEqual ( p . returncode , <NUM_LIT:1> ) <EOL> def test_stdin_fileobj ( self ) : <EOL> tf = tempfile . TemporaryFile ( ) <EOL> tf . write ( "<STR_LIT>" ) <EOL> tf . seek ( <NUM_LIT:0> ) <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' ] , <EOL> stdin = tf ) <EOL> p . wait ( ) <EOL> self . assertEqual ( p . returncode , <NUM_LIT:1> ) <EOL> def test_stdout_pipe ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' ] , <EOL> stdout = subprocess . PIPE ) <EOL> self . assertEqual ( p . stdout . read ( ) , "<STR_LIT>" ) <EOL> def test_stdout_filedes ( self ) : <EOL> tf = tempfile . TemporaryFile ( ) <EOL> d = tf . fileno ( ) <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' ] , <EOL> stdout = d ) <EOL> p . wait ( ) <EOL> os . lseek ( d , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . assertEqual ( os . read ( d , <NUM_LIT> ) , "<STR_LIT>" ) <EOL> def test_stdout_fileobj ( self ) : <EOL> tf = tempfile . TemporaryFile ( ) <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' ] , <EOL> stdout = tf ) <EOL> p . wait ( ) <EOL> tf . seek ( <NUM_LIT:0> ) <EOL> self . assertEqual ( tf . read ( ) , "<STR_LIT>" ) <EOL> def test_stderr_pipe ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' ] , <EOL> stderr = subprocess . PIPE ) <EOL> self . assertEqual ( remove_stderr_debug_decorations ( p . stderr . read ( ) ) , <EOL> "<STR_LIT>" ) <EOL> def test_stderr_filedes ( self ) : <EOL> tf = tempfile . TemporaryFile ( ) <EOL> d = tf . fileno ( ) <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' ] , <EOL> stderr = d ) <EOL> p . wait ( ) <EOL> os . lseek ( d , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . assertEqual ( remove_stderr_debug_decorations ( os . read ( d , <NUM_LIT> ) ) , <EOL> "<STR_LIT>" ) <EOL> def test_stderr_fileobj ( self ) : <EOL> tf = tempfile . TemporaryFile ( ) <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' ] , <EOL> stderr = tf ) <EOL> p . wait ( ) <EOL> tf . seek ( <NUM_LIT:0> ) <EOL> self . assertEqual ( remove_stderr_debug_decorations ( tf . read ( ) ) , <EOL> "<STR_LIT>" ) <EOL> def test_stdout_stderr_pipe ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' ] , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . STDOUT ) <EOL> output = p . stdout . read ( ) <EOL> stripped = remove_stderr_debug_decorations ( output ) <EOL> self . assertEqual ( stripped , "<STR_LIT>" ) <EOL> def test_stdout_stderr_file ( self ) : <EOL> tf = tempfile . TemporaryFile ( ) <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' ] , <EOL> stdout = tf , <EOL> stderr = tf ) <EOL> p . wait ( ) <EOL> tf . seek ( <NUM_LIT:0> ) <EOL> output = tf . read ( ) <EOL> stripped = remove_stderr_debug_decorations ( output ) <EOL> self . assertEqual ( stripped , "<STR_LIT>" ) <EOL> def test_stdout_filedes_of_stdout ( self ) : <EOL> cmd = r"<STR_LIT>" <EOL> rc = subprocess . call ( [ sys . executable , "<STR_LIT:-c>" , cmd ] , stdout = <NUM_LIT:1> ) <EOL> self . assertEquals ( rc , <NUM_LIT:2> ) <EOL> def test_cwd ( self ) : <EOL> tmpdir = os . getenv ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> cwd = os . getcwd ( ) <EOL> os . chdir ( tmpdir ) <EOL> tmpdir = os . getcwd ( ) <EOL> os . chdir ( cwd ) <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' '<STR_LIT>' ] , <EOL> stdout = subprocess . PIPE , <EOL> cwd = tmpdir ) <EOL> normcase = os . path . normcase <EOL> self . assertEqual ( normcase ( p . stdout . read ( ) ) , normcase ( tmpdir ) ) <EOL> def test_env ( self ) : <EOL> newenv = os . environ . copy ( ) <EOL> newenv [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' '<STR_LIT>' ] , <EOL> stdout = subprocess . PIPE , <EOL> env = newenv ) <EOL> self . assertEqual ( p . stdout . read ( ) , "<STR_LIT>" ) <EOL> def test_communicate_stdin ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' ] , <EOL> stdin = subprocess . PIPE ) <EOL> p . communicate ( "<STR_LIT>" ) <EOL> self . assertEqual ( p . returncode , <NUM_LIT:1> ) <EOL> def test_communicate_stdout ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' ] , <EOL> stdout = subprocess . PIPE ) <EOL> ( stdout , stderr ) = p . communicate ( ) <EOL> self . assertEqual ( stdout , "<STR_LIT>" ) <EOL> self . assertEqual ( stderr , None ) <EOL> def test_communicate_stderr ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' ] , <EOL> stderr = subprocess . PIPE ) <EOL> ( stdout , stderr ) = p . communicate ( ) <EOL> self . assertEqual ( stdout , None ) <EOL> self . assert_ ( stderr . startswith ( "<STR_LIT>" ) ) <EOL> def test_communicate ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' ] , <EOL> stdin = subprocess . PIPE , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE ) <EOL> ( stdout , stderr ) = p . communicate ( "<STR_LIT>" ) <EOL> self . assertEqual ( stdout , "<STR_LIT>" ) <EOL> self . assertEqual ( remove_stderr_debug_decorations ( stderr ) , <EOL> "<STR_LIT>" ) <EOL> def test_communicate_returns ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> "<STR_LIT>" ] ) <EOL> ( stdout , stderr ) = p . communicate ( ) <EOL> self . assertEqual ( stdout , None ) <EOL> self . assertEqual ( stderr , None ) <EOL> @ test_support . impl_detail ( "<STR_LIT>" ) <EOL> def test_communicate_pipe_buf ( self ) : <EOL> x , y = os . pipe ( ) <EOL> if mswindows : <EOL> pipe_buf = <NUM_LIT> <EOL> else : <EOL> pipe_buf = os . fpathconf ( x , "<STR_LIT>" ) <EOL> os . close ( x ) <EOL> os . close ( y ) <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' % pipe_buf ] , <EOL> stdin = subprocess . PIPE , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE ) <EOL> string_to_write = "<STR_LIT:abc>" * pipe_buf <EOL> ( stdout , stderr ) = p . communicate ( string_to_write ) <EOL> self . assertEqual ( stdout , string_to_write ) <EOL> def test_writes_before_communicate ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' '<STR_LIT>' ] , <EOL> stdin = subprocess . PIPE , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE ) <EOL> p . stdin . write ( "<STR_LIT>" ) <EOL> ( stdout , stderr ) = p . communicate ( "<STR_LIT>" ) <EOL> self . assertEqual ( stdout , "<STR_LIT>" ) <EOL> self . assertEqual ( remove_stderr_debug_decorations ( stderr ) , "<STR_LIT>" ) <EOL> def test_universal_newlines ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT>" , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ] , <EOL> stdout = subprocess . PIPE , <EOL> universal_newlines = <NUM_LIT:1> ) <EOL> stdout = p . stdout . read ( ) <EOL> if hasattr ( file , '<STR_LIT>' ) : <EOL> self . assertEqual ( stdout , <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . assertEqual ( stdout , <EOL> "<STR_LIT>" ) <EOL> def test_universal_newlines_communicate ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT>" , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ] , <EOL> stdout = subprocess . PIPE , stderr = subprocess . PIPE , <EOL> universal_newlines = <NUM_LIT:1> ) <EOL> ( stdout , stderr ) = p . communicate ( ) <EOL> if hasattr ( file , '<STR_LIT>' ) : <EOL> self . assertEqual ( stdout , <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . assertEqual ( stdout , "<STR_LIT>" ) <EOL> def test_no_leaking ( self ) : <EOL> if not hasattr ( test_support , "<STR_LIT>" ) or test_support . is_resource_enabled ( "<STR_LIT>" ) and not mswindows : <EOL> max_handles = <NUM_LIT> <EOL> else : <EOL> max_handles = <NUM_LIT> <EOL> for i in range ( max_handles ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> "<STR_LIT>" ] , <EOL> stdin = subprocess . PIPE , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE ) <EOL> data = p . communicate ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( data , "<STR_LIT>" ) <EOL> def test_list2cmdline ( self ) : <EOL> self . assertEqual ( subprocess . list2cmdline ( [ '<STR_LIT>' , '<STR_LIT:d>' , '<STR_LIT:e>' ] ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( subprocess . list2cmdline ( [ '<STR_LIT>' , '<STR_LIT:\\>' , '<STR_LIT:d>' ] ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( subprocess . list2cmdline ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:h>' ] ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( subprocess . list2cmdline ( [ '<STR_LIT>' , '<STR_LIT:c>' , '<STR_LIT:d>' ] ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( subprocess . list2cmdline ( [ '<STR_LIT>' , '<STR_LIT:d>' , '<STR_LIT:e>' ] ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( subprocess . list2cmdline ( [ '<STR_LIT>' , '<STR_LIT:d>' , '<STR_LIT:e>' ] ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( subprocess . list2cmdline ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' ) <EOL> def test_poll ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , <EOL> "<STR_LIT:-c>" , "<STR_LIT>" ] ) <EOL> count = <NUM_LIT:0> <EOL> while p . poll ( ) is None : <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> count += <NUM_LIT:1> <EOL> self . assert_ ( count >= <NUM_LIT:2> ) <EOL> self . assertEqual ( p . poll ( ) , <NUM_LIT:0> ) <EOL> def test_wait ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , <EOL> "<STR_LIT:-c>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( p . wait ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( p . wait ( ) , <NUM_LIT:0> ) <EOL> def test_invalid_bufsize ( self ) : <EOL> try : <EOL> subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> if not mswindows : <EOL> def test_exceptions ( self ) : <EOL> try : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , "<STR_LIT>" ] , <EOL> cwd = "<STR_LIT>" ) <EOL> except OSError , e : <EOL> self . assertNotEqual ( e . child_traceback . find ( "<STR_LIT>" ) , - <NUM_LIT:1> ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def _suppress_core_files ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> import resource <EOL> old_limit = resource . getrlimit ( resource . RLIMIT_CORE ) <EOL> resource . setrlimit ( resource . RLIMIT_CORE , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> return old_limit <EOL> except ( ImportError , ValueError , resource . error ) : <EOL> return None <EOL> def _unsuppress_core_files ( self , old_limit ) : <EOL> """<STR_LIT>""" <EOL> if old_limit is None : <EOL> return <EOL> try : <EOL> import resource <EOL> resource . setrlimit ( resource . RLIMIT_CORE , old_limit ) <EOL> except ( ImportError , ValueError , resource . error ) : <EOL> return <EOL> def test_run_abort ( self ) : <EOL> old_limit = self . _suppress_core_files ( ) <EOL> try : <EOL> p = subprocess . Popen ( [ sys . executable , <EOL> "<STR_LIT:-c>" , "<STR_LIT>" ] ) <EOL> finally : <EOL> self . _unsuppress_core_files ( old_limit ) <EOL> p . wait ( ) <EOL> self . assertEqual ( - p . returncode , signal . SIGABRT ) <EOL> def test_preexec ( self ) : <EOL> p = subprocess . Popen ( [ sys . executable , "<STR_LIT:-c>" , <EOL> '<STR_LIT>' '<STR_LIT>' ] , <EOL> stdout = subprocess . PIPE , <EOL> preexec_fn = lambda : os . putenv ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> self . assertEqual ( p . stdout . read ( ) , "<STR_LIT>" ) <EOL> def test_args_string ( self ) : <EOL> f , fname = self . mkstemp ( ) <EOL> os . write ( f , "<STR_LIT>" ) <EOL> os . write ( f , "<STR_LIT>" % <EOL> sys . executable ) <EOL> os . close ( f ) <EOL> os . chmod ( fname , <NUM_LIT:0> <NUM_LIT> ) <EOL> p = subprocess . Popen ( fname ) <EOL> p . wait ( ) <EOL> os . remove ( fname ) <EOL> self . assertEqual ( p . returncode , <NUM_LIT> ) <EOL> def test_invalid_args ( self ) : <EOL> self . assertRaises ( ValueError , subprocess . call , <EOL> [ sys . executable , <EOL> "<STR_LIT:-c>" , "<STR_LIT>" ] , <EOL> startupinfo = <NUM_LIT> ) <EOL> self . assertRaises ( ValueError , subprocess . call , <EOL> [ sys . executable , <EOL> "<STR_LIT:-c>" , "<STR_LIT>" ] , <EOL> creationflags = <NUM_LIT> ) <EOL> def test_shell_sequence ( self ) : <EOL> newenv = os . environ . copy ( ) <EOL> newenv [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> p = subprocess . Popen ( [ "<STR_LIT>" ] , shell = <NUM_LIT:1> , <EOL> stdout = subprocess . PIPE , <EOL> env = newenv ) <EOL> self . assertEqual ( p . stdout . read ( ) . strip ( ) , "<STR_LIT>" ) <EOL> def test_shell_string ( self ) : <EOL> newenv = os . environ . copy ( ) <EOL> newenv [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> p = subprocess . Popen ( "<STR_LIT>" , shell = <NUM_LIT:1> , <EOL> stdout = subprocess . PIPE , <EOL> env = newenv ) <EOL> self . assertEqual ( p . stdout . read ( ) . strip ( ) , "<STR_LIT>" ) <EOL> def test_call_string ( self ) : <EOL> f , fname = self . mkstemp ( ) <EOL> os . write ( f , "<STR_LIT>" ) <EOL> os . write ( f , "<STR_LIT>" % <EOL> sys . executable ) <EOL> os . close ( f ) <EOL> os . chmod ( fname , <NUM_LIT:0> <NUM_LIT> ) <EOL> rc = subprocess . call ( fname ) <EOL> os . remove ( fname ) <EOL> self . assertEqual ( rc , <NUM_LIT> ) <EOL> if mswindows : <EOL> def test_startupinfo ( self ) : <EOL> STARTF_USESHOWWINDOW = <NUM_LIT:1> <EOL> SW_MAXIMIZE = <NUM_LIT:3> <EOL> startupinfo = subprocess . STARTUPINFO ( ) <EOL> startupinfo . dwFlags = STARTF_USESHOWWINDOW <EOL> startupinfo . wShowWindow = SW_MAXIMIZE <EOL> subprocess . call ( [ sys . executable , "<STR_LIT:-c>" , "<STR_LIT>" ] , <EOL> startupinfo = startupinfo ) <EOL> def test_creationflags ( self ) : <EOL> CREATE_NEW_CONSOLE = <NUM_LIT:16> <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> subprocess . call ( sys . executable + <EOL> '<STR_LIT>' , <EOL> creationflags = CREATE_NEW_CONSOLE ) <EOL> def test_invalid_args ( self ) : <EOL> self . assertRaises ( ValueError , subprocess . call , <EOL> [ sys . executable , <EOL> "<STR_LIT:-c>" , "<STR_LIT>" ] , <EOL> preexec_fn = lambda : <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , subprocess . call , <EOL> [ sys . executable , <EOL> "<STR_LIT:-c>" , "<STR_LIT>" ] , <EOL> close_fds = True ) <EOL> def test_shell_sequence ( self ) : <EOL> newenv = os . environ . copy ( ) <EOL> newenv [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> p = subprocess . Popen ( [ "<STR_LIT>" ] , shell = <NUM_LIT:1> , <EOL> stdout = subprocess . PIPE , <EOL> env = newenv ) <EOL> self . assertNotEqual ( p . stdout . read ( ) . find ( "<STR_LIT>" ) , - <NUM_LIT:1> ) <EOL> def test_shell_string ( self ) : <EOL> newenv = os . environ . copy ( ) <EOL> newenv [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> p = subprocess . Popen ( "<STR_LIT>" , shell = <NUM_LIT:1> , <EOL> stdout = subprocess . PIPE , <EOL> env = newenv ) <EOL> self . assertNotEqual ( p . stdout . read ( ) . find ( "<STR_LIT>" ) , - <NUM_LIT:1> ) <EOL> def test_call_string ( self ) : <EOL> rc = subprocess . call ( sys . executable + <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( rc , <NUM_LIT> ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( ProcessTestCase ) <EOL> if hasattr ( test_support , "<STR_LIT>" ) : <EOL> test_support . reap_children ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
