3 § fã@sædZddlmZddlZddlmZedƒddlZddlm Z ddl m Z ddl m Z dd lmZd d „Zd d „ZGdd„dejƒZGdd„dejƒZGdd„dejƒZGdd„dejƒZGdd„dejƒZedkrâejdd�dS)aTest textview, coverage 100%. Since all methods and functions create (or destroy) a ViewWindow, which is a widget containing a widget, etcetera, all tests must be gui tests. Using mock Text would not change this. Other mocks are used to retrieve information about calls. é)ÚtextviewN)ÚrequiresZgui)ÚTk)ÚButton)ÚFunc)Ú Mbox_funccCstƒatjƒdS)N)rÚrootÚwithdraw©r r úD/opt/alt/python36/lib64/python3.6/idlelib/idle_test/test_textview.pyÚ setUpModulesr cCstjƒtjƒbdS)N)rÚupdate_idletasksÚdestroyr r r r ÚtearDownModulesrc@seZdZeƒZeƒZeƒZdS)ÚVWN)Ú__name__Ú __module__Ú __qualname__rÚ transientÚgrab_setÚ wait_windowr r r r r#src@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) ÚViewWindowTestcCs"tjjƒtjjƒtjjƒdS)N)rrÚ__init__rr)Úselfr r r ÚsetUp,s  zViewWindowTest.setUpcCsBttddƒ}|jtjjƒ|jtjjƒ|jtjjƒ|jƒdS)NÚTitlez test text)rrÚ assertTruerÚcalledrrÚok)rÚviewr r r Útest_init_modal1s  zViewWindowTest.test_init_modalcCsFttdddd�}|jtjjƒ|jtjjƒ|jtjjƒ|jƒdS)Nrz test textF)Úmodal)rrZ assertFalserrrrr)rrr r r Útest_init_nonmodal8s z!ViewWindowTest.test_init_nonmodalcCs>ttdddd�}tƒ|_|jƒ|j|jjƒ|`|jƒdS)Nrz test textF)r!)rrrrrrr)rrr r r Útest_ok?s zViewWindowTest.test_okN)rrrrr r"r#r r r r r*src@s,eZdZedd„ƒZedd„ƒZdd„ZdS)Ú TextFrameTestcCs&tƒ|_}|jƒtj|dƒ|_dS)Nz test text)rrr ÚtvZ TextFrameÚframe)Úclsrr r r Ú setUpClassJs zTextFrameTest.setUpClasscCs |`|jjƒ|jjƒ|`dS)N)r&rr r)r'r r r Ú tearDownClassPs  zTextFrameTest.tearDownClasscCs |jjj}|j|ddƒdƒdS)Nz1.0z1.endz test text)r&ÚtextÚgetÚ assertEqual)rr+r r r Ú test_line1Ws zTextFrameTest.test_line1N)rrrÚ classmethodr(r)r-r r r r r$Hs  r$c@sLeZdZedd„ƒZedd„ƒZdd„Zdd„Zd d „Zd d „Z d d„Z dS)ÚViewFunctionTestcCstj|_tƒt_dS)N)r%Ú showerrorÚ orig_errorr)r'r r r r(_szViewFunctionTest.setUpClasscCs|jt_|`dS)N)r1r%r0)r'r r r r)dszViewFunctionTest.tearDownClasscCs>tjtdddd�}|j|tjƒ|j|jtjƒ|jjƒdS)Nrz test textF)r!)r%Ú view_textrÚassertIsInstanceÚ ViewWindowÚ viewframeÚ ViewFramer)rrr r r Útest_view_textiszViewFunctionTest.test_view_textcCs\tjtdtddd�}|j|tjƒ|j|jtjƒ|jjj j }|j d|ddƒƒ|j ƒdS)NrÚasciiF)r!ZTestz1.0z1.end) r%Ú view_filerÚ__file__r3r4r5r6Ú textframer*r+ZassertInr)rrr+r r r Útest_view_fileos  zViewFunctionTest.test_view_filecCs2tjtddddd�}|j|ƒ|jtjjdƒdS)Nrzabc.xyzr8F)r!zFile Load Error)r%r9rÚ assertIsNoner,r0Útitle)rrr r r Ú test_bad_filews zViewFunctionTest.test_bad_filecCsRtj}|j|j|jtƒddƒƒ}tjtd|ddd�}|j |ƒ|j tj j dƒdS)Nz..z CREDITS.txtrr8F)r!zUnicode Decode Error) ÚosÚpathÚabspathÚjoinÚdirnamer:r%r9rr=r,r0r>)rÚpÚfnrr r r Útest_bad_encoding}s  z"ViewFunctionTest.test_bad_encodingcCs4tjtddddd�}|jjj}|j|jdƒdƒdS)NrZtestFZnone)r!ÚwraprH)r%r2rr5r;r*r,Zcget)rrZ text_widgetr r r Ú test_nowrap„s zViewFunctionTest.test_nowrapN) rrrr.r(r)r7r<r?rGrIr r r r r/]s  r/c@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) ÚButtonClickTestcCsd|_d|_dS)NF)rr)rr r r r�szButtonClickTest.setUpcCs|jr|jjƒdS)N)rr)rr r r ÚtearDown‘szButtonClickTest.tearDowncsn‡fdd„}ttd|d�}|jƒˆj|jƒˆjˆjdƒˆjˆjjƒdƒˆjˆjj j j j ddƒd ƒdS) Ncsdˆ_tjtdddd�ˆ_dS)NTÚ TITLE_TEXTÚCOMMAND)Ú_utest)rr%r2rrr )rr r Ú_command–szAButtonClickTest.test_view_text_bind_with_button.._commandÚBUTTON)r*ÚcommandTrLz1.0z1.endrM) rrÚinvokeÚ addCleanuprr,rrr>r5r;r*r+)rrOÚbuttonr )rr Útest_view_text_bind_with_button•s  z/ButtonClickTest.test_view_text_bind_with_buttonc s°‡fdd„}ttd|d�}|jƒˆj|jƒˆjˆjdƒˆjˆjjƒdƒˆjj j j j }t tƒ�B}ˆj|ddƒ|jƒjƒƒ|jƒˆj|d d ƒ|jƒjƒƒWdQRXdS) Ncs dˆ_tjtdtddd�ˆ_dS)NTÚ TITLE_FILEr8)ÚencodingrN)rr%r9rr:rr )rr r rO£s zAButtonClickTest.test_view_file_bind_with_button.._commandrP)r*rQTrVz1.0z1.endz3.0z3.end)rrrRrSrr,rrr>r5r;r*r+Úopenr:ÚreadlineÚstrip)rrOrTr+Úfr )rr Útest_view_file_bind_with_button¢s   z/ButtonClickTest.test_view_file_bind_with_buttonN)rrrrrKrUr\r r r r rJ‹s rJÚ__main__é)Ú verbosity)Ú__doc__Zidlelibrr%ZunittestZ test.supportrr@ZtkinterrZ tkinter.ttkrZidlelib.idle_test.mock_idlerZidlelib.idle_test.mock_tkrr rr4rZTestCaserr$r/rJrÚmainr r r r Ús$       .)