<s> """<STR_LIT>""" <EOL> import os <EOL> import unittest <EOL> import mock <EOL> import certbot . errors as errors <EOL> from certbot . display import util as display_util <EOL> CHOICES = [ ( "<STR_LIT>" , "<STR_LIT>" ) , ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> TAGS = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> TAGS_CHOICES = [ ( "<STR_LIT:1>" , "<STR_LIT>" ) , ( "<STR_LIT:2>" , "<STR_LIT>" ) , ( "<STR_LIT:3>" , "<STR_LIT>" ) ] <EOL> class NcursesDisplayTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( NcursesDisplayTest , self ) . setUp ( ) <EOL> self . displayer = display_util . NcursesDisplay ( ) <EOL> self . default_menu_options = { <EOL> "<STR_LIT>" : CHOICES , <EOL> "<STR_LIT>" : "<STR_LIT:OK>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:width>" : display_util . WIDTH , <EOL> "<STR_LIT>" : display_util . HEIGHT , <EOL> "<STR_LIT>" : display_util . HEIGHT - <NUM_LIT:6> , <EOL> } <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_notification ( self , mock_msgbox ) : <EOL> """<STR_LIT>""" <EOL> self . displayer . notification ( "<STR_LIT:message>" ) <EOL> self . assertEqual ( mock_msgbox . call_count , <NUM_LIT:1> ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_menu_tag_and_desc ( self , mock_menu ) : <EOL> mock_menu . return_value = ( display_util . OK , "<STR_LIT>" ) <EOL> ret = self . displayer . menu ( "<STR_LIT>" , CHOICES ) <EOL> mock_menu . assert_called_with ( "<STR_LIT>" , ** self . default_menu_options ) <EOL> self . assertEqual ( ret , ( display_util . OK , <NUM_LIT:0> ) ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_menu_tag_and_desc_cancel ( self , mock_menu ) : <EOL> mock_menu . return_value = ( display_util . CANCEL , "<STR_LIT>" ) <EOL> ret = self . displayer . menu ( "<STR_LIT>" , CHOICES ) <EOL> mock_menu . assert_called_with ( "<STR_LIT>" , ** self . default_menu_options ) <EOL> self . assertEqual ( ret , ( display_util . CANCEL , - <NUM_LIT:1> ) ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_menu_desc_only ( self , mock_menu ) : <EOL> mock_menu . return_value = ( display_util . OK , "<STR_LIT:1>" ) <EOL> ret = self . displayer . menu ( "<STR_LIT>" , TAGS , help_label = "<STR_LIT>" ) <EOL> self . default_menu_options . update ( <EOL> choices = TAGS_CHOICES , help_button = True , help_label = "<STR_LIT>" ) <EOL> mock_menu . assert_called_with ( "<STR_LIT>" , ** self . default_menu_options ) <EOL> self . assertEqual ( ret , ( display_util . OK , <NUM_LIT:0> ) ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_menu_desc_only_help ( self , mock_menu ) : <EOL> mock_menu . return_value = ( display_util . HELP , "<STR_LIT:2>" ) <EOL> ret = self . displayer . menu ( "<STR_LIT>" , TAGS , help_label = "<STR_LIT>" ) <EOL> self . assertEqual ( ret , ( display_util . HELP , <NUM_LIT:1> ) ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_menu_desc_only_cancel ( self , mock_menu ) : <EOL> mock_menu . return_value = ( display_util . CANCEL , "<STR_LIT>" ) <EOL> ret = self . displayer . menu ( "<STR_LIT>" , TAGS , help_label = "<STR_LIT>" ) <EOL> self . assertEqual ( ret , ( display_util . CANCEL , - <NUM_LIT:1> ) ) <EOL> @ mock . patch ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def test_input ( self , mock_input ) : <EOL> self . displayer . input ( "<STR_LIT:message>" ) <EOL> self . assertEqual ( mock_input . call_count , <NUM_LIT:1> ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_yesno ( self , mock_yesno ) : <EOL> mock_yesno . return_value = display_util . OK <EOL> self . assertTrue ( self . displayer . yesno ( "<STR_LIT:message>" ) ) <EOL> mock_yesno . assert_called_with ( <EOL> "<STR_LIT:message>" , display_util . HEIGHT , display_util . WIDTH , <EOL> yes_label = "<STR_LIT>" , no_label = "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def test_checklist ( self , mock_checklist ) : <EOL> self . displayer . checklist ( "<STR_LIT:message>" , TAGS ) <EOL> choices = [ <EOL> ( TAGS [ <NUM_LIT:0> ] , "<STR_LIT>" , True ) , <EOL> ( TAGS [ <NUM_LIT:1> ] , "<STR_LIT>" , True ) , <EOL> ( TAGS [ <NUM_LIT:2> ] , "<STR_LIT>" , True ) , <EOL> ] <EOL> mock_checklist . assert_called_with ( <EOL> "<STR_LIT:message>" , width = display_util . WIDTH , height = display_util . HEIGHT , <EOL> choices = choices ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_directory_select ( self , mock_dselect ) : <EOL> self . displayer . directory_select ( "<STR_LIT:message>" ) <EOL> self . assertEqual ( mock_dselect . call_count , <NUM_LIT:1> ) <EOL> class FileOutputDisplayTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( FileOutputDisplayTest , self ) . setUp ( ) <EOL> self . mock_stdout = mock . MagicMock ( ) <EOL> self . displayer = display_util . FileDisplay ( self . mock_stdout ) <EOL> def test_notification_no_pause ( self ) : <EOL> self . displayer . notification ( "<STR_LIT:message>" , <NUM_LIT:10> , False ) <EOL> string = self . mock_stdout . write . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( "<STR_LIT:message>" in string ) <EOL> def test_notification_pause ( self ) : <EOL> with mock . patch ( "<STR_LIT>" , return_value = "<STR_LIT>" ) : <EOL> self . displayer . notification ( "<STR_LIT:message>" ) <EOL> self . assertTrue ( "<STR_LIT:message>" in self . mock_stdout . write . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> @ mock . patch ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def test_menu ( self , mock_ans ) : <EOL> mock_ans . return_value = ( display_util . OK , <NUM_LIT:1> ) <EOL> ret = self . displayer . menu ( "<STR_LIT:message>" , CHOICES ) <EOL> self . assertEqual ( ret , ( display_util . OK , <NUM_LIT:0> ) ) <EOL> def test_input_cancel ( self ) : <EOL> with mock . patch ( "<STR_LIT>" , return_value = "<STR_LIT:c>" ) : <EOL> code , _ = self . displayer . input ( "<STR_LIT:message>" ) <EOL> self . assertTrue ( code , display_util . CANCEL ) <EOL> def test_input_normal ( self ) : <EOL> with mock . patch ( "<STR_LIT>" , return_value = "<STR_LIT>" ) : <EOL> code , input_ = self . displayer . input ( "<STR_LIT:message>" ) <EOL> self . assertEqual ( code , display_util . OK ) <EOL> self . assertEqual ( input_ , "<STR_LIT>" ) <EOL> def test_yesno ( self ) : <EOL> with mock . patch ( "<STR_LIT>" , return_value = "<STR_LIT>" ) : <EOL> self . assertTrue ( self . displayer . yesno ( "<STR_LIT:message>" ) ) <EOL> with mock . patch ( "<STR_LIT>" , return_value = "<STR_LIT:y>" ) : <EOL> self . assertTrue ( self . displayer . yesno ( "<STR_LIT:message>" ) ) <EOL> with mock . patch ( "<STR_LIT>" , side_effect = [ "<STR_LIT>" , "<STR_LIT:y>" ] ) : <EOL> self . assertTrue ( self . displayer . yesno ( "<STR_LIT:message>" ) ) <EOL> with mock . patch ( "<STR_LIT>" , return_value = "<STR_LIT>" ) : <EOL> self . assertFalse ( self . displayer . yesno ( "<STR_LIT:message>" ) ) <EOL> with mock . patch ( "<STR_LIT>" , side_effect = [ "<STR_LIT>" , "<STR_LIT:n>" ] ) : <EOL> self . assertFalse ( self . displayer . yesno ( "<STR_LIT:message>" ) ) <EOL> with mock . patch ( "<STR_LIT>" , return_value = "<STR_LIT:a>" ) : <EOL> self . assertTrue ( self . displayer . yesno ( "<STR_LIT>" , yes_label = "<STR_LIT>" ) ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_checklist_valid ( self , mock_input ) : <EOL> mock_input . return_value = ( display_util . OK , "<STR_LIT>" ) <EOL> code , tag_list = self . displayer . checklist ( "<STR_LIT>" , TAGS ) <EOL> self . assertEqual ( <EOL> ( code , set ( tag_list ) ) , ( display_util . OK , set ( [ "<STR_LIT>" , "<STR_LIT>" ] ) ) ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_checklist_miss_valid ( self , mock_input ) : <EOL> mock_input . side_effect = [ <EOL> ( display_util . OK , "<STR_LIT>" ) , <EOL> ( display_util . OK , "<STR_LIT>" ) , <EOL> ( display_util . OK , "<STR_LIT:1>" ) <EOL> ] <EOL> ret = self . displayer . checklist ( "<STR_LIT>" , TAGS ) <EOL> self . assertEqual ( ret , ( display_util . OK , [ "<STR_LIT>" ] ) ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_checklist_miss_quit ( self , mock_input ) : <EOL> mock_input . side_effect = [ <EOL> ( display_util . OK , "<STR_LIT>" ) , <EOL> ( display_util . CANCEL , "<STR_LIT:1>" ) <EOL> ] <EOL> ret = self . displayer . checklist ( "<STR_LIT>" , TAGS ) <EOL> self . assertEqual ( ret , ( display_util . CANCEL , [ ] ) ) <EOL> def test_scrub_checklist_input_valid ( self ) : <EOL> indices = [ <EOL> [ "<STR_LIT:1>" ] , <EOL> [ "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:1>" ] , <EOL> [ "<STR_LIT:2>" , "<STR_LIT:3>" ] , <EOL> ] <EOL> exp = [ <EOL> set ( [ "<STR_LIT>" ] ) , <EOL> set ( [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> set ( [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ] <EOL> for i , list_ in enumerate ( indices ) : <EOL> set_tags = set ( <EOL> self . displayer . _scrub_checklist_input ( list_ , TAGS ) ) <EOL> self . assertEqual ( set_tags , exp [ i ] ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_directory_select ( self , mock_input ) : <EOL> message = "<STR_LIT>" <EOL> result = ( display_util . OK , "<STR_LIT>" , ) <EOL> mock_input . return_value = result <EOL> self . assertEqual ( self . displayer . directory_select ( message ) , result ) <EOL> mock_input . assert_called_once_with ( message ) <EOL> def test_scrub_checklist_input_invalid ( self ) : <EOL> indices = [ <EOL> [ "<STR_LIT:0>" ] , <EOL> [ "<STR_LIT:4>" ] , <EOL> [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT:1>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT:2>" , "<STR_LIT:o>" ] <EOL> ] <EOL> for list_ in indices : <EOL> self . assertEqual ( <EOL> self . displayer . _scrub_checklist_input ( list_ , TAGS ) , [ ] ) <EOL> def test_print_menu ( self ) : <EOL> self . displayer . _print_menu ( "<STR_LIT>" , CHOICES ) <EOL> self . displayer . _print_menu ( "<STR_LIT>" , TAGS ) <EOL> def test_wrap_lines ( self ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( os . linesep ) ) <EOL> text = display_util . _wrap_lines ( msg ) <EOL> self . assertEqual ( text . count ( os . linesep ) , <NUM_LIT:3> ) <EOL> def test_get_valid_int_ans_valid ( self ) : <EOL> with mock . patch ( "<STR_LIT>" , return_value = "<STR_LIT:1>" ) : <EOL> self . assertEqual ( <EOL> self . displayer . _get_valid_int_ans ( <NUM_LIT:1> ) , ( display_util . OK , <NUM_LIT:1> ) ) <EOL> ans = "<STR_LIT:2>" <EOL> with mock . patch ( "<STR_LIT>" , return_value = ans ) : <EOL> self . assertEqual ( <EOL> self . displayer . _get_valid_int_ans ( <NUM_LIT:3> ) , <EOL> ( display_util . OK , int ( ans ) ) ) <EOL> def test_get_valid_int_ans_invalid ( self ) : <EOL> answers = [ <EOL> [ "<STR_LIT:0>" , "<STR_LIT:c>" ] , <EOL> [ "<STR_LIT:4>" , "<STR_LIT>" , "<STR_LIT:C>" ] , <EOL> [ "<STR_LIT:c>" ] , <EOL> ] <EOL> for ans in answers : <EOL> with mock . patch ( "<STR_LIT>" , side_effect = ans ) : <EOL> self . assertEqual ( <EOL> self . displayer . _get_valid_int_ans ( <NUM_LIT:3> ) , <EOL> ( display_util . CANCEL , - <NUM_LIT:1> ) ) <EOL> class NoninteractiveDisplayTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( NoninteractiveDisplayTest , self ) . setUp ( ) <EOL> self . mock_stdout = mock . MagicMock ( ) <EOL> self . displayer = display_util . NoninteractiveDisplay ( self . mock_stdout ) <EOL> def test_notification_no_pause ( self ) : <EOL> self . displayer . notification ( "<STR_LIT:message>" , <NUM_LIT:10> ) <EOL> string = self . mock_stdout . write . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( "<STR_LIT:message>" in string ) <EOL> def test_input ( self ) : <EOL> d = "<STR_LIT>" <EOL> ret = self . displayer . input ( "<STR_LIT:message>" , default = d ) <EOL> self . assertEqual ( ret , ( display_util . OK , d ) ) <EOL> self . assertRaises ( errors . MissingCommandlineFlag , self . displayer . input , "<STR_LIT:message>" ) <EOL> def test_menu ( self ) : <EOL> ret = self . displayer . menu ( "<STR_LIT:message>" , CHOICES , default = <NUM_LIT:1> ) <EOL> self . assertEqual ( ret , ( display_util . OK , <NUM_LIT:1> ) ) <EOL> self . assertRaises ( errors . MissingCommandlineFlag , self . displayer . menu , "<STR_LIT:message>" , CHOICES ) <EOL> def test_yesno ( self ) : <EOL> d = False <EOL> ret = self . displayer . yesno ( "<STR_LIT:message>" , default = d ) <EOL> self . assertEqual ( ret , d ) <EOL> self . assertRaises ( errors . MissingCommandlineFlag , self . displayer . yesno , "<STR_LIT:message>" ) <EOL> def test_checklist ( self ) : <EOL> d = [ <NUM_LIT:1> , <NUM_LIT:3> ] <EOL> ret = self . displayer . checklist ( "<STR_LIT:message>" , TAGS , default = d ) <EOL> self . assertEqual ( ret , ( display_util . OK , d ) ) <EOL> self . assertRaises ( errors . MissingCommandlineFlag , self . displayer . checklist , "<STR_LIT:message>" , TAGS ) <EOL> def test_directory_select ( self ) : <EOL> default = "<STR_LIT>" <EOL> expected = ( display_util . OK , default ) <EOL> actual = self . displayer . directory_select ( "<STR_LIT>" , default ) <EOL> self . assertEqual ( expected , actual ) <EOL> self . assertRaises ( <EOL> errors . MissingCommandlineFlag , self . displayer . directory_select , "<STR_LIT>" ) <EOL> class SeparateListInputTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . exp = [ "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:test>" ] <EOL> @ classmethod <EOL> def _call ( cls , input_ ) : <EOL> from certbot . display . util import separate_list_input <EOL> return separate_list_input ( input_ ) <EOL> def test_commas ( self ) : <EOL> self . assertEqual ( self . _call ( "<STR_LIT>" ) , self . exp ) <EOL> def test_spaces ( self ) : <EOL> self . assertEqual ( self . _call ( "<STR_LIT>" ) , self . exp ) <EOL> def test_both ( self ) : <EOL> self . assertEqual ( self . _call ( "<STR_LIT>" ) , self . exp ) <EOL> def test_mess ( self ) : <EOL> actual = [ <EOL> self . _call ( "<STR_LIT>" ) , <EOL> self . _call ( "<STR_LIT>" ) , <EOL> self . _call ( "<STR_LIT>" ) , <EOL> ] <EOL> for act in actual : <EOL> self . assertEqual ( act , self . exp ) <EOL> class PlaceParensTest ( unittest . TestCase ) : <EOL> @ classmethod <EOL> def _call ( cls , label ) : <EOL> from certbot . display . util import _parens_around_char <EOL> return _parens_around_char ( label ) <EOL> def test_single_letter ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . _call ( "<STR_LIT:a>" ) ) <EOL> def test_multiple ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . _call ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( "<STR_LIT>" , self . _call ( "<STR_LIT>" ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
