ó {G_Tc@sddlmZmZmZedƒZedƒddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z dZ dZer°d„Zn d„Zd „Zd e jfd „ƒYZd e jfd „ƒYZdd„ZedkreƒndS(iÿÿÿÿ(tverboset run_unittestt import_moduletfcntlttermiosNsI wish to buy a fish license. sFor my pet fish, Eric. cCs |GHdS(N((tmsg((s)/usr/local/lib/python2.7/test/test_pty.pytdebugscCsdS(N((R((s)/usr/local/lib/python2.7/test/test_pty.pyRscCsB|jdƒr|jddƒS|jdƒr>|jddƒS|S(Ns s s (tendswithtreplace(tdata((s)/usr/local/lib/python2.7/test/test_pty.pytnormalize_outputs tPtyTestcBs5eZd„Zd„Zd„Zd„Zd„ZRS(cCs,tjtj|jƒ|_tjdƒdS(Ni (tsignaltSIGALRMt handle_sigt old_alarmtalarm(tself((s)/usr/local/lib/python2.7/test/test_pty.pytsetUp5scCs'tjdƒtjtj|jƒdS(Ni(R RR R(R((s)/usr/local/lib/python2.7/test/test_pty.pyttearDown;s cCs|jdƒdS(Ns isatty hung(tfail(Rtsigtframe((s)/usr/local/lib/python2.7/test/test_pty.pyR@scCsñybtdƒtjƒ\}}td||fƒtd|fƒtj|ƒ}td|ƒWntk rtjd‚nX|jtj |ƒdƒt j |t j ƒ}t j |t j |tj Bƒy&tj|dƒ}|jd|ƒWn+tk r }|jtjkr!‚q!nXt j |t j |ƒtd ƒtj|tƒtj|dƒ}|jd t|ƒƒtd ƒtj|td ƒtj|td ƒtj|dƒ}|jd t|ƒƒtj|ƒtj|ƒdS(NsCalling master_open()s#Got master_fd '%d', slave_name '%s'sCalling slave_open(%r)sGot slave_fd '%d's,Pseudo-terminals (seemingly) not functional.sslave_fd is not a ttyitsWriting to slave_fdsI wish to buy a fish license. sWriting chunked outputisFor my pet fish, Eric. (Rtptyt master_opent slave_opentOSErrortunittesttSkipTestt assertTruetostisattyRtF_GETFLtF_SETFLt O_NONBLOCKtreadt assertEqualterrnotEAGAINtwritet TEST_STRING_1R t TEST_STRING_2tclose(Rt master_fdt slave_nametslave_fdt orig_flagsts1tets2((s)/usr/local/lib/python2.7/test/test_pty.pyt test_basicCs@        cCstdƒtjƒ\}}|tjkrètjdƒsTtdƒtjdƒntdƒytjƒWnRtk r‰tdƒnOt k r£tdƒn5tdƒtjdƒnXtd ƒtjd ƒtjd ƒntd |ƒx[t rSytj |d ƒ}Wntk r)PnX|s4Pnt j j|jddƒƒqùWtj|dƒ\}}|d?}td|||fƒ|dkr©|jdƒnT|d krÅ|jdƒn8|dkrá|jdƒn|d krý|jdƒntj|ƒdS(Nscalling pty.fork()isChild's fd 1 is not a tty?!isIn child, calling os.setsid()sGood: OSError was raised.sNo setsid() available?sAn unexpected error was raised.sos.setsid() succeeded! (bad!)iis!Waiting for child (%d) to finish.iPs s iis&Child (%d) exited with status %d (%d).s3Child raised an unexpected exception in os.setsid()s1pty.fork() failed to make child a session leader.s8Child spawned by pty.fork() did not have a tty as stdouts&pty.fork() failed for unknown reasons.(RRtforktCHILDRR t_exittsetsidRtAttributeErrortTrueR$tsyststdoutR(RtwaitpidRR+(RtpidR,R tstatustres((s)/usr/local/lib/python2.7/test/test_pty.pyt test_forkrsT                   (t__name__t __module__RRRR3R@(((s)/usr/local/lib/python2.7/test/test_pty.pyR 4s     /t SmallPtyTestscBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(s)These tests don't spawn children or hang.cCsCtj|_tj|_tj|_g|_g|_g|_ dS(N( Rt STDIN_FILENOtorig_stdin_filenot STDOUT_FILENOtorig_stdout_filenotselecttorig_pty_selecttfdstselect_rfds_lengthstselect_rfds_results(R((s)/usr/local/lib/python2.7/test/test_pty.pyRÊs      cCsW|jt_|jt_|jt_x,|jD]!}ytj |ƒWq.q.Xq.WdS(N( RERRDRGRFRIRHRJRR+(Rtfd((s)/usr/local/lib/python2.7/test/test_pty.pyRÒs   cCs tjƒ}|jj|ƒ|S(N(RtpipeRJtextend(Rtpipe_fds((s)/usr/local/lib/python2.7/test/test_pty.pyt_pipeÜs cCs;|j|jjdƒt|ƒƒ|jjdƒggfS(Ni(R%RKtpoptlenRL(Rtrfdstwfdstxfds((s)/usr/local/lib/python2.7/test/test_pty.pyt _mock_selectás"c Cs‚|jƒ\}}|t_|jƒ\}}|t_tjƒ}g|D]}|jƒ^qI}|jj|ƒt j |ddƒt j |dƒ|j t_ |j jdƒ|jj||dgƒ|j jdƒ|jtƒtj|dƒWdQXt j ||dgggdƒd}|j||dg|ƒ|jt j|dƒdƒ|jt j|ddƒdƒdS(s6Test the normal data case on both master_fd and stdin.is from masters from stdiniiNi(RQRRFRDtsockett socketpairtfilenoRJRORR(RWRHRKtappendRLt assertRaisest IndexErrort_copyR%R$( Rtread_from_stdout_fdtmock_stdout_fdt mock_stdin_fdtwrite_to_stdin_fdRYtstmastersRT((s)/usr/local/lib/python2.7/test/test_pty.pyttest__copy_to_eachæs&    &cCs|jƒ\}}|t_|jƒ\}}|t_tjƒ}g|D]}|jƒ^qI}|jj|ƒt j |dƒ|dj ƒt j |ƒ|j t_ |j jdƒ|jj||dgƒ|j jdƒ|jtƒtj|dƒWdQXdS(s9Test the empty read EOF case on both master_fd and stdin.iiiN(RQRRFRDRXRYRZRJRORR+RWRHRKR[RLR\R]R^(RR_R`RaRbRYRcRd((s)/usr/local/lib/python2.7/test/test_pty.pyttest__copy_eof_on_alls      ( RARBt__doc__RRRQRWReRf(((s)/usr/local/lib/python2.7/test/test_pty.pyRCÇs    cCstttƒdS(N(RRCR (R((s)/usr/local/lib/python2.7/test/test_pty.pyt test_mainst__main__(ttest.test_supportRRRRR&RRR:RHR RXRR)R*RR tTestCaseR RCtNoneRhRA(((s)/usr/local/lib/python2.7/test/test_pty.pyts*             “V