a ‚oe‘3ã@s¬dZddlZddlZddlmZddlZddlmZddlmZ ddl m Z ddgZ gd ¢ZGd d „d ejƒZGd d „d ejƒZedkr¨e e ejdd…eg¡¡dS)z*Test :mod:`certbot._internal.display.obj`.éN)Úmock)Úerrors)Úobj)Úutil)ZFirstZ Description1)ZSecondZ Description2)Útag1Útag2Útag3cs>eZdZdZ‡fdd„Ze d¡dd„ƒZdd„Zd d „Z d d „Z d d„Z e d¡dd„ƒZ dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Ze d"¡d#d$„ƒZe d"¡d%d&„ƒZe d"¡d'd(„ƒZe d"¡d)d*„ƒZd+d,„Zd-d.„Ze d"¡d/d0„ƒZd1d2„Zd3d4„Zd5d6„Zd7d8„Zd9d:„Z d;d<„Z!‡Z"S)=ÚFileOutputDisplayTestz®Test stdout display. Most of this class has to deal with visual output. In order to test how the functions look to a user, uncomment the test_visual function. cs(tƒ ¡t ¡|_t |jd¡|_dS)NF)ÚsuperÚsetUprÚ MagicMockÚ mock_stdoutÚ display_objZ FileDisplayÚ displayer©Úself©Ú __class__©úIC:\Program Files\Certbot\pkgs\certbot\_internal\tests\display\obj_test.pyr s  zFileOutputDisplayTest.setUpú$certbot._internal.display.obj.loggercCs>|j dd¡|jjjdd}d|vs,J‚|j dd¡dS)NÚmessageFrúNotifying user: %s©rÚ notificationr ÚwriteÚ call_argsÚdebugZassert_called_with©rÚ mock_loggerÚstringrrrÚtest_notification_no_pauses z0FileOutputDisplayTest.test_notification_no_pausecCs`d}tj|dd�� |jjddd�Wdƒn1s80Yd|jjjddvs\J‚dS)Nú1certbot._internal.display.util.input_with_timeoutZenter©Ú return_valuerT©Úforce_interactiver)rÚpatchrrr rr©rÚinput_with_timeoutrrrÚtest_notification_pause$s.z-FileOutputDisplayTest.test_notification_pausecCs2| |jjd¡|jjjdd}d|vs.J‚dS)Nrr)Ú_force_noninteractiverrr rr©rr rrrÚ test_notification_noninteractive+sz6FileOutputDisplayTest.test_notification_noninteractivecCsl| |jjd¡|jjjdd}d|vs.J‚|jjs:J‚| |jjd¡|jjjdd}d|vshJ‚dS)NrrÚmessage2)r+rrr rrÚskipped_interactionr,rrrÚ!test_notification_noninteractive20s  z7FileOutputDisplayTest.test_notification_noninteractive2cCs†ddlm}|jjdddd�|jjjdd}|d|jksBJ‚|jjddd�|jjjdd}d|vspJ‚d|j|vs‚J‚dS© Nr)ÚosrF)ÚpauseZdecorater.)r3z- - - ©Zcertbot.compatr2rrr rrÚlinesep©rr2r rrrÚtest_notification_decoration=s  z2FileOutputDisplayTest.test_notification_decorationzd|_|jjdtdd�\}}|t|ƒftjddhfks:J‚dS)Nz2 1r?Tr%rr©r$rÚ checklistÚTAGSÚsetr9r:©rÚ mock_inputrGZtag_listrrrÚtest_checklist_valid‘s ÿ z*FileOutputDisplayTest.test_checklist_validcCs>d|_|jjdtdd�\}}|t|ƒftjhd£fks:J‚dS)NÚr?Tr%>rrrr`rdrrrÚtest_checklist_empty˜sz*FileOutputDisplayTest.test_checklist_emptycCs4gd¢|_|jjdtdd�}|tjdgfks0J‚dS)N)Ú10z tag1 pleaseÚ1r?Tr%r)rYrrarbr9r:©rrer=rrrÚtest_checklist_miss_validžs z/FileOutputDisplayTest.test_checklist_miss_validcCs2ddg|_|jjdtdd�}|tjgfks.J‚dS)NrirDr?Tr%)rYrrarbr9rFrkrrrÚtest_checklist_miss_quit¥s z.FileOutputDisplayTest.test_checklist_miss_quitcCs<t}|j|jjdt|d�\}}|tjks,J‚||ks8J‚dS)Nr?r@)rbr+rrar9r:rLrrrÚtest_checklist_noninteractive¬s  ÿ z3FileOutputDisplayTest.test_checklist_noninteractivecCs`dggd¢ddgg}dhddhddhg}t|ƒD]*\}}t|j |t¡ƒ}|||ks0J‚q0dS)Nrj)rjÚ2rjroÚ3rrr)Ú enumeratercrÚ_scrub_checklist_inputrb)rÚindicesZexpÚiÚlist_Zset_tagsrrrÚ test_scrub_checklist_input_valid´sýý ÿz6FileOutputDisplayTest.test_scrub_checklist_input_validcCs4gd¢}d}||_|jj|Ž}|tj|fks0J‚dS)N)r?ú /var/www/htmlrNTrw)r$rÚdirectory_selectr9r:)rreÚargsZ user_inputZreturnedrrrÚtest_directory_selectÅs  z+FileOutputDisplayTest.test_directory_selectcCs:d}|j|jjd|d�\}}|tjks*J‚||ks6J‚dS)Nrwr?r@)r+rrxr9r:rLrrrÚ$test_directory_select_noninteractiveÎs  ÿ z:FileOutputDisplayTest.test_directory_select_noninteractivec Osœ|jj}t d¡�P}d|j_t d¡�}||i|¤Ž}Wdƒn1sJ0YWdƒn1sh0Y|rˆ|jjdus˜J‚n|jjdks˜J‚|S)Nz'certbot._internal.display.obj.sys.stdinFrr8) rr/rr'Úisattyr$ZwarningZcalledZ call_count)rÚfuncryÚkwargsr/Z mock_stdinrrBrrrr+Ös  Jz+FileOutputDisplayTest._force_noninteractivecCs@dgdgdgddgddgg}|D]}|j |t¡gks J‚q dS)NÚ0Ú4rrjroÚo)rrrrb)rrsrurrrÚ"test_scrub_checklist_input_invalidåsûz8FileOutputDisplayTest.test_scrub_checklist_input_invalidcCs |j dt¡|j dt¡dS)Nr?)rZ _print_menur<rbrrrrÚtest_print_menuñsz%FileOutputDisplayTest.test_print_menucCs d}tj|dd��*|j d¡tjdfks.J‚Wdƒn1sB0Yd}tj||d��.|j d¡tjt|ƒfks~J‚Wdƒn1s’0YdS)Nr"rjr#r8roé)rr'rÚ_get_valid_int_ansr9r:Úint)rr)ÚansrrrÚtest_get_valid_int_ans_valid÷s8  ÿz2FileOutputDisplayTest.test_get_valid_int_ans_validc Csnddggd¢dgg}d}|D]L}tj||d��*|j d¡tjdfksJJ‚Wdƒq1s^0YqdS)NrrD)r€ZoneÚCr"rXr„éÿÿÿÿ)rr'rr…r9rF)rZanswersr)r‡rrrÚtest_get_valid_int_ans_invalidsý ÿz4FileOutputDisplayTest.test_get_valid_int_ans_invalid)#Ú__name__Ú __module__Ú __qualname__Ú__doc__r rr'r!r*r-r0r7r>rCrIrKrMrSrUr^r_rfrhrlrmrnrvrzr{r+r‚rƒrˆr‹Ú __classcell__rrrrr sH            r c@sZeZdZdZdd„Ze d¡dd„ƒZdd„Zd d „Z d d „Z d d„Z dd„Z dd„Z dS)ÚNoninteractiveDisplayTestz:Test non-interactive display. These tests are pretty easy!cCst ¡|_t |j¡|_dS)N)rr r rZNoninteractiveDisplayrrrrrr s zNoninteractiveDisplayTest.setUprcCs>|j dd¡|jjjdd}d|vs,J‚|j dd¡dS)Nré rrrrrrrr!s z4NoninteractiveDisplayTest.test_notification_no_pausecCs†ddlm}|jjdddd�|jjjdd}|d|jksBJ‚|jjddd�|jjjdd}d|vspJ‚d|j|vs‚J‚dSr1r4r6rrrr7s  z6NoninteractiveDisplayTest.test_notification_decorationcCsbd}|jjd|d�}|tj|fks&J‚t tj¡�|j d¡Wdƒn1sT0YdS)Nzan incomputable valuerr@)rrEr9r:rPrQrÚMissingCommandlineFlag©rÚdr=rrrÚ test_input(s z$NoninteractiveDisplayTest.test_inputcCsb|jjdtdd�}|tjdfks$J‚t tj¡�|j dt¡Wdƒn1sT0YdS)Nrr8r@) rr;r<r9r:rPrQrr“)rr=rrrr>/sz#NoninteractiveDisplayTest.test_menucCs\d}|jjd|d�}||ks J‚t tj¡�|j d¡Wdƒn1sN0YdS)NFrr@)rr]rPrQrr“r”rrrr^5s  z$NoninteractiveDisplayTest.test_yesnocCsjddg}|jjdt|d�}|tj|fks,J‚t tj¡�|j dt¡Wdƒn1s\0YdS)Nr8r„rr@) rrarbr9r:rPrQrr“r”rrrÚtest_checklist<s z(NoninteractiveDisplayTest.test_checklistcCsdd}tj|f}|j d|¡}||ks(J‚t tj¡�|j d¡Wdƒn1sV0YdS)Nrwr?)r9r:rrxrPrQrr“)rrAZexpectedÚactualrrrrzCs   z/NoninteractiveDisplayTest.test_directory_selectN)rŒr�rŽr�r rr'r!r7r–r>r^r—rzrrrrr‘s  r‘Ú__main__r8)r�ÚsysZunittestrrPZcertbotrZcertbot._internal.displayrrZcertbot.displayrr9r<rbZTestCaser r‘rŒÚexitÚmainÚargvÚ__file__rrrrÚs    >